Game Development Reference
In-Depth Information
Truth Tables
If you ever forget how the boolean operators work, you can look at these charts, which
are called truth tables :
Table 6-1: The and operator's truth table.
A
and
B
is
Entire statement
True
and
True
is
True
True
and
False
is
False
False
and
True
is
False
False
and
False
is
False
Table 6-2: The or operator's truth table.
A
or
B
is
Entire statement
True
or
True
is
True
True
or
False
is
True
False
or
True
is
True
False
or
False
is
False
Table 6-3: The not operator's truth table.
not A
is
Entire statement
not True
is
False
not False
is
True
Getting the Player's Input
14. print('Which cave will you go into? (1 or 2)')
15. cave = input()
Here, the player is asked to enter which cave they chose to enter by typing in 1 or 2 and
hitting Enter. Whatever string the player typed will be stored in cave . After this code is
executed, we jump back to the top of the while statement and recheck the condition.
Remember that the line was:
13. while cave != '1' and cave != '2':
If this condition evaluates to True , we will enter the while-block again and ask the
player for a cave number to enter. But if the player typed in 1 or 2, then the cave value
will either be '1' or '2' . This causes the condition to evaluate to False , and the
Search WWH ::




Custom Search