Python:从文本中选择单词

时间:2016-02-27 17:27:35

标签: python

所以我正在处理一个我正在研究的小项目的问题,问题出在第10行和第18行。由于某种原因,我无法触发48行,我无法理解为什么?另外我还有另外一个问题,这就是为什么当我输入一些不应被程序确认的随机内容时,例如当程序说“请说出你的问题”并且我输入“iajsdb”时为什么程序没有结束?相反,它会选择其中一个结果,例如“互联网速度慢还是整体手机?”。同样是的,我知道代码非常混乱,这是我写的内容的片段,如果需要更多来解决问题,那么我会很乐意发布更多内容。非常感谢。

        #Twig2 (iPhone/2g/problem/wet)
    elif "wet" in iproblem2g.lower():
        print ("The chances that your phone will recover from water damage is extremly minimal. You may wish to go to a proffesional and see if any data can be restored, otehrwise you will most likely need to buy a new phone.")
        applestore = raw_input ("Would you like to find an Apple store near you? ")
        if "yes" or "sure" or "okay" in applestore:
            webbrowser.open("http://www.apple.com/retail/")
        else:
            print("Troubleshooting complete.")

    elif "no wifi" or "can't connect" or "cant connect" in iproblem2g.lower():
        print("If you cannot connect to your local wifi network then follow these steps:")
        print("1. Make sure you have a strong signal")
        print("2. Make sure your wifi is actually on in your settings")
        print("3. Make sure your wifi network is visible to the public and not invisible.")
        print("If none of these steps helped then consider going to your local phone repair shop and getting it checked up.")

            #Twig4 (iPhone/problem/slow)
    elif "slow" or "lag" in iproblem2g.lower():
        slow = raw_input ("Is the internet slow or the phone overall? ")
        if "net" or "web" in slow:
            print ("Make sure that your slow connection isn't caused by a weak signal.")
            nettips = raw_input ("Would you like to be redirected to a page with tips to speed up your internet? ")

1 个答案:

答案 0 :(得分:1)

您没有正确使用if。你应该使用:

elif "no wifi" in iproblem2g.lower() or "can't connect"  in iproblem2g.lower() or "cant connect" in iproblem2g.lower():
elif "slow" in iproblem2g.lower() or "lag" in iproblem2g.lower():

依此类推(重复条件,or无论您输入什么,它都会一直评价为True ...