我是一名业余爱好者试图在Python中编写一个简单的故障排除程序,但我确定我需要使用哪种功能来阻止这种情况发生...... enter image description here
如果用户输入yes,我应该怎么做才能继续运行代码?
TxtFile =open('Answers.txt')
lines=TxtFile.readlines()
import random
def askUser(question):
answer = input(question + "? ").lower()
Split = answer.split()
if any(word in Split for word in KW1):
return False
elif any(word in Split for word in KW2):
return True
else:
print("Please answer yes or no.")
askUser(question)
KW1=["didn't", "no",'nope','na'] #NO
KW2=["did","yes","yeah","ya","oui","si"] #YES
print (lines[0])
print("Nice to meet you, " + input("What is your name? "))
print("Welcome to my troubleshooter")
#This is the menu to make the user experience better
shooter=True
while shooter:
print('\n\n1.Enter troubleshooter\n2.Exit\n\n')
shooter=input('Press enter to continue: ')
if shooter==('2'):
print('Ok bye')
break
words = ('tablet', 'phone', 's7 edge')
while True:
question = input('What type of device do you have?: ').lower()
if any(word in question for word in words):
print("Ok, we can help you")
break
else:
print("Either we dont support your device or your answer is too vague")
if askUser("Have you tried charging your phone"):
print("It needs to personally examined by Apple")
else:
if askUser("Is it unresponsive"):
print (lines[0])
else:
print ("Ok")
if askUser("Are you using IOS 5.1 or lower"):
print (lines[1])
else:
if askUser("Have you tried a hard reboot"):
print (lines[2])
else:
if askUser("Is your device jailbroken"):
print (lines[3])
else:
if askUser("Do you have a iPhone 5 or later"):
print (lines[4])
else:
print(lines[5])
print ('Here is your case number, we have stored this on our system')
print (random.random())
这是我的代码供参考。
编辑:这是问题所在 enter image description here
它应该只是结束那里的代码,但它没有。我不确定如何解决它
答案 0 :(得分:-2)
我建议移动以下内容:
Descriptor
进入其他部分:
if askUser("Are you using IOS 5.1 or lower"):
print (lines[1])
else:
if askUser("Have you tried a hard reboot"):
print (lines[2])
else:
if askUser("Is your device jailbroken"):
print (lines[3])
else:
if askUser("Do you have a iPhone 5 or later"):
print (lines[4])
else:
print(lines[5])
print ('Here is your case number, we have stored this on our system')
print (random.random())
希望这有帮助。