May-09-2019, 07:58 PM
I'm currently going through the Python Crash Course and I'm on Chapter 7. I'm attempting to use an active variable to control how long the loop runs.
prompt = "\nWhat is your age?"
prompt += "\n(Enter 'quit' when you are finished.)"
active = True
while active:
age = input(prompt)
if age == 'quit':
active = False
age = int(age)
if age < 3:
print("\nYour ticket is free!")
elif age < 12:
print("\nYour ticket is 10$!")
else:
print("\nYour ticket is 15$!")
The above works until I enter quit. Error:Traceback (most recent call last):
File "parrot.py", line 10, in <module>
age = int(age)
ValueError: invalid literal for int() with base 10: 'quit'I know that this is because I change age data type to an integer data type so I can use the comparison operators However, quit is not an int. I feel like maybe this is a matter of placement? I've tried different placements (before the if age == 'quit') but it's still not working. Could someone please point me in the right direction? Thank you!
