错误消息“int() 参数”和“NoneType”

时间:2021-06-09 02:41:51

标签: python integer nonetype

我想知道你是否可以再次帮助我。 还在入门级苦苦挣扎..

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

我写了这个(不知道它是否运行到最后,可能写得不好),但它告诉我我在问题 5 中写错了一些东西,并告诉我一些关于“NoneType”的信息。 我有点理解“NoneType”是什么,但我不明白它错在哪里。

我也不明白为什么它在之前的 q3 和 q4 中没有向我抛出这个。

如果有人能帮忙,非常感谢!

Z


#lc is total lending capacity v is income w is years left x is asset y is dependents z is healthrisk

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 = print("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)

-- 但我明白了...

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

---

2 个答案:

答案 0 :(得分:0)

你所做的只是犯了一个愚蠢的错误。在定义 input 时,您必须使用 print 而不是 q5。这是修复

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

我对您的代码进行了一些更改,以使速度更快!!欢迎您

答案 1 :(得分:-1)

这是你的代码:

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)

I did not get what you want to do in the last two lines do you want to call the function lc?

相关问题