input() reads a user's response from standard input, making a command-line program interactive. Use it when the program must pause, ask a question, and continue with the entered text. section 6.3.3
A practical input flow can:
- Prompt for a menu choice. section 6.3.3
- Repeat the prompt while the response is invalid. section 6.3.3
- Collect required and optional fields through a reusable helper. section 6.3.3
Validated menu input
choice = input('Choose an option: ') while not option_choice_is_valid(choice, options): print('Invalid choice') choice = input('Choose an option: ') return options[choice.upper()] section 6.3.3
Listing 6.13. Getting a user’s choice of menu option
def option_choice_is_valid(choice, options): #1
return choice in options or choice.upper() in options
def get_option_choice(options):
choice = input('Choose an option: ') #2
while not option_choice_is_valid(choice, options): #3
print('Invalid choice')
choice = input('Choose an option: ')
return options[choice.upper()] #4
if __name__ == '__main__':
...
chosen_option = get_option_choice(options)
chosen_option.choose()
Shows input() used with validation, case normalization, and menu selection. section 6.3.3






