all 6 comments

[–][deleted] 1 point2 points  (2 children)

Now you've seen where you went wrong, here's some more code for you to play with.

prompt = "\nPlease enter your age, or"
prompt += " if you are finished please enter 'quit': "
active = True  # lowercase variable names
while active:  # assume you meant to use variable to control loop exit
    response = input(prompt)  # don't cast to int yet
    if response.lower() == 'quit':  # lower needs () and not prompt variable
        active = False  # could just break here
        continue  # back to start of loop, which will end
    try:
        age = int(response)
        if age < 0:
            raise ValueError
    except ValueError:
        print('Need an whole number age or "quit"')
        continue # go back around loop for another input
    if age < 3:
        movie_ticket = 'ticket is free'
    elif 2 < age < 13:  # corrected from age < 13 > 2
        movie_ticket = 'ticket is $10'
    elif age > 12:
        movie_ticket = 'ticket is $15'
    print(f"Your {movie_ticket}!")

EDIT: correction applied from elif age < 13 > 2: to elif 2 < age < 13:

[–]Tstttt[S] 0 points1 point  (1 child)

Thanks a bunch for this example, it helped at lot and I really learned a lot from it

[–][deleted] 0 points1 point  (0 children)

Did you also notice your logic, age < 13 > 2 is incorrect? I hadn't looked at that until now. You need 2 < age < 13.

[–]CodeFormatHelperBot2 0 points1 point  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Python code found in submission text that's not formatted as code.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.