Python Forum
while with a conditional test
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
while with a conditional test
#3
That's because you're getting input after the loop has already been entered.

One way to fix this would be to get input once before the loop is started, and then get it again at the end of each iteration:
age = input(prompt)
while age.lower() != 'quit':
    # do stuff
    age = input(prompt)
Another option is using a for loop with iter():
for age in iter(lambda: input(prompt).lower(), 'quit'):
    # do stuff
Reply


Messages In This Thread
while with a conditional test - by driep - Apr-16-2018, 08:30 AM
RE: while with a conditional test - by j.crater - Apr-16-2018, 08:37 AM
RE: while with a conditional test - by stranac - Apr-16-2018, 08:40 AM
RE: while with a conditional test - by driep - Apr-16-2018, 12:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to test and import a model form computer to test accuracy using Sklearn library Anldra12 6 3,204 Jul-03-2021, 10:07 AM
Last Post: Anldra12
  How to write test cases for a init function by Unit test in python? binhduonggttn 2 3,159 Feb-24-2020, 12:06 PM
Last Post: Larz60+
  How to write test cases by Unit test for database configuration file? binhduonggttn 0 2,589 Feb-18-2020, 08:03 AM
Last Post: binhduonggttn

Forum Jump:

User Panel Messages

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