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'))
Asked
Active
Viewed 63 times
-3

aachebe1029
- 11
- 2
-
`weekday` is given as a string, so `weekday !=
` will always be True. Did you mean to write `weekday not in – Brian61354270 Aug 17 '21 at 21:09`? -
2Note: your first two conditions could be replaced by a single one: `if vacation == "Yes" or weekday not in list_of_weekdays` – Pranav Hosangadi Aug 17 '21 at 21:11
1 Answers
0
Here's some better code:
def sleep_in(weekday, vacation):
if vacation:
return True
if weekday in ['monday', 'tuesday', 'wednesday', 'thursday', 'friday']:
return False
else:
return True
This code works because it first checks vacation
, and returns True
when vacation is true (you can simply do if vacation
for this).
Next, if vacation is false, it evaluates the next if
statement, and sees whether the weekday parameter is within the list of ['monday', 'tuesday', 'wednesday', 'thursday', 'friday']
. If it is, it returns False (no sleep_in). If it is not, it means it's a weekend and sleep_in returns true.
I think that's the goal you were trying to achieve.

Alan duan
- 46
- 5