Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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()
  

  
 
PREVIOUS NEXT
Tagged: #reject #invalid #input #loop #python
ADD COMMENT
Topic
Name
4+9 =