-
Notifications
You must be signed in to change notification settings - Fork 0
/
decision.py
81 lines (64 loc) · 1.5 KB
/
decision.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Selection is like a fork in the road. It allows your programs to decide which path to take.
#sets the value of age
age = 22
if age >= 18:
# executed only if customer is over-age
print("Regular price")
else:
#executed only if age is less than 18
print("Discount")
if age >= 18:
print("Regular price")
else:
print("Discount")
age = 41
if age >= 18:
print("Regular price")
else:
print("Discount")
age = 30
if age >= 18:
print("Regular price")
else:
print("Discount")
print("Proceed to payment")
age = 32
is_student = True
if age < 18 or is_student:
print("Discount")
else:
print("Regular price")
# lessons learned 🌟 the colon : symbol and the use of indentation are needed to prevent errors
age = 30
if age < 18:
print("Apply Discount")
print("Proceed to payment")
# indentation check
age = 16
if age < 18:
print("Apply Discount")
print("Proceed to Payment")
age = 75
if age < 18:
print("Junior discount")
elif age >= 75:
print("Senior discount")
else:
print("No discount")
print("Proceed to payment")
age = 16
is_student = True
if age < 18:
#execute if age is less than 18
if is_student:
#execute if under 18 and also a student
print("20% discount")
else:
#execute if under 18 and not a student
print("10% discount")
else:
#execute this code customer 18 or over
print("Regular price")
# 🌟 skip the else statement when it is not needed
# 🌟 check for more conditions with the elif statement
# 🌟 nest if-else statements within each other