def main():
section = 'A'
while section:
section = (input('What section are you inputing ticket numbers for? '))
if section in ('a', 'A') :
limit = 300
cost = 20
ticketSold = getTickets(section, limit)
sectionACost = calcIncome(ticketSold, cost)
elif section in ('b', 'B'):
limit = 500
cost = 15
ticketSold = getTickets(section, limit)
sectionBCost = calcIncome(ticketSold, cost)
elif section in ('c', 'C'):
limit = 200
cost = 10
ticketSold = getTickets(section, limit)
sectionBCost = calcIncome(ticketSold, cost)
displayTotals()
def getTickets(section, limit):
ticketSold = int(input('How many tickets were sold? '))
return int(ticketSold)
if ticketsValid(ticketSold, limit):
return ticketsValid
def ticketsValid(ticketSold, limit):
if ticketSold <= limit:
status = True
else:
status = False
return status
def calcIncome(ticketSold, cost):
sectionIncome = ticketSold * cost
return sectionIncome
def displayTotals():
print('Section A generated {}'.format(sectionACost))
print('Section B generated {}'.format(sectionBCost))
print('Section C generated {}'.format(sectionCCost))
totalRevenue = sectionACost + sectionBCost + sectionCCost
print('The total revenue is {}'(totalRevenue))
main()
我的问题是循环不能退出来显示总数
其他问题要求:
•创建一个主模块作为程序启动模块
•在主模块中使用本地命名常量,用于座位成本和章节座位限制,这些将传递给以下各点所述的模块和功能。在
•尽管问题中有三个座位区,但将根据传递的参数创建一组通用模块和函数,用于任何给定的部分。这些功能的一般逻辑描述如下:
o包含输入函数(getTickets),该函数将给定部分的节字母和座位限制作为参数。返回给定区段的票数。此函数只应返回有效票证数;应从该函数调用验证函数ticketsValid。在
o包括验证功能(ticketsValid),该功能将每节售出的车票和每节的座位限制作为通过的参数。返回一个布尔值,该布尔值指示为给定部分售出的已通过票证是否在有效范围内。此验证函数将从先前定义的getTickets函数中调用。在
o包含收入计算功能(Calincome),该功能将售出的机票和座位成本作为传递的参数,并返回该部分产生的收入。在
•确保使用currencyFormat
在我解决您的主要问题之前,该代码中存在一些问题:
既然我们已经解决了这个问题,让我们来回答这个问题:
当前编写代码的方式很简单,因为您只调用
main
一次,并且只对部分调用main进程。答案总是指向0
,只有一个部分除外。在但是,让我们看看如果我们假设您连续调用
^{pr2}$main
直到满足某个条件,会发生什么情况:好吧,我们可能会看到一些相当复杂的解决方案,但是基于这段代码,我将假设最简单的事情:每个部分一个变量。我们可以用全球名字
我们需要一个函数来显示最终总数:
(旁白:如果不清楚,我这里的目标并不是解决现实问题的最佳解决方案——我在假设OP在课程中的位置,并试图通过使用复杂的数据结构或聚合器来避免跳得太远。我也试图不给出完整的答案,而是在vein of how to answer a homework question中回答。)
相关问题 更多 >
编程相关推荐