

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 7
click for more info
No active XP Potion
Accept a Quest
Login to submit answers
Back
ctrl+,
Next
ctrl+.
In Fantasy Quest, players can go to a town's local pub. Drinking virtual beer refills their stamina!
Complete the function that determines if a bartender should serve drinks to a customer. Only return True if all of these conditions apply. If any of these conditions are False, return False:
This assignment tests your ability to think critically by challenging your expectations up to this point. First, understand the problem before rushing to conclusions about the requirements. Then, convert these positive conditions into negatives. Finally, convert them into code.
False.False.time is before 5 or after 10, return False.True.Why go through the hassle of inverting the logic? The alternative is to write a function that is deeply nested and therefore less readable and more confusing than the solution.
def check_conditions(condition_1, condition_2, condition_3):
if condition_1:
if not condition_2:
if condition_3 > 1:
return True
return False
Where "is_big" is a boolean value, the following statements are identical:
if is_big:
# ...
if is_big == True:
# ...
The first option should be preferred due to length; however, the second is more readable. The == True is redundant.
Focus Editor
Alt+Shift+]
Next Tab
Alt+Shift+[
Become a member to Submit
Become a member to Run
Become a member to view solution