Partial struggle with while loops /u/Stock-Bookkeeper4823 Python Education

Hello everyone. I could really use some assistance in understanding why my while loop is returning an error when the user tries to exit the program with input ‘quit’. I’ve been studying the book ‘Python Crash Course’ by Eric Mathes. It’s a damn good book. The exercise that gave me problems is 7-5. I keep getting a ValueError. Here is the code below:

“` prompt = “How old are you so we can determine your ticket price?” prompt += “nSay ‘quit’ if you are too scarred to ride!! “

while True: age = input(prompt)

if age == quit: break else: age = int(age) if age < 3: print("nYour addmitance is free!!n") elif age < 13: print("nYour ticket is $10.n") else: print("nYour ticket will be $15.n") 

“`

Here is the error code when I enter the prompt ‘quit’.

“` Traceback (most recent call last): File “7-5.py”, line 10, in <module> age = int(age) ^ ValueError: invalid literal for int() with base 10: ‘quit’

“`

The code works fine until I try to quit the program. Can anyone please help me with this issue? I’ve tried for two weeks in my free time to figure out whats going wrong.

submitted by /u/Stock-Bookkeeper4823
[link] [comments]

​r/learnpython Hello everyone. I could really use some assistance in understanding why my while loop is returning an error when the user tries to exit the program with input ‘quit’. I’ve been studying the book ‘Python Crash Course’ by Eric Mathes. It’s a damn good book. The exercise that gave me problems is 7-5. I keep getting a ValueError. Here is the code below: “` prompt = “How old are you so we can determine your ticket price?” prompt += “nSay ‘quit’ if you are too scarred to ride!! ” while True: age = input(prompt) if age == quit: break else: age = int(age) if age < 3: print(“nYour addmitance is free!!n”) elif age < 13: print(“nYour ticket is $10.n”) else: print(“nYour ticket will be $15.n”) “` Here is the error code when I enter the prompt ‘quit’. “` Traceback (most recent call last): File “7-5.py”, line 10, in <module> age = int(age) ^ ValueError: invalid literal for int() with base 10: ‘quit’ “` The code works fine until I try to quit the program. Can anyone please help me with this issue? I’ve tried for two weeks in my free time to figure out whats going wrong. submitted by /u/Stock-Bookkeeper4823 [link] [comments] 

Hello everyone. I could really use some assistance in understanding why my while loop is returning an error when the user tries to exit the program with input ‘quit’. I’ve been studying the book ‘Python Crash Course’ by Eric Mathes. It’s a damn good book. The exercise that gave me problems is 7-5. I keep getting a ValueError. Here is the code below:

“` prompt = “How old are you so we can determine your ticket price?” prompt += “nSay ‘quit’ if you are too scarred to ride!! “

while True: age = input(prompt)

if age == quit: break else: age = int(age) if age < 3: print("nYour addmitance is free!!n") elif age < 13: print("nYour ticket is $10.n") else: print("nYour ticket will be $15.n") 

“`

Here is the error code when I enter the prompt ‘quit’.

“` Traceback (most recent call last): File “7-5.py”, line 10, in <module> age = int(age) ^ ValueError: invalid literal for int() with base 10: ‘quit’

“`

The code works fine until I try to quit the program. Can anyone please help me with this issue? I’ve tried for two weeks in my free time to figure out whats going wrong.

submitted by /u/Stock-Bookkeeper4823
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *