day14_Udemy Python 100days

"""
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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值