

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 6
click for more info
Not enough gems
Cost: 6 gems
1: Comparison Operators
incomplete
2: Comparison Operator Evaluations
incomplete
3: Comparison Practice
incomplete
4: If Statements
incomplete
5: If Practice
incomplete
6: If-Else
incomplete
7: If-Else Practice
incomplete
8: If-Else Practice
incomplete
9: Boolean Logic
incomplete
10: Boolean Quiz
incomplete
11: Should Serve Drinks
incomplete
12: Mount Rental
incomplete
13: Combat Advantage
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
So you think you understand conditionals? Get ready to invert your logic!
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. This means 5 and 10 would return True.True.Why go through the hassle of inverting the logic? These early returns are the whole solution. 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.