Getting error message when trying to break out of a while loop in Python
<p>I'm trying to write code that includes the following:</p>

<p>1) Uses a conditional test in the while statement to stop the loop.</p>

<p>2) Uses an active variable to control how long the loop runs.</p>

<p>3) Use a break statement to exit the loop when the user enters a 'quit' value.</p>

<p><strong>Here is my code:</strong></p>

<pre><code>prompt = "What is your age?"
prompt += "\nEnter 'quit' to exit: "

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

    if age == 'quit':
        break
    elif age &lt; 3:
        print("Your ticket is free.")
    elif 3 &lt;= age &lt;=12:
        print("Your ticket is $10.")
    elif 12 &lt; age:
        print("Your ticket is $15.")
    else:
        print("Please enter a valid age.")
</code></pre>

<p>I believe I've answered part 1 and 2 correctly but whenever I enter 'quit' or any other word to test for part 3, I get an error message that states: "ValueError: invalid literal for int() with base 10: 'quit'"</p>

<p>Does anyone have any suggestions of what I may be doing wrong in my code? Thank you for your time.</p>

<p>You are casting the string "quit" to integer, and python tells you it's wrong.</p>

<p>This will work :</p>

<pre><code>prompt = "What is your age?"   
prompt += "\nEnter 'quit' to exit: "
while True:
    age = input(prompt)       
    if age == 'quit':
        break
    age = int(age)
    if age &lt; 3:
        print("Your ticket is free.")
    elif 3 &lt;= age &lt;=12:
        print("Your ticket is $10.")
    elif 12 &lt; age:
        print("Your ticket is $15.")
    else:
        print("Please enter a valid age.")
</code></pre>

python