Question

# Write a program to pre-sell a limited number of cinema tickets. Each buyer can buy as...

1. Write a program to pre-sell a limited number of cinema tickets. Each buyer can buy as many as 4 tickets. No more than 20 tickets can be sold. Implement a program called TicketSeller that prompts the user for the desired number of tickets and then displays the number of remaining tickets. Repeat until all tickets have been sold, and then display the total number of buyers.4 pts

Loop

There are currently xxx tickets remaining.

How many tickets would you like to purchase?

(make sure you print an error message if they try to buy more than 4)

The total number of buyers was xxx.

python, keep it simple

``````def TicketSeller():

#initialize available_tickets to 20
available_tickets = 20

#count is used to keep track of no of customers
count = 0
flag = 1

#to continue run loop untill available_tickets becomes 0
while(flag == 1):

print("There are currently",available_tickets ,"tickets remaining")

#takes the no of tickets entered by user and store it in a tickets variable
tickets = int(input("How many tickets would you like to purchase? "))

#if user entered more than 4 tickets then prints the error message
if(tickets > 4):
print("You can buy maximum 4 tickets!!!")

#if available_tickets < tickets then prints message
if(available_tickets < tickets):
print("Only ",available_tickets,"tickets available !!!")

#if user entered less than or equal to 4 and
#available_tickets is greater than or equal to tickets
#than increment the count of customer
# reduce the available_tickets value
if(tickets <= 4 and available_tickets >= tickets ):
count = count + 1
available_tickets = available_tickets - tickets

#if available_tickets is 0 then set flag to 0 so while loop terminates
if(available_tickets <= 0):
flag = 0;

#returns the customer count
return count

#stores the count returned by the TicketSeller method in buyers variable

#print the result

``````

OUTPUT: