2

I am new to python and coding in general so sorry if the code is messy. I want to summarize all of the values that the user has inputted as a list at the end of the code when the user inputs 0. If you can help it would be greatly appreciated.

while True:


 print("Press 1 to apply for the ride\nPress 0 to quit")

 userchoice = input("Choice:")

 #for option 1

 if userchoice == "1":
  print("What is your age?")
  
  userage = int(input("Age:"))

  if userage < 7:
    print("You are too young")

  elif userage < 12:
    print("You can ride the ride")

  elif userage > 12:
    print("You are too old")
 
 #for option 0
 if userchoice == "0":
   print("Application Exited")
   break
Ben Marks
  • 43
  • 3

1 Answers1

1

Use a global variable to store values entered by the user. And append the userchoice value to it in the if statement.

userchoices = []

while True:


 print("Press 1 to apply for the ride\nPress 0 to quit")

 userchoice = input("Choice:")

 #for option 1

 if userchoice == "1":
  userchoices.append(userchoice)
  print("What is your age?")
  
  userage = int(input("Age:"))

  if userage < 7:
    print("You are too young")

  elif userage < 12:
    print("You can ride the ride")

  elif userage > 12:
    print("You are too old")
 
 #for option 0
 if userchoice == "0":
   print(userchoices)
   print("Application Exited")
   break
Karambit
  • 317
  • 4
  • 11