【问题标题】:Python "trouble shooting machine " needs fixingPython“故障排除机”需要修复
【发布时间】:2017-02-18 18:57:36
【问题描述】:

以下代码旨在成为 Python 中的自动故障排除程序。

# Welcoming the user to the program
print("Hello this is a automated mobile phone troubleshooter ") 
print("The code will ask you a few questions try to answer them to the best of your ability") # Explaining what the code will do

# A list storing all the questions the code will ask the user
questions = ["Is there a problem with your hardware or is do you need technical assistance. Please type technical assistance or hardware",
             "Have you dropped your phone recently? Please type Yes or No",
             "Is your phone able to charge? please type Yes or No",
             "Is your phone a iphone? Please type yes or no",
             "Does your phone keep freezing? Please type yes or no",
             "Can your phone connect to wifi? please type either yes or no",
             "Have you gotten your phone wet? ",
             "Is the phone's screen cracked or broken? ",
             "Is there a problem with the camera? ",
             "Is the problem with phone fixed? "] 
# A list containing all the solutions that will be given to the user
solutions = ["This troubleshooter is only for hardware problems please call 01474 709853 for technical assistance",
             "Please try turning it off and on again",
             "Try changing the cable you charge the phone with",
             "Please hold the lock button and home button for 5 seconds this causes a force restart",
             "Try deleting some data to make your phone run faster E.G. Delete applications",
             "Try restarting your router",
             "Put your phone in a bowl of rice overnight",
             "Take the phone to the manufacturer's store",
             "Uninstall any third party apps or applications that you have downloaded since the camera has not been working",
             "Please take the phone to your local phone manufacturers store and ask them for help"]
answers = ["technical assistance","yes","no","yes","yes","no","yes","yes","yes","no"]
validation = ["hardware","no","yes","no","no","yes","no","no","no","yes"]
answer = "a"
# Creating a loop and making the variable loop go from 0 to 9
for loop in range(0,10):
    while answer != answers[loop] and answer != validation[loop]:
        answer = input(questions[loop])
        # Turning the user's answer and turning it to lowercase making sure the IF statement gets the right answer
        answer = answer.lower()    
        if answer == answers[loop]:
            # prints the solution the problem
            print(solutions[loop])
            else goto 

print("Thank you for using the automated troubleshooting program goodbye")

我无法让这段代码正常运行,因为它在结束之前最多需要输入两个问题,有没有人可以提供帮助?

【问题讨论】:

  • 您可以尝试在代码框中格式化代码吗? meta.stackexchange.com/questions/22186/…
  • 请正确格式化您的代码。如果系统不允许您使用巨大的代码块和少量文本进行询问,那是有原因的(抄送。@MartinGottweis)。你的问题缺乏信息。请阅读How to Ask
  • 上次我看到 goto 就像是在 25 年前玩 c64 basic 时:)
  • @grubjesic 不错,我想知道如果运行两个问题,python OP 使用的是什么版本:)

标签: python


【解决方案1】:

用“if statements”和 raw_input 来做这件事怎么样?

x = raw_input("Is there a problem with your hardware or is do you need technical assistance. Please type technical assistance or hardware")

if x == ("technical assistant"):
    print("This troubleshooter is only for hardware problems please call 01474 709853 for technical assistance")

if x == ("hardware"):
    x1=raw_input("Have you dropped your phone recently? Please type Yes or No")

if x1 == ("No"):
    x2=raw_input("Is your phone able to charge? Please type Yes or No")

等等……

【讨论】:

  • 你的答案不清楚,很容易导致未定义的x1
猜你喜欢
  • 2020-03-07
  • 2019-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-15
  • 2020-07-16
相关资源
最近更新 更多