-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
85 lines (66 loc) · 2.76 KB
/
main.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
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
# Importing modules
import random
import os
from os import path
from game_data import database
from art import logo, vs
from time import sleep
def get_random_data():
"""Get data from random account"""
return random.choice(database)
def format_data(account):
"""Format account into printable format: name, description and country"""
name = account["name"]
description = account["description"]
country = account["country"]
# print(f'{name}: {account["follower_count"]}')
return f"{name}, a {description}, from {country}"
def check_answer(guess, a_followers, b_followers):
"""Checks followers against user's guess
and returns True if they got it right.
Or False if they got it wrong."""
if a_followers > b_followers:
return guess == "a"
else:
return guess == "b"
def game():
print(logo)
score = 0
game_should_continue = True
account_a = get_random_data()
account_b = get_random_data()
while game_should_continue:
account_a = account_b
account_b = get_random_data()
while account_a == account_b:
account_b = get_random_data()
print(f"Compare A: {format_data(account_a)}.")
print(vs)
print(f"Against B: {format_data(account_b)}.")
guess = input("Who has more followers? Type 'A' or 'B': ").lower()
a_follower_count = account_a["follower_count"]
b_follower_count = account_b["follower_count"]
is_correct = check_answer(guess, a_follower_count, b_follower_count)
os.system('cls')
print(logo)
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}")
sleep(1)
if input("Do you want to play again? Type 'y' for Yes, 'n' for No: ") == 'y':
os.system('cls')
game()
# call the function to start the game
game()
'''
FAQ: Why does choice B always become choice A in every round, even when A had more followers?
Suppose you just started the game and you are comparing the followers of A - Instagram (364k) to B - Selena Gomez (174k).
Instagram has more followers, so choice A is correct. However, the subsequent comparison should be between
Selena Gomez (the new A) and someone else. The reason is that everything in our list has fewer followers than Instagram.
If we were to keep Instagram as part of the comparison (as choice A) then Instagram would stay there for the rest of the game.
This would be quite boring. By swapping choice B for A each round, we avoid a situation where the number of followers of choice
A keeps going up over the course of the game. Hope that makes sense :-)
'''