216k views
0 votes
Write an application to pre-sell a limited number of cinema tickets. Each buyer can buy as many as 4 tickets. No more than 100 tickets can be sold. Implement a program that prompts the user for desired number of tickets and then display the number of remaining tickets. Do not allow the user to enter an invalid number of tickets. Repeat until all tickets have been sold, and then display the total number of buyers. Safe the file as Tickets.java.

User Rbedger
by
4.0k points

1 Answer

5 votes

Answer:

Python code explained below

Step-by-step explanation:

**CODE:

tickets = 100

count = 0

# Loop runs until tickets become zero

while tickets !=0:

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

# Taking input from user for tickets

userInput = int(input("How many tickets would you like to purchase?"))

# If user enters more than 4 tickets

if userInput > 4:

print("You cannot purchase more than 4 tickets")

# If available tickets are less than user requirment

elif tickets < userInput:

print("Available tickets are less than required")

else:

# Count increment to store the users who brought

count += 1

# Decrementing the available tickets with the user requirements

tickets -= userInput

print("Transaction successful")

print()

print("All the tickets are sold")

print("The total number of buyers was ", count)

User Will Byrne
by
3.6k points