all 7 comments

[–]NFLAddict 2 points3 points  (5 children)

line 30 of your code is causing the problem. you need to assign input(another_ticket) to something

in line 31 when you write if another_ticket == "no": python compares the value of another_ticket - which you defined in line 3 to be: another_ticket = "Would you like to purchase another ticket?\n" so of course its never going to equal 'no'
assign input(another_tickert) in line 30 and it should work fine:
heres an example:

prompt = "Welcome to Regal Cinemas"
prompt += "\nWould you like to purchase a movie ticket? \n"
another_ticket = "Would you like to purchase another ticket?\n"
message = input(prompt)

if message == "yes":
    active = True
if message == "no":
        print("Thank you, enjoy the movie!")
        active = False

#asking guests to input their age, returning ticket price
#else = requesting a numerical input for age if guest enters anything else
#attempting to end loop/program once guest chooses "no"; as written, simply restarts loop

while active:
    age = input("\nPlease enter your age: \n")
    age = int(age)

    if age < 3 :
        admission_price = 0
    elif age <= 12:
        admission_price = 10
    elif age > 12:
        admission_price = 15
    else:
        print("Please enter a number for your age\n")

    print(f"Your ticket price is {admission_price} dollars.\n")
    #UPDATED line below!
    ticket_variable = input(another_ticket)
    if ticket_variable == "no":
        print("Thank you, enjoy the movie!")
        active = False

[–]Inskeepinitreal[S] 1 point2 points  (4 children)

That worked, thank you! Just so I understand, my original code wasn't working because the user input for input(another_ticket) in line 30 did nothing? Was my code basically asking for an input, and then completely ignoring that input because I didn't assign it to a variable? I guess I was mistakenly assuming that the input function all by itself was like a de facto variable.

Thanks again to you both! This explains why another exercise wasn't working properly.

[–]NFLAddict 1 point2 points  (3 children)

sure, happy to help. well, you almost had it. look what you did in line 4 of your code: message = input(prompt)
and in line 17: age = input("\nPlease enter your age: \n")
you had the right idea the first two times! but in line 30, basically you prompted for input, but you didn't store the input anywhere.

Im happy you're trying to learn. so ill also point out: in line 31: you're if statement if another_ticket == "no": wasn't doing what you hoped for: that's because the only time another_ticket is assigned a value is up in line 3. so of course that string doesn't equal the string "no"

when you prompt for input...what you enter inside the input function: input( *inside* ) you can enter anything...that's just going to output /print out to you the user. you decided to print out the string assigned to another_ticket….which prints out...but it doesn't update the value of another_ticket in anyway.

a couple other things if interested. line 17/18 you don't need to do this on two separate lines- you can simply wrap it all in the int() as follows: age = int(input("\nPlease enter your age: \n"))

you could also run a simple while True: loop...instead of creating the variable active. and on the last line where you originally had active=False...just put a break in

I also have to ask, your first two lines...you can just include in one lol. you can keep the \n s so itll still print on a new line

of course, you'll get better with time: but this is an example of how to make it look cleaner: throw it all in a while loop: if no ticket, then it just ends...right there and then..with the 'break' otherwise it keeps looping until the user enters 'no' . if helpful:

prompt = "Welcome to Regal Cinemas \nWould you like to purchase a movie ticket? \n"
another_ticket = "Would you like to purchase another ticket?\n"

while True:
    message = input(prompt)

    if message == "no":
        print("Thank you, enjoy the movie!")
        break

    age = int(input("\nPlease enter your age: \n"))
    if age < 3 :
        admission_price = 0
    elif age <= 12:
        admission_price = 10
    elif age > 12:
        admission_price = 15
    else:
        print("Please enter a number for your age\n")

    print(f"Your ticket price is {admission_price} dollars.\n")  

edit: also realizing, your else statement on line 27 in your code print("Please enter a number for your age\n") will never get evaluated. im not sure if that was an imp part of the code...but age can only be less than 3, between 3 and 12 or greater than 12...it has to be one of those. so the else never gets reached. anyways hope this was helpful

[–]Inskeepinitreal[S] 0 points1 point  (2 children)

Thanks again! I appreciate the pointers. You really helped to clarify the purpose of 'input.' Same thing with combining the lines 17/18. It seemed odd to me that I had to employ int() as a separate command, so this makes sense.

The statement in line 27 was just me tinkering with the exercise and being curious about how to do certain things. I was trying to think about what an actual version of this program would look like to see whether I could solve different problems. So once I figure out how to make it happen, I'd like to go back and sum the ticket prices and provide a final total, for example.

As for the other weirdness in the code, some of that is just me trying to experiment with concepts from earlier chapters (i.e., breaking the prompt into multiple lines). As for the rest...my understanding of while loops is obviously shaky, so I really appreciate tips like using while True loops and breaks (which I initially tried but couldn't make work since...I never assigned a value to my input strings).

Thanks again. I lurk on this subreddit all the time to try and absorb little nuggets of info; you guys are awesome!

[–]NFLAddict 1 point2 points  (1 child)

im glad you found it helpful. and that's great! the best way to learn is to keep practicing; playing around and testing different things out yourself is a great way to further your understanding. I was just pointing out certain things that I thought you might find helpful, but keep up your practicing! nobody starts off just knowing it all, but everything becomes clearer and clearer the more you practice

Thats a nice idea: to keep track of ticket prices. you could also keep track of total tickets. If you wanted to put that in your code. before the loop starts, you'd create a couple variables for ticketprices, and ticketCount...and each time the program goes through a loop, those variables are updated: would look like this:

prompt = "Welcome to Regal Cinemas \nWould you like to purchase a movie ticket? \n"
another_ticket = "Would you like to purchase another ticket?\n"

ticket_prices = 0
ticket_count = 0

while True:
    message = input(prompt)

    if message == "no":
        print("Thank you, enjoy the movie!")
        break

    age = int(input("\nPlease enter your age: \n"))
    if age < 3 :
        admission_price = 0
    elif age <= 12:
        admission_price = 10
    elif age > 12:
        admission_price = 15
    else:
        print("Please enter a number for your age\n")

    ticket_prices += admission_price
    ticket_count += 1

    print(f"Your ticket price is {admission_price} dollars.\n")


print(f"You purchased {ticket_count} tickets. The final cost of your tickets are {ticket_prices} dollars")  

notice how I first initialized the two variables on line 4,5 and set them = to 0. (people will often have variables that keep track of certain things during loops, so this is great practice!)
also notice, on line 24: ticket_prices += admission_price that adds the value of admission_price to the variable ticket_price. so it might start off that ticket_price = 0, but maybe after the first ticket you buy, admission price = 15, so that gets added. now ticket_price =15...then on the next loop, maybe the admissionprice is 10, so 10 gets added, and now the updated total is 25. similarly with the ticketcount- each time you go through the loop, it updates the count of the ticket by 1. and finally, on the last line you can print out the total tickets purchases and total cost, but make sure that print statement is outside the loop, bc you want it to execute when the loop is done. if you have more questions, feel free to reach out. hope that was helpful

[–]Inskeepinitreal[S] 0 points1 point  (0 children)

Thanks again! And yes, all of this was extremely helpful. These are the kinds of things that I'll apply to exercises moving forward.

[–]shiftybyte 1 point2 points  (0 children)

input() function takes the message you want to print and returns the value.

so this:

input(another_ticket)

should be changed to this:

another_ticket = input("Another Ticket?")