努力解决为什么python在第4行抱怨:
import sys
import re
problem = input("What is wrong with your mobile device?").lower
water = re.search(r'water', problem)
screen = re.search(r'screen', problem)+ re.search(r'smashed',problem)or re.search(r'cracked',problem)+ re.search(r'display',problem)
software=re.search(r'software',problem)+ re.search(r'program',problem)
keypad=re.search(r'keypad',problem)+ re.search(r'keyboard',problem)+ re.search(r'text',problem)
speakers=re.search(r'sound',problem)+ re.search(r"can't here",problem)+ re.search(r'cant hear',problem)
microphone=re.search(r'microphone',problem)+ re.search(r'cant hear me',problem)+ re.search(r"can't hear me",problem)
battery=re.search(r'battery',problem)+ re.search(r'swollen',problem)
charger=re.search(r'Charger',problem)+ re.search(r'charge',problem)+ re.search(r'charging',problem)
if water:
print("If your phone has suffered water dammage there is not much you can do, it is recomended that you buy a new phone")
sys.exit
elif screen:
print("If your screen is cracked then it is recomended that you get it repaired this is not too expensive.")
sys.exit
elif software:
print("If you have a software issue then contact the product manurfacture, they are the only ones qualified to fix this.")
sys.exit
elif keypad:
print("Clean your keypad with a wetwipe, do not get the charger port or jack port wet.")
sys.exit
elif microphone:
print("Your microphone hole may be blocked, please clean this with a soft dry tooth brush, if this does not work then please retern the hand held device to its manufactures.")
sys.exit
elif battery:
print("If your battery is enlarged/swollen you have probbaly over charged it it is recomended that you buy a ned battery.")
sys.exit
elif speakers:
print("The speaker on most phone is located on the side or back or the device if this is blocked then please attemt to clean this with a dry, soft toothbrush, if this does not work please contact the product manurfacture.")
sys.exit
elif charger:
print("If you have not tryed buying a new charger then try that. If a new charger does not work, please send your mobile device to the product manurfacture.")
sys.exit
else:
print("please write your problem again, attempt to use keywords that relate to your problem.")
sys.exit
如果有人可以告诉我如何更正或自行更正,我们将非常感激。
答案 0 :(得分:4)
你没有在第3行调用函数。为了调用它,你必须在它之后写2个括号。因此,请按如下方式更正该行:
problem = input("What is wrong with your mobile device?").lower()
答案 1 :(得分:1)
问题实际上在第3行。根据this article,Python 2使用raw_input
来获取输入,而Python 3使用input
。看起来您的代码期望Python 3环境,但您的环境实际上是Python 2。
如果您确实在Python 2环境中运行,则可以通过调用input
来取代对raw_input
的调用。
此外,您必须在调用lower
后使用括号,以便实际调用该方法。
problem = raw_input("What is wrong with your mobile device?").lower()
problem = input("What is wrong with your mobile device?").lower()