-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay 13 python.py
More file actions
150 lines (133 loc) · 3.8 KB
/
Copy pathDay 13 python.py
File metadata and controls
150 lines (133 loc) · 3.8 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# data
data = [
{'name': 'John',
'surname': 'Smith',
'follower_count': 100,
'description': 'Python developer',
'country': 'USA'
},
{'name': 'Jane',
'surname': 'Doe',
'follower_count': 200,
'description': 'Java developer',
'country': 'Canada'
},
{'name': 'Bob',
'surname': 'Johnson',
'follower_count': 300,
'description': 'C# developer',
'country': 'UK'
},
{'name': 'Alice',
'surname': 'White',
'follower_count': 400,
'description': 'PHP developer',
'country': 'France'
},
{'name': 'David',
'surname': 'Brown',
'follower_count': 500,
'description': 'C++ developer',
'country': 'Germany'
},
{'name': 'Emily',
'surname': 'Green',
'follower_count': 600,
'description': 'Ruby developer',
'country': 'Italy'
},
{'name': 'Frank',
'surname': 'Purple',
'follower_count': 700,
'description': 'Scala developer',
'country': 'Spain'
},
{'name': 'Gary',
'surname': 'Yellow',
'follower_count': 800,
'description': 'Javascript developer',
'country': 'Austria'
},
{'name': 'Harry',
'surname': 'Pink',
'follower_count': 900,
'description': 'C# developer',
'country': 'India'
},
{'name': 'Isabella',
'surname': 'Orange',
'follower_count': 1000,
'description': 'Java developer',
'country': 'Germany'
},
{'name': 'Jacob',
'surname': 'Black',
'follower_count': 1100,
'description': 'Python developer',
'country': 'USA'
},
{'name': 'Karen',
'surname': 'White',
'follower_count': 1200,
'description': 'Java developer',
'country': 'Canada'
},
{'name': 'Lisa',
'surname': 'Pink',
'follower_count': 1300,
'description': 'C# developer',
'country': 'UK'
},
{'name': 'Mia',
'surname': 'Orange',
'follower_count': 1400,
'description': 'PHP developer',
'country': 'France'
},
{'name': 'Nancy',
'surname': 'Green',
'follower_count': 1500,
'description': 'C++ developer',
'country': 'Germany'
}
]
# create higher or lower game with previous dataset
import random
# import clear in order to clear page when answer is found
import time
def get_random_person(data):
"""
Returns a randomly selected person from the data.
"""
person = random.choice(data)
return person
def check_answer(guess, a_followers, b_followers):
if a_followers > b_followers:
return guess == "a"
else:
return guess == "b"
def game():
score = 0
game_should_continue = True
person_a = get_random_person(data)
person_b = get_random_person(data)
while game_should_continue:
person_a=person_b
person_b = get_random_person(data)
while person_a == person_b:
person_b = get_random_person(data)
if person_a == person_b:
person_b = get_random_person(data)
print(f"Compare A: {person_a['name']}, {person_a['description']}, from {person_a['country']}")
print(f"Compare B: {person_b['name']}, {person_b['description']}, from {person_b['country']}")
guess = input("Who has more followers? Type 'A' or 'B': ").lower()
a_follower_count = person_a['follower_count']
b_follower_count = person_b['follower_count']
is_correct = check_answer(guess, a_follower_count, b_follower_count)
if is_correct:
score += 1
print(f"You're right! Current score: {score}.")
else:
game_should_continue = False
print(f"Sorry, that's wrong. Final score: {score}")
game()