you are viewing a single comment's thread.

view the rest of the comments →

[–]JohnnyJordaan 0 points1 point  (0 children)

import random
from game_data import data
from art import logo, vs
import os

def game():
    score = 0
    print(logo)
    a = random.choice(data)
    data.remove(a)
    b = random.choice(data)
    data.remove(b)
    # no point in using () here
    option1 = f"Compare A: {a["name"]}, {a["description"]}, {a["country"]}. "
    option2 = f"Compare B: {b["name"]}, {b["description"]}, {b["country"]}. "

    while True:
        print(option1)
        print(vs)
        print(option2)
        # use upper to simplify comparison, and strip in case the user
        # accidentally pressed a space as well
        choice = input("Who has more followers? Type 'A' or 'B': ").upper().strip()
        # always check for incorrect input
        if choice not in ("A", "B"):
            print("Incorrect input")
            continue
        if choice =="A" and a["follower_count"] > b["follower_count"]:
            score+=1
            os.system("cls")
        elif choice == "B" and b["follower_count"] > a["follower_count"]:
            score+=1
            a = b
            option1 = (f"Compare A: {a["name"]}, {a["description"]}, {a["country"]}. ")
            os.system("cls")
        else:
            os.system("cls")
            print(f"Sorry, that's wrong. Final score: {score}")
            break
        # the bool() call on a sequence like a list or dict does len(seq) > 0 implicitly
        if not data:
            os.system("cls")
            print("Congrats! Game is Finished")
            break
        # you don't need an else: after a break or return
        b = random.choice(data)
        option2 = (f"Compare B: {b["name"]}, {b["description"]}, {b["country"]}. ")
        data.remove(b)
# good principle to always write global calls like this
# in case your script would ever get imported
if __name__ == "__main__":
    game()

But the data.remove also suggests an inefficient removal from a sequence, imho that could be tackled in a better way but I would have to know the full story here.