嘿,伙计们,我正在开发一个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)
如果不返回任何内容,Python函数默认返回
None
。您有一个else
子句,它调用一个函数,但对它不做任何操作,并且函数结束于此,因此如果它沿着控制流路径走下去,您将从该函数返回None
。您不会在
else
块中返回getTickets(limit)
:相关问题 更多 >
编程相关推荐