-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforLoops.py
More file actions
63 lines (47 loc) · 1.07 KB
/
Copy pathforLoops.py
File metadata and controls
63 lines (47 loc) · 1.07 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
# For-Loop: Iterate through a dictionary
channels = {
'MTV': 35,
'CNN': 28,
'FOX': 11,
'NBC': 4,
'CBS': 12
}
for c in channels:
print('{} is on channel {}'.format(c, channels[c]))
print()
# For-Loop: Iterate through strings
my_str = ''
for character in "Take me to the moon.":
my_str += character + '_'
print(my_str)
print()
# For-Loop: Iterate through a list, then calculate average
daily_revenues = [
1890.75 # Sunday
2356.23, # Monday
1800.12, # Tuesday
1792.50, # Wednesday
2058.10, # Thursday
1988.00, # Friday
2002.99, # Saturday
]
total = 0
for day in daily_revenues:
total += day
average = total / len(daily_revenues)
print('Weekly revenue: ${:.2f}'.format(total))
print('Daily average revenue: ${:.2f}'.format(average))
print()
# For-Loop: Iterate through a list in reverse
names = [
'Biffle',
'Bowyer',
'Busch',
'Gordon',
'Patrick'
]
for name in names:
print(name, '|', end=' ')
print('\nPrinting in reverse:')
for name in reversed(names):
print(name, '|', end=' ')