"""
Approach
1.Breakdown the problem:
break down a large problem into smaller problem
2.Start with the easiest :
look at those problems and make a to-do list.Given the items on the to-do list,
you're going to pick the one that you think is the easiest to begin.
3.Turn the problem into comments:
4.Write code beneath the comments
Run code make sure that it does what you want it to do
Fix code
5.Next Task
"""
from day14_art import logo,vs
from day14_game_data import data
import random
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"]
return f"{name},a {description},from {country}."
def check_answer(guess,a_followers,b_followers):
"""Check followers against user's guess and
return 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':")
a_follower_count = account_a["followers_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()
# Generate a random account from the game data.
# Format account data into printable format.
# Ask user for a guess.
# Check if user is correct.
## Get follower count.
## If Statement
# Feedback.
# Score Keeping.
# Make game repeatable.
# Make B become the next A.
# Add art.
# Clear screen between rounds.
day14_Udemy Python 100days
最新推荐文章于 2024-08-19 13:32:52 发布