100일 간의 코드: 2022년을 위한 완전한 Python Pro 부트캠프 - 14일차(고급 게임)
개별 작업은 다음과 같으나 이에 국한되지는 않습니다.
좀 더 예뻐보이도록 조금 더 추가했어요 ㅋㅋㅋㅋㅋ
1일 시작부터 모든 코딩은 https://replit.com의 리플릿으로 이루어졌습니다. 15일차부터는 코딩 환경에 Pycharm을 사용하기 시작합니다.
상위 하위 게임 프로젝트
- import emojis from https://unicode.org/emoji/charts/emoji-list.html
import random
from replit import clear
from art import logo, hl, vs
import emoji
print(logo)
- Welcome data, what is your name? greet the player use an emoji
print("Welcome to the HigherLower Game. This game is based off the original which is hosted at http://www.higherlowergame.com/. ")
user_name = input("What is your name? ")
computer_response = print(emoji.emojize(f"Welcome {user_name.capitalize()}, 'Lets Play' :grinning_face: "))
def get_random_account():
"""Get random account details from game_data dictionary"""
from game_data import data
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(hl)
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_a = get_random_account()
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(hl)
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()
Reference
이 문제에 관하여(100일 간의 코드: 2022년을 위한 완전한 Python Pro 부트캠프 - 14일차(고급 게임)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://dev.to/mike_kameta_aed62d48c2d0f/100-days-of-code-the-complete-python-pro-bootcamp-for-2022-day-14-3fk3
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
- import emojis from https://unicode.org/emoji/charts/emoji-list.html
import random
from replit import clear
from art import logo, hl, vs
import emoji
print(logo)
- Welcome data, what is your name? greet the player use an emoji
print("Welcome to the HigherLower Game. This game is based off the original which is hosted at http://www.higherlowergame.com/. ")
user_name = input("What is your name? ")
computer_response = print(emoji.emojize(f"Welcome {user_name.capitalize()}, 'Lets Play' :grinning_face: "))
def get_random_account():
"""Get random account details from game_data dictionary"""
from game_data import data
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(hl)
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_a = get_random_account()
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(hl)
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()
Reference
이 문제에 관하여(100일 간의 코드: 2022년을 위한 완전한 Python Pro 부트캠프 - 14일차(고급 게임)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/mike_kameta_aed62d48c2d0f/100-days-of-code-the-complete-python-pro-bootcamp-for-2022-day-14-3fk3텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)