类型错误:不支持的操作数类型Int和NoneType [英] Type Error: Unsupported operand types Int and NoneType

查看:529
本文介绍了类型错误:不支持的操作数类型Int和NoneType的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我正在研究python程序,但我不断从循环中返回错误,这应该只是提示用户输入数字.我遇到的问题是,它不断返回一个无法用于我需要在其他功能中进行操作的nonetype,因此需要任何帮助.谢谢.

Hey guys I am working on a python program and I keep getting errors returned from the loop which is supposed to just reprompt the user to enter a number. The problem I am having is that it keeps returning a nonetype which cannot be used to operate on which I need to do in on of the other functions any help is appreciated. Thanks.

(这是我的代码,抱歉,如果格式不正确.)

( Here's my code, Sorry ahead of time if it is not formatted correctly. )

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)

推荐答案

您没有在else块内返回getTickets(limit):

def getTickets(limit):
   ticketSold=int(input("How many tickets were sold? "))
   if (ticketsValid(ticketSold,limit)):
        return ticketSold
   else:
        return getTickets(limit)  # You need to use return here

这篇关于类型错误:不支持的操作数类型Int和NoneType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆