Create a function validate_input that repeatedly prompts the user for input until they enter an input within a set of valid options. Arguments The
Create a function validate_input that repeatedly prompts the user for input until they enter an input within a set of valid options. Arguments The function takes two arguments: prompt: a string to print when asking user for input valid inputs: a list of strings representing all options the user is restricted to Outputs/Returns The function should print prompt when asking the user for input. Upon an invalid input, please display the following message before prompting the user again: "Invalid input, please try again." Once a valid input is provided, the function should return it as a string. Example >>> validate_input("Please select an option (a, b, c): ", ["a", "b", "c"]) Please select an option (a, b, c): 1 Invalid input, please try again. Please select an option (a, b, c): 3 Invalid input, please try again. Please select an option (a, b, c): di Invalid input, please try again. Please select an option (a, b, c): a 1 def validate_input (prompt, valid_inputs): 12345 6 7 8 9 355W NIO 10 11 12 13 14 if 15 16 Repeatedly ask user for input until they enter an input within a set valid of options. :param prompt: The prompt to display to the user, string. :param valid_inputs: The range of values to accept, list :return: The user's input, string. || || || # Implement your solution below raise NotImplementedError == __name__ "__main__": # Enter test code below user_input = validate_input ("Please select an option (a, b, c)
Step by Step Solution
3.47 Rating (160 Votes )
There are 3 Steps involved in it
Step: 1
def validateinputprompt validinputs while True userinput inputprompt if userinput in ...See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started