I would like the Buyer Number to change every time there is a new buyer
total = 200 # Assigns 200 tickets to variable total
sold = 0 # Assigns 0 tickets to variable sold
count = 0
while sold < total: # Runs while loop as long as tickets sold is less than total tickets
remaining = total - sold # Assigns total - sold to variable remaining
if sold == 0: # If tickets are equal to 0
print("Welcome to Movies4Us!") # Prints "Welcome to Movies4Us!" if condition above is satisfied
else:
print('You are buyer NO.', count + 1, "." "The number of remaining tickets is now", remaining, ".") # Prints user's number and remaining amount of tickets
name = input('What is your name?: ')
tickets = input("How many tickets would you like to purchase?: ") # Asks user to enter desired amount of tickets to purchase
try:
tickets = int(tickets) # Converts variable tickets to integer type
if tickets > remaining: # If user enters more tickets than remaining tickets available
print("Sorry, there aren't that many tickets available.") # Prints no more tickets available
else:
sold += tickets # Updates value of variable sold into tickets
print("You have purchased", tickets, "tickets, Enjoy the movie", name, '!') # Prints the amount of tickets the user purchased
except ValueError: # If user inputs anything except for an integer
print("Invalid input. Please enter a number.") # Prints invalid input and asks user to input again
continue # Ends current loop and runs the while loop again
print ("There are no more tickets available.") # If number of tickets reached 0, program ends
Tried adding count = 0 and count + 1
>Solution :
You’ve already initialized a counter: count = 0. You just need to increment it inside the loop whenever a valid ticket purchase is made.
Add count += 1 inside the else block where a valid ticket purchase is made under the statement sold += tickets. This will increment the counter whenever a successful purchase happens.