Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Python

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 (using functions) that asks how many tickets for each class of seats were sold, and then displays the amount of income generated from ticket sales.

This is what i have so far but it wont run :(.

Python
def main ( ) : 
      intro ( )
      readinput ( )
      calculatedsales ( )

#this function prints welcome to the ticket sales program the cost of each seat is as follows ect
def intro ( ) :
print ("welcome to the ticket sales program")
print ("the cost of each seat is as follows, seat a=15, seat b=12, seat c=9")

#this function prompts the user to input each sections sales and returns each value.
def readinput ( ) :
section_a = int ( input ( "how many tickets sold for section a=")
section_b = int ( input ( "how many tickets sold for section b=")
section_c = int ( input ( "how many tickets sold for section c=")
return (section_a,section_b,section_c)

#this function grabs input from readinput and calculates each task.
def calculatedsales (section_a, section_b, section_c) :
sales_a = section_a*15
sales_b = section_b*12
sales_c = section_c*9  
total_sales = sales_a + sales_b + sales_c
print ("total sales = {0:.2f}".format(total_sales)

main()


running the program:

welcome to the ticket sales program
the cost of each seat is as follows, seat a=15, seat b=12, seat c=9
how many tickets sold for section a=2 (i inputed these values)
how many tickets sold for section b=3
how many tickets sold for section c=1
Traceback (most recent call last):
File "/Users/nathandavis9752/CP104/testing/src/testing.py", line 40, in <module>
main()
File "/Users/nathandavis9752/CP104/testing/src/testing.py", line 15, in main
calculatedsales ( )
TypeError: calculatedsales() takes exactly 3 arguments (0 given)
Posted
Updated 31-Jan-15 13:50pm
v4
Comments
Garth J Lancaster 31-Jan-15 19:44pm    
saying "but it wont run" is as useful to anyone who may be able to help you, as t*ts on a bull - you need to describe what actually happens - do you get an error message, an exception, a bad answer, does the program stop on line x, etc - please update your question with any more pertinent info you have
Member 11417510 31-Jan-15 20:00pm    
sorry first time on this site, really appreciate you getting back to me. I just updated it with the error message. please let me know if the error message is enough to help me out or if i need to add more information. Thanks a bunch.

1 solution

In your main method, you call calculatedsales() without arguments, but that function expects three arguments. I assume you want to pass the inputted values to that function. In that case, try this:
Python
def main():
    intro()
    section_a, section_b, section_c = readinput()
    calculatedsales(section_a, section_b, section_c)

Also, there are some syntax and indentation errors in your code: Python has strict indentation rules, and there are also some missing parentheses in the code. Here is the code with the TypeError fixed and with correct syntax and indentation:
Python
def main():
    intro()
    section_a, section_b, section_c = readinput()
    calculatedsales(section_a, section_b, section_c)
 
#this function prints welcome to the ticket sales program the cost of each seat is as follows ect
def intro():
    print("welcome to the ticket sales program")
    print("the cost of each seat is as follows, seat a=15, seat b=12, seat c=9")
 
#this function prompts the user to input each sections sales and returns each value.
def readinput():
    section_a = int(input("how many tickets sold for section a="))
    section_b = int(input("how many tickets sold for section b="))
    section_c = int(input("how many tickets sold for section c="))
    return (section_a,section_b,section_c)
 
#this function grabs input from readinput and calculates each task.
def calculatedsales(section_a, section_b, section_c):
    sales_a = section_a*15
    sales_b = section_b*12
    sales_c = section_c*9  
    total_sales = sales_a + sales_b + sales_c
    print("total sales = {0:.2f}".format(total_sales))

main()
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900