b_followers : return guess == "A" else : return guess == "B" def game(): print(logo) score = 0 game_should_continue = True data_a = get_random_data() data_b = get_random_data() # 후보 변경 while game_should_continue : data_a = data_b data_b = get_random_data() # 후보 중복시 교체 while data_a == data_b : data_b = get_random_data() print(f"후보 A : {format_data(data_a)}.") print(vs) print(f"후보 B : {format_data(data_b)}.") "> b_followers : return guess == "A" else : return guess == "B" def game(): print(logo) score = 0 game_should_continue = True data_a = get_random_data() data_b = get_random_data() # 후보 변경 while game_should_continue : data_a = data_b data_b = get_random_data() # 후보 중복시 교체 while data_a == data_b : data_b = get_random_data() print(f"후보 A : {format_data(data_a)}.") print(vs) print(f"후보 B : {format_data(data_b)}.") "> b_followers : return guess == "A" else : return guess == "B" def game(): print(logo) score = 0 game_should_continue = True data_a = get_random_data() data_b = get_random_data() # 후보 변경 while game_should_continue : data_a = data_b data_b = get_random_data() # 후보 중복시 교체 while data_a == data_b : data_b = get_random_data() print(f"후보 A : {format_data(data_a)}.") print(vs) print(f"후보 B : {format_data(data_b)}.") ">
from game_data import data
from art import logo, vs
import random
def get_random_data() :
"""데이터를 랜덤으로 추출해주는 함수."""
return random.choice(data)
def format_data(data) :
"""데이터 형식으로 출력하는 함수"""
name = data["name"]
description = data["description"]
country = data["country"]
return f"{name}, {description}. {country}"
def check_answer(guess, a_followers, b_followers) :
"""팔로워 수 비교하는 함수"""
if a_followers > b_followers :
return guess == "A"
else :
return guess == "B"
def game():
print(logo)
score = 0
game_should_continue = True
data_a = get_random_data()
data_b = get_random_data()
# 후보 변경
while game_should_continue :
data_a = data_b
data_b = get_random_data()
# 후보 중복시 교체
while data_a == data_b :
data_b = get_random_data()
print(f"후보 A : {format_data(data_a)}.")
print(vs)
print(f"후보 B : {format_data(data_b)}.")
guess = input("팔로워가 많은 후보를 골라주세요 A or B \\n > ")
a_follower_count = data_a["follower_count"]
b_follower_count = data_b["follower_count"]
is_correct = check_answer(guess, a_follower_count, b_follower_count)
print(logo)
if is_correct :
score += 1
print(f"정답입니다. 현재 점수 : {score}")
else :
game_should_continue = False
print(f"틀렸습니다. 최종 점수 : {score}")
game()