The World of Two
Hoppy reaches a strange clearing. Everything here is black or white, light or dark. There are no shades of gray.
This is the land of Booleans. Here, everything is either True or False.
The Boolean Spell
is_light_on = True is_door_open = False print(is_light_on) print(is_door_open)
Notice that True and False start with capital letters. They are special keywords in Python, not just words in quotes.
Your Mission
1
Define Reality
Create a variable named hoppy_is_happy and set it to True.
2
Check the Path
Create a variable named path_is_blocked and set it to False.
3
Reveal the Truth
Print both variables to see their values.
Capitalization
Python is case-sensitive! true (lowercase) will cause an error. It must be True.
Suggested SolutionClick to expandClick to collapse
Here is how you define the truth:
hoppy_is_happy = True path_is_blocked = False print(hoppy_is_happy) print(path_is_blocked)
Advanced TipsWant more? Click to expandClick to collapse
You can turn other things into Booleans using the bool() function.
print(bool(1)) # True
print(bool(0)) # False
print(bool("Hi")) # True
print(bool("")) # FalseGenerally, "something" is True, and "nothing" (like 0 or empty text) is False.
pymain.py
Loading...
Terminal
Terminal
Ready to run...