I designed an input
A python program based on the sum of deposits for each day within 7 days
I hope the execution result is:
Please enter the deposit on day 1: 40
Please enter the deposit on day 2: 70
Please enter the deposit on day 3: 89
Please enter the 4th day deposit: 489
Please enter the 5th day deposit: 39
Please enter the deposit on day 6: 48
Please enter the 7th day deposit: 99
Total deposit: 874 dollar
But the problem with my python program is
Circulate from the deposit on the first day to after the deposit on the seventh day
Unable to add up smoothly, but re-start the cycle from the first day of deposit
In an infinite loop
My code:
sum1=0
mes=list()
while True:
for mes in range(1,8):
mey=int(input(f"Please enter the deposit on day {mes}:"))
if mes==7:
break
mes.append(mey)
sum1+=mey
print("Total Deposit",str(mes),"dollar")
forloop and thewhileloop. You have only onebreakstatement. Thebreakstatement exits the for loop. Then goes back to the while loop and starts all over again. The code you have posted and the output you shared are not the same. Day 4, 5, and 7 code looks different. Also, why are you checking formes==7, the for loop will exit oncemesreaches 8. In summary, you just need the for loop. You can remove the while loop.