I've been reading through a beginner's book for Python, and I can't quite get this example to work perfectly.

active = True
age = ""

while active:
    age = input("Please enter your age  ")
    if str(age) == 'quit':
        active = False
    elif int(age) < 3 and int(age) != 0:
        price = 0
    elif int(age) >= 3 and int(age) <= 12:
        price = 10
    elif int(age) > 12:
        price = 15

    print(str(price) + " dollars is the cost of your ticket")

Everything works perfectly, except for the fact that when I type "quit", instead of quitting it says " X dollars is the cost of your ticket" (X being the last amount of dollars it said I owed it.) Thanks for the help!

Recommended Answers

All 2 Replies

While I don't see the end of the while loop, it appears to me it will do one last print before exit. You could fix that and move on.

Such as line 16 change it to
if (active) print .....

Seems easy to polish up.

That change to line 16 worked perfectly. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.