-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path5_booleans.py
More file actions
46 lines (34 loc) · 1.3 KB
/
5_booleans.py
File metadata and controls
46 lines (34 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# ** Boolean Comparisons **
print("Examples of boolean comparisons")
# Python also supports logical operations on booleans. Logical operations take
# booleans as their operands and produce boolean outputs. Keep reading to learn
# what boolean operations Python supports.
# And
# The statement `a and b` evaluates to True only if both a and b are `True`.
# Use the keyword `and` to perform this operation
print("True and True is", True and True)
print("False and False is", False and False)
print("True and False is", True and False)
# Or
# The statement `a or b` evaluates to True if a is `True` or b is `True`.
# use the keyword `or` to perform this operation
print("True or True is", True or True)
print("False or False is", False or False)
print("True or False is", True or False)
# Not
# The keyword `not` flips a boolean from True to False or vice versa
print("not True is", not True)
print("not False is", not False)
print("\n")
# ** Exercises **
print("Output of exercises")
# 1. Modify line 38 below so that it only prints `True` if all of a, b, and c
# are True. Modify the three values to test your code.
a = True
b = True
c = True
print(False)
# 2. Modify line 42 so that it only prints `True` if x is less than 10 or
# greater than 100. Change the value of x to test your code.
x = 0
print(False)