Question: Complete the get_user_input() function that takes no parameters. It prompts the user to enter a value between 1 and 6 inclusive. While the user enters
Complete the get_user_input() function that takes no parameters. It prompts the user to enter a value between 1 and 6 inclusive. While the user enters an invalid integer value, the function informs them that their selection is invalid and prompts them again. Once the user enters an integer value between 1 and 6 inclusive, the get_user_input() function returns this value. Note that you can assume that the user will always enter an integer value when prompted. Some examples of the function being used are shown below.
For example:
| Test | Input | Result |
|---|---|---|
user_selection = get_user_input() print("You have selected:", user_selection) | 0 7 5 | Enter your choice (between 1 and 6 inclusive): 0 Invalid menu option. Please try again: 7 Invalid menu option. Please try again: 5 You have selected: 5 |
user_selection = get_user_input() print("You have selected:", user_selection) | -1 99 24 -3 2 | Enter your choice (between 1 and 6 inclusive): -1 Invalid menu option. Please try again: 99 Invalid menu option. Please try again: 24 Invalid menu option. Please try again: -3 Invalid menu option. Please try again: 2 You have selected: 2 |
user_selection = get_user_input() print("You have selected:", user_selection) | 6 | Enter your choice (between 1 and 6 inclusive): 6 You have selected: 6 |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
