83.0k views
5 votes
Design and write a program that asks how many tickets for each class of seats were sold, then displays the amount of income generated from ticket sales. There are three seating categories at the stadium. Class A seats costs $20, Class B seats cost $15, and Class C seats cost $10.

i. Assume the user will enter valid data (Integer/Float).
ii. Declare Global variables, Local variables and Global constants as needed in the program
iii. Write and call function showIncome to calculate and display total income generated from ticket sales for all three Class seating categories.
iv. The program should round the amount of income generated from ticket sales to a maximum of two decimal places.

1 Answer

0 votes

Here's an example Python program that meets the requirements:

# Global constants

CLASS_A_PRICE = 20.0

CLASS_B_PRICE = 15.0

CLASS_C_PRICE = 10.0

# Function to calculate and display total income generated from ticket sales

def showIncome(numClassA, numClassB, numClassC):

# Calculate income for each class

classA_income = numClassA * CLASS_A_PRICE

classB_income = numClassB * CLASS_B_PRICE

classC_income = numClassC * CLASS_C_PRICE

# Calculate total income

total_income = classA_income + classB_income + classC_income

# Display income for each class and total income

print("Income from Class A seats: $", format(classA_income, ".2f"), sep="")

print("Income from Class B seats: $", format(classB_income, ".2f"), sep="")

print("Income from Class C seats: $", format(classC_income, ".2f"), sep="")

print("Total income from ticket sales: $", format(total_income, ".2f"), sep="")

# Main program

def main():

# Local variables

numClassA = int(input("Enter the number of Class A seats sold: "))

numClassB = int(input("Enter the number of Class B seats sold: "))

numClassC = int(input("Enter the number of Class C seats sold: "))

# Call showIncome function

showIncome(numClassA, numClassB, numClassC)

# Call main program

main()

In this program, the global constants CLASS_A_PRICE, CLASS_B_PRICE, and CLASS_C_PRICE are declared to represent the prices of each class of seat. The showIncome function takes three parameters, which represent the number of seats sold for each class, and calculates the income for each class, as well as the total income from all three classes. The main function prompts the user to enter the number of seats sold for each class, and then calls the showIncome function to display the income generated from ticket sales. The format function is used to round the income to two decimal places.

User Changdae Park
by
8.4k points