-1

How can I let the last variable only accept number from 1 to 31 in a compact way?

stat = "none"
while stat != "Start" :
    stat = input("Type\"Start\"to start generating: ")
    if stat != "Start" :
        print('Not started')
print(' ' ' Program started.Awnser the questions to generate a password ' ' ')
name = input("Enter your name: ")
name_last = input("Enter your last name: ",)
birth_year = input('Enter your birth year: ',int)
birth_day = input('Enter your birth day: ',int)
Andrey Belykh
  • 2,578
  • 4
  • 32
  • 46
  • 1
    Does this answer your question? [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) – Georgy Apr 21 '20 at 20:30

1 Answers1

0

I don't know what programming language you are using but using python:

After you get the input,

birth_day = input('Enter your birth day (1-31) ')

you can check if it is valid and make them enter it again if it isn't:

while(int(birth_day)<1 or int(birth_day)>31):
   print('Invalid value!')
   birth_day = input('Enter your birth day (1-31) ')

Next time you ask a question, please specify the programming language and add it to the tags.

SpencerLS
  • 361
  • 5
  • 16