【发布时间】:2020-01-31 05:25:41
【问题描述】:
所以我正在编写一个程序,该程序应该将 2 个数据输入作为 int 用于用户的债务。变量是debt1 和debt2。它应该将这两个值相加,然后根据用户的输入,它应该使用我创建的“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.")
【问题讨论】:
-
900,000不是有效数字 -
在 python 3 中,您可以使用
_代替,用于包含大量零的数字。900_000会起作用。
标签: python if-statement error-handling logic runtime-error