Requirements for the Higher Lower Game
Higher Lower Game
# what i wrote
from random import choice
from art import logo, vs
from game_data import data
print(logo)
def game():
A = choice(data)
B = choice(data)
A_name = A["name"]
A_description = A["description"]
A_country = A["country"]
B_name = B["name"]
B_description = B["description"]
B_country = B["country"]
print(f"Compare A: {A_name}, {A_description}, {A_country}.")
print(vs)
print(f"Against B: {B_name}, {B_description}, {B_country}.")
a_follower = A["follower_count"]
b_follower = B["follower_count"]
if a_follower > b_follower:
answer = "a"
else:
answer = "b"
print(answer)
user_choice = (input("Who has more followers? Type 'A' or 'B': ")).lower()
score = 0
while user_choice != answer:
if user_choice == answer:
score += 1
print(f"You're right! Current score: {score}")
else:
print(f"Sorry, that's wrong. Final score: {score}")
game()
game()
뭔가 잘못됐는데....
너무 오랫동안 쥐고 있었어....
TODO
# Solution
from game_data import data
import random
from art import logo, vs
from replit import clear
def get_random_account():
"""Get data from random account"""
return random.choice(data)
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_account()
account_b = get_random_account()
while game_should_continue:
account_a = account_b
account_b = get_random_account()
while account_a == account_b:
account_b = get_random_account()
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)
clear()
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}")
game()
완벽하진 못했지만 n시간동안 고민했다는 것에 의의를 두고,, 이만..