Respuesta :
Answer:
Following are the program to this question:
def calculate_income(num,seat):#defining method calculate_income
if seat=="A": #defining condition for seat a
return num * 20 #return value
if seat=="B": #defining condition for seat b
return num * 15 #return value
if seat=="C": #defining condition for seat c
return num * 10 #return value
def show_income(a,b,c): #defining method show_Income
sum=a+b+c # add total seats income
print("Income for A class seats: $",a) #print value
print("Income for B class seats: $",b) #print value
print("Income for C class seats: $",c) #print value
print("Total Income: $",sum) #print value
def main(): # defining main method
a=int(input("Enter class A seats: ")) #input seats a value
b=int(input("Enter class B seats: ")) #input seats b value
c=int(input("Enter class C seats: ")) #input seats c value
a_income=calculate_income(a,"A") #call method for seat a
b_income=calculate_income(b,"B") #call method for seat b
c_income=calculate_income(c,"C") #call method for seat c
show_income(a_income,b_income,c_income) # call method show_income for print all seat value
main()
Output:
Enter class A seats: 2
Enter class B seats: 3
Enter class C seats: 2
Income for A class seats: $ 40
Income for B class seats: $ 45
Income for C class seats: $ 20
Total Income: $ 105
Explanation:
The description of the above program can be described as follows:
- In the above python program, three methods "calculate_income, show_income, and the main method" were defined.
- The method "calculate_income" accepts two-variable "num and seat" as the parameter, inside the method a three if block is used, that calculate all types of seat class rate and returns its value.
- In the "show_income", we add all the seat value in the sum variable and use the print method, that prints all seat cost, and total cost.
- In the main method, we input all seat value from user input and pass into the calculate_income method and collect all the return value, after calculating calculate_income we pass its return value into the show_income method, that prints all value.