【发布时间】:2021-08-26 00:36:15
【问题描述】:
我想知道您是否可以再次帮助我。 仍然在入门级挣扎..
这一次,我冒险看看我是否可以编写一个简单的贷款模拟器,就像你看到的那样,找出你可以获得的最大抵押贷款金额。
我写了这个(不知道它是否运行到最后,并且可能写得不好),但它告诉我我在问题 5 中写错了一些东西,并告诉我一些关于“NoneType”的信息。 我有点理解“NoneType”是什么,但我不明白哪里错了。
我也不明白为什么它没有在之前的第三季度和第四季度向我抛出这个问题。
如果有人可以提供帮助,非常感谢!
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'
---
【问题讨论】:
-
你写的是
q5 = print而不是q5 = input() -
所以你得到 Nonetype 的原因让我解释一下
print()是一个函数,但print()函数不返回任何输出只是认为它做了一些操作,当你分配一个变量@ 987654327@ python 为您提供函数的变量返回值,因此print()函数输出为无,因此变量q5输出为无None -
所以如果
print()函数返回值1,变量q5 would be 1的值但是print()不返回任何值print()默认是None。跨度> -
所以你的代码的主要问题是你写了
q5 = print()而不是q5 = input() -
天啊!我真傻!对不起,我刚下班。非常感谢!也感谢您对 print() 函数的友好提示!你太客气了!