mardi 9 mai 2017

annotating python code + troubleshooting program

this is my code :

 print("Welcome to Apple online iPhone help system, I will ask you a series "
      "of questions and please answer with a 'yes' or 'no', if by the end "
      "our automatic troubleshooting system does not help you,there are more "
      "support and help options available on our website "
      "http://ift.tt/17k3gb1 \n")

q_and_a = [
         ["Is your phone running slow? ",
          "You need to free up space, phones slow down when they are full,"  
          " try deleting unused apps or unnecessary photos or buy more storage."
          " If that doesn’t fix your problem contact Apple for more help."],

         ["Have your dropped your phone in water? ",
          "turn off your phone and leave it in a bag of rice for 72 hours "
          "and after the waiting periodturn it on and it should work, if it "
          "doesn't your phone is broken, contact Apple to get it fixed"],

         ["Does your phone keep crashing? ",
          "Reset your phone and that should prevent your phone from crashing. "
          "If that doesn’t fix your problem contact Apple for more help."],

         ["Is your problem due to the recent update? ",
          "There could be multiple solutions to the this problem, "
          "go to 'http://ift.tt/2pYapAJ and find your problem"],

          ]

def askit(question):
    retn = False

    ans = input(question[0])
    if ans == "yes":
        print(question[1])
        retn = True
    else:
        print("\nOkay let's move on to the next question")

    return retn

for q in q_and_a:
    if askit(q):
        break

i need to have this annotated , i understand the basics of this but i need to have detailed description of it, i understand what the return function does but i need to in detail explain the purpose of each line of the function, can you help ? i previously had indention errors so my code is now indented properly. i understand that you Use elif blocks to manage your logic flow.

Your code has the else functionality within the if blocks so they will never execute. but can someone explain that and my code in more detail please?

Aucun commentaire:

Enregistrer un commentaire