本文介绍了使用函数帮助编写程序。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


体育场有三种座位类别。对于垒球比赛,A级座位售价15美元,B级座位售价12美元,C级座位售价9美元。编写一个程序(使用函数),询问每类座位的售票数量,然后显示售票所产生的收入金额。



这是我到目前为止但它不会运行:(。



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 :(.

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()





正在运行程序:



欢迎来到售票计划

每个座位的费用如下,座位a = 15,座位b = 12,座位c = 9

为a = 2出售了多少张门票(我输入了这些值)

为b部分出售了多少张门票= 3

为c = 1卖出多少票?

Traceback(最近一次调用最后一次):

文件/ Users / nathandavis9752 / CP104 / testing / src / testing.py,第40行,在< module>

main()

文件/Users/nathandavis9752/CP104/testing/src/testing.py,第15行,主要是

calculatedsales()

TypeErr或:calculatedsales()正好需要3个参数(0给定)



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)

推荐答案



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()





正在运行程序:



欢迎来到售票计划

每个座位的费用如下,座位a = 15,座位b = 12,座位c = 9

为a = 2出售了多少张门票(我输入了这些值)

为b部分出售了多少张门票= 3

为c = 1卖出多少票?

Traceback(最近一次调用最后一次):

文件/ Users / nathandavis9752 / CP104 / testing / src / testing.py,第40行,在< module>

main()

文件/Users/nathandavis9752/CP104/testing/src/testing.py,第15行,主要是

calculatedsales()

TypeErr或:calculatedsales()正好取3个参数(0给定)



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)


这篇关于使用函数帮助编写程序。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 06:03