Python Python Basics All Together Now Branch and Loop

while loop error

My Code seems to skip to the bottom. everytime I input into console it goes to the last print function please help!


tickets_remaining = 100

# Run this code until there are no tickets

while tickets_remaining <=1:

#out put how many tickets are remaining using the tickets_remaining variable
print("there are {} Tickets Left".format(tickets_remaining))

#Gather the user's name and assign it to a new variable
name_of_user = input("what is your name?  ")

#prompt the user by name and ask how many tickets they would like
num_tickets=input("thank you {}, and how many tickets".format(name_of_user))

#calculate the price (not * by Price) and assign it to var

price= num_tickets * TICKET_PRICE 

print("the total ammount due is ${}.".format(price))
#output the price to the screen 

#prompt the user if they want to proceed. y/n

confirm_purchase=input("do you want to proceed with the purchase? y/n   ")

if confirm_purchase.lower() =="y":
    tickets_remaining-= num_tickets

    print("thank you {}!".format(name_of_user))

print("sorry we are all SOLD OUT :(")


Lucas Garcia
Lucas Garcia
2,449 Points

I believe your error is in your while condition while tickets_remaining <=1: But you have your tickets_remaining set to 100 so they will never be less than or equal to 1 unless you sell them. while tickets_remaining >=1: This will run the loop as long as the number of tickets are greater than or equal to 1.

2 Answers

Steven Parker
Steven Parker
203,207 Points

I think you just have a typo. As Lucas pointed out, the "while" condition is false so the loop code gets skipped over.

Instead of "<=", you probably meant to write ">=" (greater or equal).

OH! thank you will add to the code

Cameron-Lee Rothenburg
Cameron-Lee Rothenburg
4,415 Points

Steven is correct. The great way I remember is to imagine the < is a crocodile. The bigger number has to go to the "mouth"

So 1 < 10 or 10 > 1 Hope that helps you remember

Steven Parker
Steven Parker
203,207 Points

So :point_right:10 :crocodile: 1
Now you've got me thinking about an "emoji programming language"... :laughing: