[udemy] python 부트캠프 _ section 14_ 숫자 업다운 게임 프로젝트

Dreamer ·2022년 8월 21일
0
post-thumbnail

project _ Higher - Loser Game

# import module
# print logo 
# ask the question compare a, compare b 
# who has more followers? 
# compare a, b 
# add score 
# show you're right! current score: 
from art import logo,vs
from game_data import data
import random 
from replit import clear



def format_data(account):
  """takes the account data and returns the printable format."""
  account_name = account["name"]
  account_descr = account["description"]
  account_country = account["country"]
  return f"{account_name}, a {account_descr},from {account_country}"

def check_answer(guess, a_followers, b_followers):
  """Take the user guess and follower counts and returns it they got it right."""
  if a_followers > b_follower_count:
    return guess == "a"  #guess = a인 경우에는 true를 반환함 
  else:
    return guess == "b" #guess = b인 경우에는 true를 반환함 

print(logo)
score = 0
game_should_continue = True
account_b = random.choice(data)


while game_should_continue :
  account_a = account_b
  account_b = random.choice(data)
 
  while account_a == account_b :
    account_b = random.choice(data)
  
  print(f"compare A: {format_data(account_a)}.")
  print(vs)
  print(f"compare A: {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:
    print(f"Sorry, that's wrong! Final score : {score}.")
    game_should_continue = False
profile
To be a changer who can overturn world

0개의 댓글