-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflow_control.py
More file actions
116 lines (80 loc) · 2.63 KB
/
Copy pathflow_control.py
File metadata and controls
116 lines (80 loc) · 2.63 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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# flow-control.py
# Feb 05, 2020
# monica@utk.edu
#######################################################################################################
#######################################################################################################
print("\n*** IF STATEMENTS ***\n")
#######################################################################################################
# if statement demo 1: simple if statement
name = "George"
if name == "George":
print("Top of the morning, George!")
# if statement demo 2: if/else
# if/else means that if the first test fails, the else block is executed by default
# try uncommenting the different name examples and see how the outcome changes
name = "Sam"
#name = "Not Sam"
if name == "Sam":
print('Hello Sam!')
else:
print("Where is Sam?")
# if statement demo 3: if/elif/else. Uncomment different names to see different outcomes
#name = "Trudy"
#name = "Judy"
name = "Sam"
if name == "Trudy":
print('Howdy Trudy')
elif name == "Jane":
print("Howdy Jane")
elif name == "Judy":
print("Go away Judy")
else:
print("Nothing to see here.")
# if statement demo 4: if/elif/else but demonstrates that even in the case of multiple true conditions, only the
# first passing conditional block will be executed
num = 123
if num < 10:
print("Less than 10")
elif num < 500:
print("Less than 500")
elif num == 123:
print("We have a match!")
else:
print('Nothing to see here.')
#######################################################################################################
print("\n*** FOR LOOPS ***\n")
#######################################################################################################
# for loop demo 1
grades = [88,100,93,100,80] # a list of grades. Lists are iterable. We'll learn more soon!
print("Here are your grades:")
for grade in grades:
print(grade)
print("Done listing Grades")
print('\n')
# for loop demo 2: nested statements
grades = [88,100,93,100,80]
print("Some Other Grades")
for grade in grades:
print(grade)
if grade == 100:
print("WOW AMAZING!")
print("Done listing Grades")
print('\n')
# for loop demo 3: nested statements with break
grades = [88,100,93,100,80]
print("Last Set of Grades")
for grade in grades:
if grade == 93:
break
print(grade)
print("Done listing Grades")
#######################################################################################################
print("\n*** WHILE LOOPS ***\n")
#######################################################################################################
# while demo 1
count = 1
stop = 5
while stop > count:
print(count)
count += 1
print("All done.")