forked from jennielees/oh-no-broken-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeyboard.py
More file actions
46 lines (32 loc) · 1.14 KB
/
keyboard.py
File metadata and controls
46 lines (32 loc) · 1.14 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
# I had this great script, but my keyboard broke and I can't indent
# any of my code. Can you indent it for me?
import random
cats = ['Grizabella', 'Rum Tum Tugger', 'Demeter', 'Munkustrap',
'Mistoffelees', 'Macavity', 'Rumpleteazer', 'Mungo Jerry',
'Skimbleshanks']
instruments = ['keyboard', 'cello', 'bass', 'flute', 'pipe', 'piano',
'violin', 'oboe', 'triangle']
def get_cat_and_instrument(position):
cat = cats[position]
instrument = instruments[position]
return "{} plays the {}".format(cat, instrument)
# Print out my cat orchestra one by one
total_cats = len(cats)
position = 0
while True:
if position >= total_cats:
break
print get_cat_and_instrument(position)
position += 1
# Could you do the assignment of cats and instruments any other ways?
random.shuffle(cats)
random.shuffle(instruments)
def get_cat_and_instrument(position):
cat = cats[position]
instrument = instruments[position]
return "{} plays the {}".format(cat, instrument)
# Print out my cat orchestra one by one
position = 0
for item in cats:
print get_cat_and_instrument(position)
position += 1