【发布时间】:2020-04-09 04:16:15
【问题描述】:
我需要编写一个使用 FOR 循环的程序,向用户索要 7 笔存款。当用户输入存款金额时,需要使用累积概念更新余额。
此外,还要计算大于或等于 1000 美元、500 到 999 美元、100 到 499 美元以及 0 到 99 美元的存款数量。 输出 = 显示上述每个组的计数和所有存款的最终余额。
问题:最后输入的数字(存款)是唯一正在注册的数字
amount1000orover = 0
amount500to999 = 0
amount100to499 = 0
less99 = 0
total = 0
for count in range(7):
deposit = int(input("Please enter your deposit amount: "))
if deposit >= 1000:
amount1000orover + 1
total=total + deposit
if deposit>=500 and deposit<=999:
amount500to999 = amount500to999 + 1
total=total + deposit
if deposit>= 100 and deposit<=499:
amount100to499 = amount100to499 + 1
total=total + deposit
if deposit>=0 and deposit<=99:
less99 = less99 + 1
total=total + deposit
print("You have "+str(amount1000orover)+" deposit over or equal to 1000 dollars.")
print("You have "+str(amount500to999)+" deposit between 500 and 999 dollars.")
print("You have "+str(amount100to499)+" deposit between 100 and 499 dollars. ")
print("You have "+str(less99)+" deposit below 100 dollars.")
print("Your balance is : "+str(total))
【问题讨论】:
-
这真的是缩进的样子吗?那些
if语句是否应该在循环中缩进? -
我猜这是真正的缩进,为什么只添加最后一个
deposit是有道理的。
标签: python python-3.x loops coding-style accumulator