如何正确使用while循环功能?

时间:2019-11-29 16:22:10

标签: python while-loop dataset

我正在开发一个程序,如果用户收到Date not found, please try a different date

,则需要使用while循环重新打开输入框。
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()

我曾尝试在if语句之外使用while的其他变体,但无法正常工作。我想象也许会做类似的事情:while user_input <= True or user_input <= False。所有帮助都将不胜感激!

1 个答案:

答案 0 :(得分: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!')

类似的东西