from game_data import data
import random

def pick_contender(exception = {}) :
    contender = exception

    while contender == exception:
        contender = random.choice(data)

    return(contender)

def get_answer():
    answer = input("Who has more followers? Type 'A' or 'B':")
    if answer.lower() not in ["a", "b"]:
        print("Invalid option - try again")
        return(get_answer())
    return(answer.lower())

def run_round(current_contender, score):
    if current_contender == {}:
        current_contender = pick_contender()

    new_contender = pick_contender(current_contender)

    print(f"Compare A: {current_contender['name']}, a {current_contender['description']}, from {current_contender['country']}")
    print(f"Against B: {new_contender['name']}, a {new_contender['description']}, from {new_contender['country']}")

    answer = get_answer()

    if current_contender['follower_count'] > new_contender['follower_count']:
        winner = "a"
    else:
        winner = "b"

    if answer == winner:
        score +=1
        print("Correct!")
        print(f"Current score: {score}")
        run_round(new_contender, score)
    else:
        print("Wrong!")
        print(f"Game over! Your final score: {score}")

run_round({}, 0)
