-
Notifications
You must be signed in to change notification settings - Fork 1
/
unit4_ex4.2.1.py
55 lines (44 loc) · 1.06 KB
/
unit4_ex4.2.1.py
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
44
45
46
47
48
49
50
51
52
53
54
55
# exercise 4.2.1 from unit 4
'''
Here are a couple of code snippets. For each couple, complete whether the couple's output
will be the same or different.
(Write the word "same" or "different" in the box, without quotation marks)
Guidelines
Assume that the variable rain_mm is of type integer (int).
Assume that the variable in both code snippets has the same value.
Recommendation: Test each pair of code sections using different variable values.
Recommendation: use a truth table.
'''
# first code:
if rain_mm < 6 and rain_mm > 4:
print("illegal")
else:
print("legal")
# second code:
if not (rain_mm == 5):
print("legal")
else:
print("illegal")
# Answer: same
# first code:
if rain_mm > 20 and rain_mm < 40:
print("legal")
else:
print("illegal")
# second code:
if not (rain_mm < 20 and rain_mm > 40):
print("legal")
else:
print("illegal")
# Answer: different
# first code:
if rain_mm > 6 and rain_mm < 4:
print("illegal")
else:
print("legal")
# second code:
if not (False):
print("legal")
else:
print("illegal")
# Answer: same