-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameGuessingGame.py
More file actions
72 lines (60 loc) · 2.06 KB
/
Copy pathGameGuessingGame.py
File metadata and controls
72 lines (60 loc) · 2.06 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
#1) add logo of the game
from art import logo, vs
#import the celebrity data from game_data
from game_data import data
import random
#3) format data into printable form
#we will make this into a method
def format_data(account):
account_name = account["name"]
account_description = account["description"]
account_country = account["country"]
return(f"{account_name}, a {account_description} from {account_country}.")
#method to check if the answer is correct
def check_answer(user_guess, a_followers, b_followers):
if a_followers > b_followers:
"""
if user_guess == "a":
return True
else:
return False"""
#we will shorten this
return user_guess == "a"
else:
return user_guess == "b"
#because account b will become account a after guessing correctly
account_b = random.choice(data)
print(logo)
game_should_continue = True
while game_should_continue:
# 2)assign value to a and b where the celebrities will be posted
account_a = account_b
account_b = random.choice(data)
# keep track of the score
score = 0
if account_a == account_b:
account_b = random.choice(data)
print(f"Compare a: {format_data(account_a)}")
print(vs)
print(f"Compare b: {format_data(account_b)}")
# 4) ask the user for a guess
user_guess = input("Who has more followers? Type 'A' or 'B': ").lower()
#clear the screen
print("\n" * 20)
print(logo)
# 5) check if the user guess is correct
# get follower count of both accounts
a_followers = account_a["follower_count"]
b_followers = account_b["follower_count"]
# check if user is correct
is_correct = check_answer(user_guess, a_followers, b_followers)
# 6)give user feedback on their guess
if is_correct:
score += 1
print(f"Congratulations, you guessed it right! Score : {score}")
else:
print(f"Sorry, that's wrong. Final score is {score}")
game_should_continue = False
#7) keep track of user score
#8) repeat the game
#9) make account B into account A