【发布时间】:2021-10-19 18:09:57
【问题描述】:
def sleep_in(weekday, vacation):
if weekday == ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'] and vacation == 'Yes':
return True
elif weekday != ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'] or vacation == 'Yes':
return True
else:
return False
print(sleep_in('monday', 'No'))
【问题讨论】:
-
weekday以字符串形式给出,因此weekday != <some list>将始终为 True。你的意思是写weekday not in <some list>? -
注意:您的前两个条件可以替换为一个条件:
if vacation == "Yes" or weekday not in list_of_weekdays
标签: python return boolean-operations