Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
while loop
#1
So I was required to solve this question: Write a program to use a while loop to read the numbers from the user repeatedly until he/she inputs 0. Then report the sum of these numbers and the minimum value among them.

And my code for the sum part is like this:
sum1 = 0
n = int(input())
while n != 0:
    sum1 += n
print(sum1)
But when I run the code and input some integer, it does not show the sum although I have input a 0 lastly. Could someone tell me what the problem is in my code?
Reply


Messages In This Thread
while loop - by idddj - Oct-01-2022, 08:22 AM
RE: while loop - by Yoriz - Oct-01-2022, 08:39 AM
RE: while loop - by idddj - Oct-01-2022, 08:43 AM
RE: while loop - by Yoriz - Oct-01-2022, 08:47 AM
RE: while loop - by rob101 - Oct-01-2022, 09:19 AM
RE: while loop - by idddj - Oct-01-2022, 01:45 PM
RE: while loop - by rob101 - Oct-01-2022, 02:02 PM
RE: while loop - by idddj - Oct-01-2022, 02:04 PM
RE: while loop - by jefsummers - Oct-03-2022, 05:03 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020