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....
Write a program (C language) that will read the number of a month and will print...
Write a program (C language) that will read the number of a month and will print the number of days in the month. Ignore leap years. Use 28 days for February. Have the program runs in a continuous loop, allowing the user to enter a month number, see that number of days, and repeat. Use month number = 0 to exit the loop and the program. Program must meet the following criteria: 1.Your name and the name of the program...
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....
In each of the projects that follow, you should write a program that contains an introductory...
In each of the projects that follow, you should write a program that contains an introductory docstring. This documentation should describe what the program will do (analysis) and how it will do it (design the program in the form of a pseudocode algorithm). Include suitable prompts for all inputs, and label all outputs appropri- ately. After you have coded a program, be sure to test it with a reasonable set of legitimate inputs. 1 The tax calculator program of the...
Ice Cream Program Assignment Write a program in c# that uses a function to ask the...
Ice Cream Program Assignment Write a program in c# that uses a function to ask the user to choose an ice cream flavor from a menu (see output below.) You must validate the users input for the flavor of ice cream accounting for both upper and lower-case letters. You must give them an appropriate error message and allow them to try again.   Once you have a valid flavor, your function will return the flavor back to the main() function.   ...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT