因此,我正在编写一个程序,该程序应该以2的数据输入作为int的用户债务。变量是债务1和债务2。它应该将这两个值加在一起,然后根据用户的输入,使用我创建的“if/else”循环给出特定的响应。问题在于该程序仅打印出第一个“if”语句的响应,而不管输入是什么,它总是打印出“您的债务非常危险”。我该如何纠正?

**这是我的代码**

Name = input("Please enter your name: ")

debt1 = int(input("Please enter your first debt amount: "))
debt2 = int(input("Please enter your second debt amount: "))

totalDebt = debt1+debt2
print("Your total debt is ", totalDebt)

if (totalDebt > 900,000):
    print("Your debt is dangerously high ", Name)

elif((totalDebt >= 450,000 and totalDebt < 900,000)):
    print("We can help you reduce your debt.")

else:
    print("Congratulations, you know how to manage debt.")

最佳答案

请勿在数字中使用逗号:

if totalDebt > 900000:
    print("Your debt is dangerously high ", Name)
elif (totalDebt >= 450000 and totalDebt < 900000):
    print("We can help you reduce your debt.")
else:
    print("Congratulations, you know how to manage debt.")

正如@rdas所说,您可以将_用作长数字,而不是,

关于python - 如果else循环在python中无法正常运行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58192928/

10-12 07:34