SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Tony Gaddis
Chapter:
Simple Functions
Exercise:
Programming Exercises
Question:8 | ISBN:9780132576376 | Edition: 2

Question

There are three seating categories at a stadium. For a softball game, Class A seats cost $15,Class B seats cost $12, and Class C seats cost $9. Write a program that asks how many tick-ets for each class of seats were sold, and then displays the amount of income generated from ticket sales.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Python program code:

#The method 'calculate_income' is used to 
#the amount of income generated from ticket sales
def calculate_income(class_a_tickets, class_b_tickets, class_c_tickets):
    class_a_income = class_a_tickets * 15
    class_b_income = class_b_tickets * 12
    class_c_income = class_c_tickets * 9
    total_income = class_a_income + class_b_income + class_c_income
    return total_income
#main method
def main():
    #Prompt and asks how many tick-ets for each class 
    #of seats were sold, and then displays the amount 
    #of income generated from ticket sales.
    class_a_tickets = int(input("Enter the number of Class A tickets sold: "))
    class_b_tickets = int(input("Enter the number of Class B tickets sold: "))
    class_c_tickets = int(input("Enter the number of Class C tickets sold: "))
    #Call the method
    total_income = calculate_income(class_a_tickets, class_b_tickets, class_c_tickets)
    #Display output
    print("Total income from ticket sales: $", total_income)
if __name__ == "__main__":
    main()

Executed Output:

Enter the number of Class A tickets sold: 100
Enter the number of Class B tickets sold: 100
Enter the number of Class C tickets sold: 200
Total income from ticket sales: $ 4500

 

0 0

Discussions

Post the discussion to improve the above solution.