Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Infinite loop
#1
# [ ] use a "forever" while loop to get user input of integers to add to sum,
# until a non-digit is entered, then break the loop and print sum
sum = 0

the best I was able to think up doesn't work
while True:
    sum = ''
	sum1 = input("add number: ")
	if sum1.isdigit():
	    sum = sum + sum1
	else:
	    break
		print(sum)
Suggestions are welcome.
Reply


Messages In This Thread
Infinite loop - by Truman - Jan-18-2018, 10:54 PM
RE: Infinite loop - by Larz60+ - Jan-18-2018, 10:57 PM
RE: Infinite loop - by Truman - Jan-18-2018, 11:03 PM
RE: Infinite loop - by Larz60+ - Jan-19-2018, 12:02 AM
RE: Infinite loop - by Truman - Jan-19-2018, 10:37 PM
RE: Infinite loop - by buran - Jan-19-2018, 12:14 PM
RE: Infinite loop - by wavic - Jan-19-2018, 12:34 PM
RE: Infinite loop - by j.crater - Jan-19-2018, 10:49 PM
RE: Infinite loop - by Truman - Jan-19-2018, 11:22 PM
RE: Infinite loop - by j.crater - Jan-19-2018, 11:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Infinite loop Danado 4 2,389 Aug-16-2021, 05:56 PM
Last Post: deanhystad
  Help with while loop creating an infinite loop. FWendeburg 3 3,071 Jan-30-2019, 08:28 PM
Last Post: FWendeburg
  Infinite loop/ only half working anclark686 5 4,800 Sep-09-2018, 07:31 AM
Last Post: buran
  Why is this giving me an infinite loop? wlsa 4 3,958 Jul-25-2018, 10:11 PM
Last Post: cyberpatje
  Another infinite loop wlsa 7 4,723 Jul-20-2018, 12:04 AM
Last Post: wlsa
  How to stop an infinite loop in spyder if it's currently running? wlsa 3 24,763 Jun-30-2018, 03:27 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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