Answers for "reject invalid input using a loop in python"

1

reject invalid input using a loop in python

take input
while incorrect input:
    take input
    
#Eg. Taking the month input for the first quarter of the year.
months = ['january', 'february', 'march']
month = input('Select the month').lower()
while month not in months:
  month = input('Oops! Incorrect input. Select month again').lower()
Posted by: Guest on September-01-2021

Python Answers by Framework

Browse Popular Code Answers by Language