forked from garrettgsb/python-essentials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03-lists-and-loops.py
More file actions
66 lines (53 loc) · 1.34 KB
/
03-lists-and-loops.py
File metadata and controls
66 lines (53 loc) · 1.34 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
greeting = "Hello" # Try to notice where we override this later.
# Hey this is the first time we care about indentation!
objects = [
"World",
"Gang",
"Y'all",
"Everybody",
"Everyone",
# You can put a comment here, so that's neat.
"😁",
"Sam",
"Anita",
"Ralph",
"Mario",
]
# Bad plan. What if our list has 28,000 items in it?
print(greeting + " " + objects[0]) # 0 is the first in every list
print(greeting + " " + objects[1])
print(greeting + " " + objects[2])
print(greeting + " " + objects[3])
print(greeting + " " + objects[4])
print(greeting + " " + objects[5])
print(greeting + " " + objects[6])
print(greeting + " " + objects[7])
# Ugh. This is laborious.
print("\nDon't do that ☝️")
print("--------")
print("Do this 👇\n")
for _object in objects:
print(greeting + " " + _object)
# Nested loops
print("\n--------\n")
greetings = [
"Hello",
"Hey there,",
"Howdy",
"你好",
"👋"
]
for greeting in greetings:
for _object in objects:
print(greeting + " " + _object)
print("\n--------\n")
tails = [
"How's it going?",
"I didn't see you there.",
"You wanna get a sandwich or something?",
"🎉🎮👾🐳👌"
]
for greeting in greetings:
for _object in objects:
for tail in tails:
print(greeting + " " + _object + "! " + tail)