Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

python - How do you add a list to jump to a line on my code?

I Have a python code to fix phones and i was wondering what was the best way to jump to a particular question when i type in for example 'Broken Screen'

im really stuck and need this done i appreciate immensely all answers

def menu():
   print("Welcome to Sams Phone Troubleshooting program")
   print("Please Enter your name")
   name=input()
   print("Thanks for using Kierans Phone Troubleshooting program "+name)
   print("Would you like to start this program? Please enter either y for yes or n for no")  
   select=input()
   if select=="y":
      troubleshooter()
   elif select=="n":
      quit
   else:
      print("Invalid please enter again")
      menu()
def troubleshooter():
   print("Does Your Phone Turn On")
   answer=input()
   if answer=="y":
      print("Does it freeze?")
   else:
      print("Have you plugged in a charger?")
   answer=input()

   if answer=="y":
      print("Charge it with a diffrent charger in a diffrent phone socket")
   else:
      print("Plug it in and leave it for 20 mins, has it come on?")
   answer=input()

   if answer=="y":
      print("Is there any more problems?")
   else:
      print("Is the screen cracked?")
   answer=input()

   if answer=="y":
      print("Restart this program")
   else:
      print("Thank you for using my troubleshooting program!")
   answer=input()

   if answer=="y":
      print("Replace screen in a shop")
   else:
      print("Take it to a specialist")
   answer=input()

   if answer=="y":
      print("Did you drop your device in water?")
   else:
      print("Make sure the sim card is inserted properly and do a hard reset on the device")
   answer=input()

   if answer=="y":
      print("Do not charge it and take it to the nearest specialist")
   else:
      print("Try a hard reset when the battery has charge")
   answer=input()



menu()
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here's the best attempt I had at replicating your code. I made a couple of the problems def() so that you can call each one separately. I hope this is what you wanted!

def menu():
  print("Welcome to Sams Phone Troubleshooting program")
  print("Please Enter your name")
  name=input()
  print("Thanks for using Kierans Phone Troubleshooting program "+name +"
")

def start():
  select = " "
  print("Would you like to start this program? Please enter either y for yes or n for no")
  select=input()
  if select=="y":
    troubleshooter()
  elif select=="n":
    quit
  else:
    print("Invalid please enter again")

def troubleshooter():
  print("""Please choose the problem you are having with your phone (input 1-4):
1) My phone doesn't turn on
2) My phone is freezing
3) The screen is cracked
4) I dropped my phone in water
""")
  problemselect = int(input())
  if problemselect ==1:
    not_on()
  elif problemselect ==2:
    freezing()
  elif problemselect ==3:
    cracked()
  elif problemselect ==4:
    water()
  start()

def not_on():
  print("Have you plugged in the charger?")
  answer = input()
  if answer =="y":
    print("Charge it with a diffrent charger in a diffrent phone socket. Does it work?")
  else:
    print("Plug it in and leave it for 20 mins, has it come on?")
  answer = input()
  if answer=="y":
    print("Are there any more problems?")
  else:
    print("Restart the troubleshooter or take phone to a specialist
")
  answer=input()
  if answer =="y":
    print("Restart this program")
  else:
    print("Thank you for using my troubleshooting program!
")

def freezing():
  print("Charge it with a diffrent charger in a diffrent phone socket")
  answer = input("Are there any more problems?")
  if answer=="y":
    print("Restart the troubleshooter or take phone to a specialist
")
  else:
    print("Restart this program
")

def cracked():
  answer =input("Is your device responsive to touch?")
  if answer=="y":
    answer2 = input("Are there any more problems?")
  else:
    print("Take your phone to get the screen replaced")
  if answer2=="y":
    print("Restart the program or take phone to a specialist
")
  else:
    print("Thank you for using my troubleshooting program!
")

def water():
  print("Do not charge it and take it to the nearest specialist
")

menu()
while True:
  start()
  troubleshooter()

Hope this helps somewhat and if there are minor problems with the code then just message me! (I'm relatively new to this site!)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...