Python 错误消息";int()参数";及;“非类型”;

Python 错误消息";int()参数";及;“非类型”;,python,integer,nonetype,Python,Integer,Nonetype,我想知道你是否能再次帮助我。 仍在初级阶段挣扎 这一次,我想看看是否可以编写一个简单的贷款模拟器,就像你看到的那样,找出你能得到的最大抵押金额 我写了这个(不知道它是否会一直写到最后,可能写得很糟糕),但它告诉我,我在问题5中写了一些错误的东西,并告诉我一些关于“非类型”的东西。 我有点理解“非类型”是什么,但我不明白它错在哪里 我也不明白为什么它在上一个第三季度和第四季度没有把这件事告诉我 如果有人能帮忙,我将不胜感激 Z -- 但我明白了 Traceback (most recent ca

我想知道你是否能再次帮助我。 仍在初级阶段挣扎

这一次,我想看看是否可以编写一个简单的贷款模拟器,就像你看到的那样,找出你能得到的最大抵押金额

我写了这个(不知道它是否会一直写到最后,可能写得很糟糕),但它告诉我,我在问题5中写了一些错误的东西,并告诉我一些关于“非类型”的东西。 我有点理解“非类型”是什么,但我不明白它错在哪里

我也不明白为什么它在上一个第三季度和第四季度没有把这件事告诉我

如果有人能帮忙,我将不胜感激

Z


-- 但我明白了

Traceback (most recent call last):
 q5 = int(q5)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

---
这是您的代码:

def lc(v, w, x=0, y=1, z=1):
    """returns the maximum amount the bank can extend to you as a loan."""
    return (v*w+x)*y*z

q1 = input("Enter your monthly income in 1 man-yen units")
v = 12*0.8*int(q1)

q2 = input("Enter the years you have left at your workplace")
w = int(q2)

q3 = input("Do you have any assets? If you do, write that amount in man-yen units. If none write 'n'")
try:
    x = int(q3)
except(ValueError):
    print("Okay, it is understood that you have no assets.")

q4 = input("If you dependants, write that number as an interger. If none write 'n'")
try:
    q4 = int(q4)
    a4 = 1-0.1*q4
except(ValueError):
    print("Okay, it is understood that you have no dependants.")

q5 = input("Write the number of times you went to hospital last year. If you havent been at all write 'n'")
try:
    q5 = int(q5)
    a5 = 1-0.1*q5
except(ValueError):
    print("Okay, it is understood that you did not go to the hospital at all last year.")

lc
print(lc)

在最后两行中,我没有得到您想要做的事情是否要调用函数lc?

您所做的一切都是一个愚蠢的错误。在定义
q5
时,您必须将
input
而不是
print
。这是解决办法

q5=input(“写下你去年去医院的次数。如果你根本没有去过医院,请写‘n’”)
如果q5.是_位():
q5=int(q5)
a5=1-(0.1*Q5)
其他:
打印(“好的,据了解你去年根本没有去医院”)

我对你的代码做了一些修改,使之更快!!您的欢迎

您编写了
q5=print
而不是
q5=input()
所以您得到Nonetype的原因让我解释一下
print()
是一个函数,但是
print()
函数不返回任何输出,只要认为它执行了一些操作,当您分配变量
a=print()时
python为您提供函数的变量返回值,因此
print()
函数输出为None,因此变量
q5
输出为None
None
因此如果
print()
函数将返回值1,则变量
q5的值将为1,但作为
print()
不返回
print()
的任何值默认情况下为
None
。因此,代码的主要问题是您编写了
q5=print()
,而不是
q5=input()
OMG!我真傻!对不起,我刚下班。非常感谢你!同时也感谢您提供有关print()函数的技巧!你太好了!再次感谢Rohit12345!没问题,这是我的工作。请你把我的答案投给Alpha Wolf玩家,很抱歉这么晚才回来。刚下班。非常感谢您特意指出这一点!
def lc(v, w, x=0, y=1, z=1):
    """returns the maximum amount the bank can extend to you as a loan."""
    return (v*w+x)*y*z

q1 = input("Enter your monthly income in 1 man-yen units")
v = 12*0.8*int(q1)

q2 = input("Enter the years you have left at your workplace")
w = int(q2)

q3 = input("Do you have any assets? If you do, write that amount in man-yen units. If none write 'n'")
try:
    x = int(q3)
except(ValueError):
    print("Okay, it is understood that you have no assets.")

q4 = input("If you dependants, write that number as an interger. If none write 'n'")
try:
    q4 = int(q4)
    a4 = 1-0.1*q4
except(ValueError):
    print("Okay, it is understood that you have no dependants.")

q5 = input("Write the number of times you went to hospital last year. If you havent been at all write 'n'")
try:
    q5 = int(q5)
    a5 = 1-0.1*q5
except(ValueError):
    print("Okay, it is understood that you did not go to the hospital at all last year.")

lc
print(lc)