2024-07-30: Higher Lower game

# import art and game data
from art import logo, vs
from game_data import data
import random
from replit import clear

# randomly select a list from database

list_B = (random.choice(data))


# function compare followers
def compare(list_A_follower, list_B_follower, guess):
    if list_A['follower_count'] > list_B['follower_count']:
        return guess == "a"
    else:
        return guess == "b"


# initialize score and result value
score = 0
result = True

# use while loop to repeat the game
while result:
    clear()
    print(logo)

    # avoid print score in first round
    if score != 0:
        print(f"You are right. Current score: {score}.")

    # swap list_B to list_A
    list_A = list_B
    list_B = (random.choice(data))

    #check if two lists are duplicate
    if list_A == list_B:
        list_B = (random.choice(data))

    print(
        f"Compare A: {list_A['name']}, {list_A['description']}, from {list_A['country']}"
    )
    print(vs)
    print(
        f"Against B: {list_B['name']}, {list_B['description']}, from {list_B['country']}"
    )
    print(
        "--------------------------------------------------------------------------------"
    ) 
    guess = input("Who has more followers? Type 'A' or 'B'.\n").lower()

    # use compare function to get game result
    result = compare(list_A['follower_count'], list_B['follower_count'], guess)

    if result:
        score += 1

# out of while loop
clear()
print(logo)
print(f"Sorry, that's wrong. Final score: {score}")