Python 我的while循环一直在循环。我做错了什么?
在这种情况下,总金额是用户需要支付的金额。如果用户支付的金额低于总金额,系统需要减去支付金额并显示其余额,并继续循环,直到支付完成。但是,当我运行代码时,它会继续循环,同时显示平衡Python 我的while循环一直在循环。我做错了什么?,python,python-3.x,while-loop,Python,Python 3.x,While Loop,在这种情况下,总金额是用户需要支付的金额。如果用户支付的金额低于总金额,系统需要减去支付金额并显示其余额,并继续循环,直到支付完成。但是,当我运行代码时,它会继续循环,同时显示平衡 print ("Your total amount is:", total_amount) print ("") payment = int(input("Please insert your payment: ")) count = 0 wh
print ("Your total amount is:", total_amount)
print ("")
payment = int(input("Please insert your payment: "))
count = 0
while payment != total_amount:
count = total_amount - payment
print ("Your balance:", count)
payment = int(input("Please insert your payment: "))
if payment == total_amount:
print ("Successful")
如果用户在第一次输入时输入总金额,程序是否输出“成功”
如果用户在第一次输入时没有输入总金额,那么可能发生的情况是,名为payment的变量永远不会等于总金额,但计数最终将达到总金额yes,但while循环没有变量count working is logic语句,它使用payment作为其逻辑的变量。如果有人从商店买了一件东西,总共是5美元,而买主有1美元的钞票,买主会先把一美元放在柜台上,然后把另外1美元放在柜台上,依此类推。。。但是买方不会在柜台上放1美元,然后在柜台上放5美元,因为那将是6美元,因为您没有在循环中正确更新付款或总金额。我相信这应该行得通
payment = int(input("Please insert your payment: "))
while payment <= total_amount:
diff = total_amount - payment
print("Your balance:", diff)
payment += int(input("Please insert your payment: "))
if payment == total_amount:
print("Successful")
payment=int(输入(“请插入您的付款:”)
付款更改时<代码>付款!=总金额
到付款循环中您没有减少总金额
,即使我已完全付款。它不断循环“你的平衡:”语句。这是有道理的。抱歉,它应该<处于循环状态。好的,但是我应该怎么做才能使它正常工作?