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

Homework Answers

Answer #1
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
buyers = TicketSeller()

#print the result
print("The total number of buyers was: ",buyers)

OUTPUT:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a PYTHON program that displays a weekly payroll report. A loop in the program should...
Write a PYTHON program that displays a weekly payroll report. A loop in the program should ask the user for the employee number, gross pay, state tax, federal tax, and FICA withholdings. The loop will terminate when 0 is entered for the employee number. After the data is entered, the program should display totals for gross pay, state tax, federal tax, FICA withholdings, and net pay. Input Validation: ▪ Do not accept negative numbers for any of the items entered....
Python: Write a program that prompts the user to enter a positive integer value, and compute...
Python: Write a program that prompts the user to enter a positive integer value, and compute the following sequence: • If the value is even, halve it. • If it's odd, multiply by 3 and add 1. • Repeat this process until the value is 1, printing out each value. • Then print out how many of these operations you performed. If the input value is less than 1, print a message containing the word Error and exit the program....
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
In this assignment you will write a program that compares the relative strengths of two earthquakes,...
In this assignment you will write a program that compares the relative strengths of two earthquakes, given their magnitudes using the moment magnitude scale. Earthquakes The amount of energy released during an earthquake -- corresponding to the amount of shaking -- is measured using the "moment magnitude scale". We can compare the relative strength of two earthquakes given the magnitudes m1 and m2 using this formula: f=10^1.5(m1−m2) If m1>m2, the resulting value f tells us how many times stronger m1...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...
Topics Arrays Accessing Arrays Description Write a C++ program that will display a number of statistics...
Topics Arrays Accessing Arrays Description Write a C++ program that will display a number of statistics relating to data supplied by the user. The program will ask the user to enter the number of items making up the data. It will then ask the user to enter data items one by one. It will store the data items in a double array. Then it will perform a number of statistical operations on the data. Finally, it will display a report...
1.) True or False? For all societies, resources are scarce, and technology is limited, while people’s...
1.) True or False? For all societies, resources are scarce, and technology is limited, while people’s wants and needs for goods and services seem to be unlimited. (2 points) 2.) (1 point) Adam Smith’s “invisible hand” refers to a.) the subtle and often hidden methods that businesses use to profit at consumers’ expense. b.) the ability of free markets to reach desirable outcomes, despite the self-interest of market participants. c.) the ability of government regulations to benefit consumers, even if...
Discuss ethical issues that can be identified in this case and the mode of managing ethics...
Discuss ethical issues that can be identified in this case and the mode of managing ethics Enron finds itself in this case. How would you describe the ethical culture and levels of trust at Enron? Provide reasons for your assessment. THE FALL OF ENRON: A STAKEHOLDER FAILURE Once upon a time, there was a gleaming headquarters office tower in Houston, with a giant tilted "£"' in front, slowly revolving in the Texas sun. The Enron Corporation, which once ranked among...
1. The failure of the new supply chain system affected Nike adversely. What were the reasons...
1. The failure of the new supply chain system affected Nike adversely. What were the reasons for the failure and how did the breakdown harm Nike? 2. What are the important elements to be kept in mind while implementing a new system in an organization? What is the importance of a good working relationship between partners and the sharing of responsibility in implementing critical projects? What mistakes did Nike and i2 make? 3. comment on the lessons learned and the...