Python Forum
validating user input and loops
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
validating user input and loops
#7
Quote:
    mon = input("How many bottles did you return on Monday: ")
    is_valid = is_valid_integer(input_string)
    while not is_valid:
        mon = input("Nice try, please enter a whole number! ")
        is_valid = is_valid_integer(input_string)

You're checking if input_string is a number, but you never set input_string, so it'll never be a number.  Instead, you set mon, but then never use mon for anything.

That's why you're stuck in the loop.
Reply


Messages In This Thread
validating user input and loops - by Austin11 - Nov-02-2017, 03:50 PM
RE: validating user input and loops - by Larz60+ - Nov-02-2017, 04:09 PM
RE: validating user input and loops - by Austin11 - Nov-02-2017, 04:51 PM
RE: validating user input and loops - by Larz60+ - Nov-02-2017, 07:25 PM
RE: validating user input and loops - by Austin11 - Nov-02-2017, 08:11 PM
RE: validating user input and loops - by nilamo - Nov-02-2017, 08:34 PM
RE: validating user input and loops - by Austin11 - Nov-03-2017, 12:24 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Simulate an answer based on user input [Beginner needs guidance] Bombardini 1 1,423 Nov-12-2022, 03:47 AM
Last Post: deanhystad
  Print user input into triangle djtjhokie 1 2,528 Nov-07-2020, 07:01 PM
Last Post: buran
  Changing Directory based on user input paulmerton4pope 13 8,510 Aug-14-2020, 11:48 AM
Last Post: GOTO10
  how to add the user input from file into list wilson20 8 4,524 May-03-2020, 10:52 PM
Last Post: Larz60+
  Writing a function that changes its answer based on user input SirRavenclaw 2 2,980 Dec-21-2019, 09:46 PM
Last Post: Clunk_Head
  Print the longest str from user input edwdas 5 4,382 Nov-04-2019, 02:02 PM
Last Post: perfringo
  how to add user input to a dictionary to a graph KINGLEBRON 3 3,202 Jul-31-2019, 09:09 PM
Last Post: SheeppOSU
  New to Python - tiny coding assistance on user input function and assign to variable Mountain_Duck 1 2,625 Mar-23-2019, 06:54 PM
Last Post: Yoriz
  Extracting list element with user input valve 1 2,671 Mar-11-2019, 07:37 PM
Last Post: Yoriz
  turtle polygon as specified by user input johneven 7 11,066 Mar-02-2019, 10:11 PM
Last Post: johneven

Forum Jump:

User Panel Messages

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