首页   注册   登录

ryanjmliao

V2EX 第 286300 号会员,加入于 2018-01-24 22:00:16 +08:00
ryanjmliao 最近回复了
@xiaoming1992 感谢,我已经解决了
@hellwys1 是这样,求人不如求己。发现这个论坛不太适合非程序员。
这是我想到的第一题,但好像不完美,特别是,当时间为三位数比如 100 分钟,他总是显示不出来。。。
def positivize(review):
if "bad" in review or "Bad" in review or "BAD" in review:
review=review.replace("bad", "good")
review=review.replace("Bad", "Good")
review=review.replace("BAD", "GOOD")

if "horrible" in review or "Horrible" in review or "HORRIBLE" in review:
review=review.replace("horrible", "fantastic")
review=review.replace("Horrible", "Fantastic")
review=review.replace("HORRIBLE", "FANTASTIC")

if "dirty" in review or "Dirty" in review or "DIRTY" in review:
review=review.replace("dirty", "clean")
review=review.replace("Dirty", "Clean")
review=review.replace("DIRTY", "CLEAN")

if "disgusting" in review or "Disgusting" in review or "DISGUSTING" in review:
review=review.replace("disgusting", "sublime")
review=review.replace("Disgusting", "Sublime")
review=review.replace("DISGUSTING", "SUBLIME")

if "expensive" in review or "Expensive" in review or "EXPENSIVE" in review:
review=review.replace("expensive", "affordable")
review=review.replace("Expensive", "Affordable")
review=review.replace("Expensive", "AFFORDABLE")

if "moldy" in review or "Moldy" in review or "MOLDY" in review or "MOLDY" in review:
review=review.replace("moldy", "flavourful")
review=review.replace("Moldy", "Flavourful")
review=review.replace("MOLDY", "FLAVOURFUL")

if "frozen" in review or"Frozen" in review or "FROZEN" in review:
review=review.replace("frozen", "farm-fresh")
review=review.replace("Frozen", "Farm-fresh")
review=review.replace("FROZEN", "FARM-FRESH")

if "minutes" in review or "Minutes" in review or "min" in review or "Min" in review or "MIN" in review or "MINUTES" in review:
a=review.index("minutes")
if a<100:
i=a-3
j=a-1
n=int((review[i:j]))
review=review.replace(str(review[i:j]),"only "+str(int(n/2)))
if a>=100:
i=a-5
j=a-1
n=int(review[i:j])
review=review.replace(str(review[i:j]),"only "+str(n/2))



return review
@InkStone 我想到的是用 index 定位到 minutes,然后再减去三位数,得到数值的定位,再取出数值,除以二
@InkStone 还没学到,,,
@JerryCha 不瞒你说,因为签证问题,我还没去上过一节课,也还没见到过同学,所以是在家看课件自学,我只能说你说的很对,感谢提醒。
@Yvette 我都有说明吧,比如第一题,我卡住的地方是大小写,在第二题,我也把自己的思路说出来,我是希望在这里求问,能获得点播,我从来没有伸手要答案,我也没这个习惯,你可以看看我之前发的求教帖子,我没要求大家都把答案贴出来,我都是希望大家给思路,一起讨论。
如果觉得这个帖子对你没有价值或者不想回答,大可以不必要回复,但是没必要冷嘲热讽。如果探讨题目本身那我很感谢。
@jmc891205 就是这个不懂
@JerryCha 就是 in 用了很多了,我是想全部只用一个 if,然后 or '' xxx" in review,但是一想情况太多了,比如 Good, good, 或者 GOOD,相当于每一个都有三遍。。。那我的用 7x3=21 个 or in
@cherbim
@scukmh
@rioshikelong121
要有基础也不会来宝地问了,说了总共才上 5 节课,以前也没学过,如果说 V2EX 是不能问基础题目的,那我以后就另寻他处问吧,打扰。
关于   ·   FAQ   ·   API   ·   我们的愿景   ·   广告投放   ·   感谢   ·   实用小工具   ·   4061 人在线   最高记录 5043   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.3 · 11ms · UTC 09:35 · PVG 17:35 · LAX 01:35 · JFK 04:35
♥ Do have faith in what you're doing.