1

Very new to programming! I am working through the book Python Crash Course.

Trying to create a simple program to determine ticket pricing. Taking in user input as age but ending the program when user inputs 'done'

Looks like this:

guest_age = ("Please enter your age. ")

while True:
    age = input(guest_age)
    age = int(age)

if age == 'done':
    break
elif age < 3:
    print("Your ticket is free!")
elif age <= 12:
    print("Your ticket is $10!")
else:
    print("Your ticket is $15!")

I am stumped on how to incorporate the done input without getting the

ValueError  invalid literal for int() with base 10: 'done'
Joe Ferndz
  • 8,417
  • 2
  • 13
  • 33
mrken87
  • 13
  • 2

1 Answers1

0

You need to first check if the input is 'done' before casting. So,

guest_age = ("Please enter your age. ")
while True: 
  age = input(guest_age) 
  if age == 'done':
    break
  age = int(age)
  ...
koko
  • 158
  • 1
  • 7