0

I'm working on a program and I need to use a while loop to re open input box if user receives Date not found, please try a different date

def ask_rain_date():

    date_rain_dict = seattle_weather.groupby('DATE')['RAIN'].apply(list).to_dict()

    rain_date_input = input("Seattle is always rainy! Check to see if it was raining on a date between 1948-2017!\n FORMAT  Y-M-D:  ")

    user_input = (rain_date_input)   

    if user_input in date_rain_dict:
        date_input = (date_rain_dict[user_input])
        if date_input == [True]:
            print('It was raining!')

        elif date_input == [False]:
            print('It was not raining!')


    else:
        print('Date not found, please try a different date.')

ask_rain_date()

I've tried using different variations of while outside of the if statement but it's not working. I imagined maybe doing something like: while user_input <= True or user_input <= False would be it. All the help is appreciated in advance!

RomeP
  • 459
  • 1
  • 4
  • 8
  • What isn't working in which version you have tried? Does it fail to detect incorrect input, or to ask for input again? – MisterMiyagi Nov 29 '19 at 16:29

1 Answers1

0
def ask_rain_date():
    is_date_exists = False
    while not is_date_exists:
        dt = input()
        # searching logic
        if we_find_date_in_dataset:
            is_date_exists = True
            print('Is {}'.format(rain_status))
        else:
            print('Choose another day, please!')

Something like that

Jefferson Houp
  • 858
  • 1
  • 7
  • 17