Introduction

In this blog post, we will explore a fun and interactive Python game that challenges you to guess which social media account has more followers. The game makes use of random data from various popular accounts, and you will have to rely on your knowledge or intuition to make the right guess. Let’s dive into the code and see how it works!

Setting Up the Game

To get started, make sure you have Python installed and create a new Python file called “main.py.” Additionally, we need to install the “replit” library and the “art” library. You can install them by running the following commands in your terminal or command prompt:

pip install replit
pip install art

The Game Code

Now, let’s take a look at the code for our game:

# Import required libraries
from game_data import data
import random
from art import logo, vs
from replit import clear

# Function to get data from a random account
def get_random_account():
    return random.choice(data)

# Function to format account data into a printable format
def format_data(account):
    name = account["name"]
    description = account["description"]
    country = account["country"]
    return f"{name}, a {description}, from {country}"

# Function to check user's guess against actual follower count
def check_answer(guess, a_followers, b_followers):
    if a_followers > b_followers:
        return guess == "a"
    else:
        return guess == "b"

# Main game function
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': ").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:
            game_should_continue = False
            print(f"Sorry, that's wrong. Final score: {score}")

# Start the game
game()

How the Game Works

The game starts by importing necessary libraries, and then we define three essential functions: get_random_account(), format_data(account), and check_answer(guess, a_followers, b_followers). These functions handle selecting a random social media account, formatting its data for display, and checking if the user’s guess is correct based on follower counts.

The game() function is the main loop of the game. It initializes the score, selects two random accounts, and prompts the user for their guess. After each round, the game continues if the guess is correct, and it stops if the guess is wrong.

Making the Game Challenging

In the comments of the code, the game developer explains a crucial detail about how the game handles the account comparisons. To keep the game challenging, they make sure that choice B (the new account to guess) becomes the next choice A in the subsequent round. This way, you won’t face the same popular account multiple times, making the game more exciting and fair.

Conclusion

You have now learned how to create a simple but engaging Python game that tests your knowledge of popular social media accounts’ follower counts. The game randomly selects two accounts, and you have to make the right guess to increase your score. Remember, the more you play, the better you’ll get at guessing the followers count of different accounts.

Feel free to modify the code, add more data, or create additional features to make the game even more enjoyable. Happy coding and have fun challenging your friends with this Python game!

GitHub

Github

Medium

Medium subscribe to stay in the loop with our latest articles, tutorials, and projects. Join our community of tech enthusiasts, developers, and learners. Don’t miss out on valuable insights, coding tips, and exciting projects. Click the link to subscribe and embark on a journey of knowledge and growth. ๐Ÿ“š๐Ÿš€ #TechCommunity #Subscribe #StayUpdated #TechEnthusiasts

Feel free to use this link description for your “Subscribe” link to entice readers to join your community and stay updated with your valuable content. Best of luck with your platform and building a thriving community! ๐Ÿ“โœจ

Thank you

Thank you for your continued support, and Iโ€™m excited to have you on this enriching journey!

Sincerely, Founder of orioninsist

Follow the white rabbit

Thank you for your support! Hello friends! I want to express my gratitude for your support. Your interest and encouragement mean a lot to me. To keep our connection strong and to provide you with more valuable content, I encourage you to stay connected with me on my social media platforms.

I am excited to share more content with you through these platforms and I value your engagement and feedback. Thank you once again for your support. Letโ€™s stay connected and keep the conversation going!

Your feedback and engagement mean the world to me. Thank you once again for your unwavering support.

Letโ€™s continue to โ€œfollow the white rabbitโ€ and discover new horizons together!

Best regards,

Murat Kurkoglu

Founder of orioninsist

Google Survey Forms

Stay connected with me ๐Ÿ”— Patreon ๐Ÿ”— Buymeacoffee ๐Ÿ”— Instagram ๐Ÿ”— Twitter ๐Ÿ”— Facebook ๐Ÿ”— Pinterest ๐Ÿ”— Website ๐Ÿ”— GitHub ๐Ÿ”— YouTube ๐Ÿ”— Medium ๐Ÿ”— LinkedIn-Personal ๐Ÿ”— LinkedIn-Company