Bob
Bob

Reputation: 11

While Loop - constant variables NOT working with user input boundaries

So the VALUE_MAX variable is = to 25, and VALUE_MIN is = to 1. When I type 26, or 0, it is supposed to pop up and give the user another chance to input a value within 1-25 range (in easygui window). I have written this code, but I am not sure what is wrong with it. I would very much appreciate any help to resolve this issue. Here is my FULL code for this program: https://github.com/UnknownBob123/Card-Catalogue

Here is my original code for this part:

def validate_value(value, item): 

    """Input validation: Checks that the user has input a valid value. 
    """ 

    # If the user presses the Cancel button, function is called to  
    # confirm that the user wants to exit. 
    if value == None: 
        value = query_cancel() 

    # If the user presses the OK button without entering a value, 
    # the no_value() function is called to display an error message 
    # and get input. 
    while value == "": 
      value = no_value(item) 

    # The while loop checks that input is valid (from VALUE_MIN to  
    # VALUE_MAX), and if not an error message is displayed, and the  
    # user is prompted to re-enter the value. 
    while float(value) < VALUE_MIN or float(value) > VALUE_MAX: 
      msg = "Please enter a valid value for " + item + " (from " + str(VALUE_MIN) + " to " + str(VALUE_MAX) + ")." 
      title = "ERROR" 
      value = easygui.enterbox(msg, title) 

        # If the user pressed OK without entering a value, the function 
        # is called to display and error message and get input. 

      while value == "": 
        value = no_value(item) 

        # If the user presses the Cancel button, function is called to  
        # confirm that the user wants to exit. 
      if value == None: 
        value = query_cancel()
        return (value) 

Upvotes: 1

Views: 190

Answers (0)

Related Questions