【发布时间】:2014-04-20 09:34:42
【问题描述】:
大家好,我正在开发一个 python 程序,我不断收到从循环返回的错误,这应该只是重新提示用户输入一个数字。我遇到的问题是它不断返回一个无法用于操作的非类型,我需要在其他功能上执行任何帮助。谢谢。
(这是我的代码,如果格式不正确,请提前道歉。)
def getTickets(limit):
ticketSold=int(input("How many tickets were sold? "))
if (ticketsValid(ticketSold,limit)):
return ticketSold
else:
getTickets(limit)
#This function checks to make sure that the sold tickets are within the Limit of seats
def ticketsValid(sold,limit):
if (sold>limit or sold<0):
print ("ERROR: There must be tickets less than "+str(limit)+" and more than 0")
return False
return True
# This function calculates the price of the tickets sold in the section.
def calcIncome(ticketSold,price):
return ticketSold*(price)
【问题讨论】:
-
回溯说错误在哪里? (哪一行?)
-
在
def getTickets的最后一行将getTickets(limit)改为return getTickets(limit)