In: Computer Science
In Python
There are three seating categories at a stadium. Class A seats cost $20, Class B seats cost $15, and Class C seats cost $10. Write a program that asks how many tickets for each class of seats were sold, then display the amount of income generated from ticket sales. \
your program MUST contain a main function, a calcIncome function, and a showIncome function.
Your main function should get the number of seats sold for each category. The values should be sent to a calcIncome function.
The calcIncome function should calculate the income from each category. Those values should be returned to the main function and those values should be sent to the showIncome function.
The showIncome function should calculate the total income generated from the ticket sales, display the income generated from each category AND display the total income generated.
CODE -
# Function to calculate income generated from selling seats of
different class
def calcIncome(numClassA, numClassB, numClassC):
# Calculating the income generated from different class seats
incomeClassA = numClassA * 20
incomeClassB = numClassB * 15
incomeClassC = numClassC * 10
# Returning the incomes
return incomeClassA, incomeClassB, incomeClassC
# Function to display income generated from ticket sales
def showIncome(incomeClassA, incomeClassB, incomeClassC):
# Calculating the total income
totalIncome = incomeClassA + incomeClassB + incomeClassC
# Displaying the income generated from seats of different class and
total income generated.
print("Income generated from Class A seats = ${:.2f}"
.format(incomeClassA))
print("Income generated from Class B seats = ${:.2f}"
.format(incomeClassB))
print("Income generated from Class C seats = ${:.2f}"
.format(incomeClassC))
print("TOtal income generated = ${:.2f}" .format(totalIncome))
# Main function
def main():
# Taking number of seats sold of different class as input from
user
numClassA = int(input("Enter the number of tickets sold for class
A: "))
numClassB = int(input("Enter the number of tickets sold for class
B: "))
numClassC = int(input("Enter the number of tickets sold for class
C: "))
# Calling function to calculate income from different class
seats
incomeClassA, incomeClassB, incomeClassC = calcIncome(numClassA,
numClassB, numClassC)
# Calling function to display the income generated
showIncome(incomeClassA, incomeClassB, incomeClassC)
main()
SCREENSHOT -
If you have any doubt regarding the solution, then do
comment.
Do upvote.