learning from 100 Days of Code: The Complete Python Pro Bootcamp for 2022
# higher-lower game
from random import choice
from replit import clear
import art
from game_data import data
def check_answer(guess,player_A,player_B):
if a_follower_count > b_follower_count:
return guess == 'a' ##return True or False
else:
return guess == 'b' ##return True or False
def format_data(player):
player_name = player['name']
player_description = player['description']
player_country = player['country']
return f"{player_name}, a {player_description}, from {player_country}"
game_over = False
score = 0
player_A = choice(data)
player_B = choice(data)
while not game_over:
clear()
print(art.logo)
player_A = player_B
player_B = choice(data)
while player_A == player_B:
player_B = choice(data)
# 第一回合得分之後,就會顯示
if score > 0:
print(f"You're right! Current score: {score}.")
print(f"Compare A: {format_data(player_A)}.")
print(art.vs)
print(f"Against B: {format_data(player_B)}.")
print(player_A['follower_count'])
print(player_B['follower_count'])
guess = input("Who has more followers? Type 'A' or 'B': ").lower()
a_follower_count = player_A['follower_count']
b_follower_count = player_B['follower_count']
is_correct = check_answer(guess, a_follower_count,b_follower_count)
if is_correct :
score +=1
else:
break
clear()
print(art.logo)
print(f"Sorry, that's wrong. Final score: {score}")