gpt4 book ai didi

python - 我正在尝试制作一个输出您的信用评分的应用程序

转载 作者:太空宇宙 更新时间:2023-11-03 20:33:12 26 4
gpt4 key购买 nike

我正在尝试制作一个程序,告诉您如果房子值(value) 100 万美元,您的首付将是多少。

如果用户输入的数字不是 350 - 850 或输入非整数,那么它会要求用户输入有效的信用评分,并循环直到用户这样做。然后它会告诉用户他们需要支付多少钱。

我一整天都在为此苦苦挣扎,不知道自己做错了什么。如果有人可以帮忙吗?

good_credit = range(750, 851)
bad_credit = range(350, 750)
valid_credit_score = range(350, 851)

print("A house is $1,000,000")
question = ("What is your credit score? ")
answer = input(f"{question} ")

for answer in valid_credit_score:
credit_score = True
else:
credit_score = False

while credit_score == False:
print("Please input a valid credit score.")
answer = input(f"{question} ")
if answer == range(350, 851):
credit_score = True
break
break

while credit_score == True:
if answer == good_credit:
print("Your down payment will be $100,000.")
break
elif answer == bad_credit:
print("Your down payment will be $200,000.")
break

无论我输入什么整数,由于某种原因,它总是使credit_score变量为假。

最佳答案

这里发生了一些事情:

  1. 您正在将一个值与一个范围进行比较,例如,10 == range(0,20) 将始终返回 False。

  2. 您正在将字符串与整数进行比较。如果您检查类型,您会发现 answer 实际上是 str

type(answer)

Out[1]:
str

因此你应该尝试:

  1. if int(answer) == good_credit 替换为 if int(answer) in good_credit
  2. 将中的answer ==替换为int(answer)



good_credit = range(750, 851)
bad_credit = range(350, 750)
valid_credit_score = range(350, 851)

print("A house is $1,000,000")
question = ("What is your credit score? ")
answer = input(f"{question} ")

if int(answer) in valid_credit_score:
credit_score = True
else:
credit_score = False

while credit_score == False:
print("Please input a valid credit score.")
answer = input(f"{question} ")
if int(answer) in range(350, 851):
credit_score = True
break
break

while credit_score == True:
if int(answer) in good_credit:
print("Your down payment will be $100,000.")
break
elif int(answer) in bad_credit:
print("Your down payment will be $200,000.")
break

关于python - 我正在尝试制作一个输出您的信用评分的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57351362/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com