# Import art & game data from art import logo, vs from game_data import data import random # from replit import clear import os # use system clear to clear screen # Linux version clear = lambda: os.system('clear') # Windows version # clear = lambda: os.system('cls') def new_high_low(): """ Generate unique new item(s) to compare """ compare["A"] = compare["C"] compare["B"] = random.choice(data) # Ensure the values are NOT the same! while compare["B"] == compare["A"]: compare["B"] = random.choice(data) def display_compare(): """ Function to display comparisons, collect and return choice """ clear() print(logo) vowels = ["a","e","i","o","u"] new_high_low() if score: print(f"You're right! Current score: {score}.") print(f"Compare A: {compare['A']['name']}, a{'n' if compare['A']['description'][0].lower() in vowels else ''} {compare['A']['description']}, {compare['A']['country']}") print(vs) print(f"Against B: {compare['B']['name']}, a{'n' if compare['B']['description'][0].lower() in vowels else ''} {compare['B']['description']}, {compare['B']['country']}") choice = input("\nWho has more followers? Type 'A' or 'B': ").upper() if choice == "A": return "A","B" return "B","A" def higher_lower(answer): """ Return True/False whether answer correct and, if True, capture answer """ if compare[answer[0]]["follower_count"] > compare[answer[1]]["follower_count"]: compare["C"] = compare[answer[0]] return True return False #Initialise Dictionary to hold values for comparison compare = {} compare["C"] = random.choice(data) # Start game here... play_again = True while play_again: score = 0 end_game = False while not end_game: if higher_lower(display_compare()): score += 1 else: end_game = True clear() print(logo) if input(f"Sorry, that's wrong. Final score: {score}.\nGame over. Play again? Type 'y' or 'n': ").lower() == 'n': play_again = False
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter