python - 如何在函数中正确使用while循环?
问题描述
我正在开发一个程序,如果用户收到,我需要使用 while 循环重新打开输入框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()
我尝试while
在 if 语句之外使用不同的变体,但它不起作用。我想可能会做类似的事情:while user_input <= True or user_input <= False
就是这样。提前感谢所有帮助!
解决方案
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!')
类似的东西
推荐阅读
- python - 比较两个不相等的元组并找出哪个更大或更小
- python - 在 .exe 程序中打开 .txt 文件
- javascript - 如何在javascript中将变量添加到url并使用@PathVariable
- python - Altair:不能刻面分层地块
- ios - 在使用 TableView 的聊天样式窗口中打开键盘时移动 UITextField
- display - 三星 Galaxy S7 上的地图标记
- ios - AVAudioEngine 插入/拔出耳机后没有声音
- python - Python中具有正值和负值的堆积面积图
- c - VS 代码片段未显示在 ctrl+space 上(但用户定义显示)
- android - 访问两张双 SIM 卡