Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我应该使用什么函数来修复代码?_Python - Fatal编程技术网

Python 我应该使用什么函数来修复代码?

Python 我应该使用什么函数来修复代码?,python,Python,我是一个业余爱好者,试图用Python编写一个简单的疑难解答,但我确定我需要使用什么函数来阻止这种情况发生。。。 如果用户输入yes,我应该怎么做才能使代码不继续运行 TxtFile =open('Answers.txt') lines=TxtFile.readlines() import random def askUser(question): answer = input(question + "? ").lower() Split = answer.split()

我是一个业余爱好者,试图用Python编写一个简单的疑难解答,但我确定我需要使用什么函数来阻止这种情况发生。。。

如果用户输入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())
这是我的代码供参考

编辑:问题出在这里


它应该在那里结束代码,但它没有。我不确定如何修复它

我建议移动以下内容:

   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())
进入以下内容的其他部分:

if askUser("Is it unresponsive"):

希望这能有所帮助。

你能发布你的完整代码,包括
askUser
函数以及
行[0]-[2]
的来源吗?谢谢你更新你的问题。错误来自哪里?你能指出你代码的具体部分吗?此外,您的缩进看起来需要在某些点上进行固定。您是否同时使用制表符和空格缩进代码?我发布了完整的代码。我正在打印一个txt文件中的第0-2行,该文件由以下内容组成,您需要将iPhone发送回苹果。在“设置”中,您需要更新软件。不幸的是,我们无能为力,您的设备需要维修。越狱你的iPhone违反了保修条款,苹果再也帮不了你了。您必须在出厂时重置手机。感谢您使用苹果客户服务,祝您度过愉快的一天。很抱歉,此问题尚未解决,我们将为您分配一个案例编号#好的,我再次编辑了它,使用了制表符和空格。