Python "Higher or Lower" Game - Who Has More Followers?

Arunmathavan KArunmathavan K
3 min read

For this game, I created a dataset with dictionary form. Each entry in the dataset is a dictionary that contains key-value pairs representing different attributes of a person or entity (such as their name, category, followers, and country). Here is how my dataset looks in dictionary format. It stores and named "datas.py"

data=[
    {
        'name':'Cristiano Ronaldo',
        'category':'Footballer',
        'followers':636,
        'country':'Portugal'
    },
    {
        'name':'Sachin Tendulkar',
        'category':'Cricketer',
        'followers':50,
        'country':'India'
    },
    {
        'name':'Lional Messi',
        'category':'Footballer',
        'followers':504,
        'country':'Argentina'
    },
    {
        'name':'Real Madrid CF',
        'category':'Football club',
        'followers':166,
        'country':'Spain'
    },
    {
        'name':'Virat Kohli',
        'category':'Cricketer',
        'followers':270,
        'country':'India'
    },
    {
        'name':'FC Barcelona',
        'category':'Football club',
        'followers':129,
        'country':'Spain'
    },
]

The logo refers to ASCII art representations that bring a playful visual element to the console-based game. ASCII art is a technique for creating images or designs using characters from the ASCII character set, such as letters, numbers, and symbols. This art is stored in a file named "design.py".

high=r"""
 _  _  __  ___  _  _  ____  ____ 
/ )( \(  )/ __)/ )( \(  __)(  _ \
) __ ( )(( (_ \) __ ( ) _)  )   /
\_)(_/(__)\___/\_)(_/(____)(__\_)
      __     __   _  _  ____  ____    
     (  )   /  \ / )( \(  __)(  _ \   
     / (_/\(  O )\ /\ / ) _)  )   /   
     \____/ \__/ (_/\_)(____)(__\_)   
"""
vs=r"""
,--.  ,--.,---.  
 \  `'  /(  .-'  
  \    / .-'  `) 
   `--'  `----'  
"""

The main part of the game involves allowing the player to guess which of the two celebrities or entities has a higher number of followers.

First, import the design and data files. Then, create a function called "display_details". This function will retrieve all the information from the data file.

import random
import design
import datas
def display_details(ac):
    name=ac['name']
    category=ac['category']
    country=ac['country']
    return f" {name}, a {category} from {country}."

In the "check" function, the parameters are guess, follow1*, and **follow2**. This function determines if the number of followers for compare 1 is less than or greater than the number of followers for compare 2.*

score=0
print(design.high)
print(f"You are right. Your score is {score}")
def check(guess,follow1,follow2):
    if follow1<follow2:
        if guess==1:
            return False
        else:
            return True
            # return follow2
    else:
        if guess==1:
            return True
            # return follow1
        else:
            return False

In this section, the user aims to guess which entity has the most followers. If the guess is correct, the global variable "score" is incremented by 1. If the guess is incorrect, the current score is returned, and the game ends.

gameover=True
while True:
    # ac1 = random.choice(datas.data)
    ac2 = random.choice(datas.data)
    while ac1==ac2:
        ac2 = random.choice(datas.data)
    print(f'compare 1: {display_details(ac1)}')
    print(design.vs)
    print(f"compare 2: {display_details(ac2)}")
    guess=int(input("Who has more Followers? Type 1 or Type 2: "))
    follow1=ac1['followers']
    follow2=ac2['followers']
    correct=check(guess,follow1,follow2)
    if correct==True:
        score+=1
        print(f"You are right. Your score is {score}.")
        if follow2>follow1:
            ac1=ac2
    else:
        print(f"You are wrong. Your final score is {score}.")
        gameover=False
        break
print("Game Over")
0
Subscribe to my newsletter

Read articles from Arunmathavan K directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Arunmathavan K
Arunmathavan K