Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
while loop stumbling block
#6
(Sep-09-2019, 08:25 PM)ichabod801 Wrote: You are keeping your variables separate enough. This is an outline of what your code should look like for both problems:

data = []
while True:
    next_datum = input('What is the next whatever? ')
    if next_datum == stop_value:
        break
    data.append(next_datum)
print(data)
next_datum is what they just entered. data is a list of everything valid that they entered. stop_value is whatever response stops the loop.

For the one with numbers, you want to look at the int() function to convert strings to integers.

Ok, I see, I will try and recode it following your suggested code outline, thanks again so much for your help I do appreciate it :)
Reply


Messages In This Thread
while loop stumbling block - by YoungGrassHopper - Sep-09-2019, 06:27 PM
RE: while loop stumbling block - by ichabod801 - Sep-09-2019, 06:35 PM
RE: while loop stumbling block - by ichabod801 - Sep-09-2019, 08:25 PM
RE: while loop stumbling block - by YoungGrassHopper - Sep-09-2019, 08:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Stop/continue While loop block Moris526 68 26,860 Mar-28-2021, 09:21 PM
Last Post: Larz60+
  for loop stumbling block YoungGrassHopper 8 4,766 Sep-11-2019, 03:34 PM
Last Post: YoungGrassHopper

Forum Jump:

User Panel Messages

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