DEV Community

Cover image for Day 12 of My AI & Data Mastery Journey: From Python to Generative A
Nitin-bhatt46
Nitin-bhatt46

Posted on

Day 12 of My AI & Data Mastery Journey: From Python to Generative A

*PROJECT :- *

** Higher–Lower Game**

Import Required Modules

Import art assets (logo, vs) from art file

Import data list from game_data file

Import random module
Enter fullscreen mode Exit fullscreen mode

Define Function: choices()

Randomly select and return one entry (dictionary) from data list.
Enter fullscreen mode Exit fullscreen mode

Define Function: main()

Set initial score = 0

Set game_active = True

Select first random choice and assign to choice_1
Enter fullscreen mode Exit fullscreen mode

Game Start – Repeat While game_active is True

Display the game logo

Select a new random data entry and assign to choice_2

If score > 0:

    Display “Your Current Score: {score}”

Display choice_1 details (name, description, country)

Display “vs” symbol

Display choice_2 details (name, description, country)

Ask user: "Who has more followers? Type 'A' or 'B'"

    Convert user input to uppercase

Determine actual winner:

    If choice_1 follower_count > choice_2 follower_count → winner = 'A'

    Else if choice_1 follower_count < choice_2 follower_count → winner = 'B'

    Else → winner = 'Draw'
Enter fullscreen mode Exit fullscreen mode

Compare User Guess

If winner == user_choice:

    Update score = score + 1

    Set choice_1 = choice_2 (carry forward next comparison)

Else:

    Display “Sorry, that’s wrong. Final score: {score}”

    Set game_active = False
Enter fullscreen mode Exit fullscreen mode

End of Game

Program stops when user gives an incorrect answer.
Enter fullscreen mode Exit fullscreen mode

Game Logic Notes

Each round, two random people/accounts are compared based on their follower count.

The user tries to guess who has more followers.

If the guess is correct, score increases by 1, and the next round compares the previous winner with a new random choice.

The game continues until the user makes a wrong choice.

Top comments (0)