-1

I am Mike and i am very new to python (2 days). I wanna ask the age of the user and then confirm that he has written the right age so after asking him what is your age I also ask is that correct?If the user says yeah it breaks the while loop and moves on, if the user says something other than yes or no it goes back and ask him yes or no again. - but how can I ask him his age again if the user says no (meaning that he has written the wrong age).

enter code here age = input("Please enter your age: ")
input("You are " + age + " years old. Correct?")
answer2 = None
while answer2 not in ("yes", "no"):
    answer2 = input("Enter yes or no: ")
    if answer2 == "yes":
        break
    elif answer2 == "no":
        input("Oops.Something went wrong.""\nLets try again.")
    else:
        print("Please enter yes or no.")
Roshan
  • 664
  • 5
  • 23

1 Answers1

0

Please check this code, I have updated it for you:

age = input("Please enter your age: ")
answer2 = None
while answer2 not in ("yes", "no"):
    answer2 = input("You are " + age + " years old. Correct?")
    if answer2 == "yes":
        break
    elif answer2 == "no":
        answer2 = None
        print("Oops.Something went wrong.""\nLets try again.")
        age = input("Please enter your age: ")
    else:
        print("Please enter yes or no.")
Roshan
  • 664
  • 5
  • 23
  • Thank you so much. My mind was stuck in this for like an hour now. Now that you told me what to do and I can't see why I could see it. Appreciate the help – Mixalis Kyrillidis May 04 '20 at 05:31
  • @MixalisKyrillidis Kindly mark my answer by clicking the tick to the left of my answer :) I'm really glad that it helped you – Roshan May 04 '20 at 05:49