python中的If-else循环无法正常运行

2024-06-17 01:43:51 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我在写一个程序,它应该接受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.")

Tags: 用户程序inputyourifelseintprint
1条回答
网友
1楼 · 发布于 2024-06-17 01:43:51

在数字中不要使用逗号:

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所说,您可以使用_代替,来表示长数字

相关问题 更多 >