-
Notifications
You must be signed in to change notification settings - Fork 151
/
5_milk_tea_four_random.py
27 lines (21 loc) · 862 Bytes
/
5_milk_tea_four_random.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
import random
ingredients = ['a', 'b', 'c', 'd', 'e']
friend1 = random.choice(ingredients)
friend2 = random.choice(ingredients)
friend3 = random.choice(ingredients)
friend4 = random.choice(ingredients)
friend5 = random.choice(ingredients)
preferences = [friend1, friend2, friend3, friend4, friend5]
count_a = preferences.count('a')
count_b = preferences.count('b')
count_c = preferences.count('c')
count_d = preferences.count('d')
count_e = preferences.count('e')
counts = {'a': count_a, 'b': count_b, 'c': count_c, 'd': count_d, 'e': count_e}
most_popular = max(counts, key=counts.get)
print('Friend 1 prefers', friend1)
print('Friend 2 prefers', friend2)
print('Friend 3 prefers', friend3)
print('Friend 4 prefers', friend4)
print('Friend 5 prefers', friend5)
print('The most popular ingredient is', most_popular, 'with', counts[most_popular], 'votes.')