import random artistslisteners = { '$NOT': 7781046, '21 Savage': 60358167, '9lokknine':…
- User
import random
artists_listeners = { '$NOT': 7781046, '21 Savage': 60358167, '9lokknine': 1680245, 'A Boogie Wit Da Hoodie': 18379137, 'Ayo & Teo': 1818645, 'Bhad Bhabie': 1915352, 'Blueface': 4890312, 'Bobby Shmurda': 2523069, 'Cardi B': 30319082, 'Central Cee': 22520846, 'Chief Keef': 9541580, 'Coi Leray': 28619269, 'DaBaby': 30353214, 'DDG ': 4422588, 'Denzel Curry': 755542, 'Desiigner': 5586908, 'Don Toliver': 27055150, 'Dusty Locane': 3213566, 'Est Gee': 5916299, 'Famous Dex': 2768895, 'Fivio Foreign ': 9378678, 'Fredo Bang': 1311960, 'Future': 47165975, 'Gazo': 5342471, 'GloRilla': 6273110, 'Gunna ': 23998763, 'Hotboii': 1816019, 'Iann Dior': 14092651, 'J. Cole': 36626203, 'JayDaYoungan': 1415050, 'Juice WRLD ': 31818659, 'Key Glock': 10397097, 'King Von': 7608559, 'Kodak Black': 24267064, 'Latto': 10943008, 'Lil Baby': 30600740, 'Lil Durk': 20244848, 'Lil Keed': 2288807, 'Lil Loaded': 2130890, 'Lil Mabu': 2886517, 'Lil Mosey': 8260285, 'Lil Peep': 15028635, 'Lil Pump': 7530070, 'Lil Skies': 4895628, 'Lil Tecca': 13070702, 'Lil Tjay': 19119581, 'Lil Uzi Vert ': 3538351, 'Lil Wayne': 32506473, 'Lil Xan': 2590180, 'Lil Yachty': 11932163, 'Machine Gun Kelly': 13883363, 'Megan Thee Stallion ': 23815306, 'Moneybagg Yo': 11361158, 'NLE Choppa ': 17472472, 'NoCap': 1030289, 'Offset': 15069868, 'Playboi Carti': 16406109, 'PnB Rock': 5127907, 'Polo G': 24374576, 'Pooh Shiesty': 4833055, 'Pop Smoke': 24438919, 'Quando Rondo': 1511549, 'Quavo': 15944317, 'Rod Wave ': 8037875, 'Roddy Ricch': 22317355, 'Russ Millions ': 6089378, 'Ski Mask The Slump God': 9417485, 'Sleepy Hallow': 8794484, 'Smokepurpp': 2377384, 'Soulja Boy': 10269586, 'SpottemGottem': 1421927, 'Takeoff': 9756119, 'Tay-K': 4449331, 'Tee Grizzley': 4052375, 'Travis Scott': 46625716, 'Trippie Redd': 19120728, 'Waka Flocka Flame': 5679474, 'XXXTENTACION': 35627974, 'YBN Nahmir ': 4361289, 'YK Osiris': 1686619, 'YNW Melly ': 8782917, 'YounBoy Never Broke Again': 18212921, 'Young M.A': 2274306, 'Young Nudy': 7553116, 'Young Thug': 28887553, 'Yungeen Ace': 1294188, }
Create a dictionary that maps the names of the rappers to their corresponding keys in the artists_listeners dictionary
names_to_keys = {} for key, value in artists_listeners.items(): names_to_keys[key.lower()] = key
keys = list(artists_listeners.keys())
score = 0
while True: # Choose two random rappers first_artist, second_artist = random.sample(keys, 2)
# Prompt the user to guess which rappper has more monthly listeners print(f"\nWhich artist has more monthly Spotify listeners: 1. {first_artist} ({artists_listeners[first_artist]:,}) or 2. {second_artist} ({artists_listeners[second_artist]:,})?") guess = input("Enter the name or number of the artist you think has more monthly Spotify listeners or 'quit' to end the game: ") guess = guess.strip().lower() # Check if the user wants to quit the game if guess == 'quit': print("Thanks for playing!") quit() # Try to interpret the user input as a number first try: guess_int = int(guess) if guess_int not in {1, 2}: print("Invalid input. Please enter 1 or 2 for the number of the artist you think has more monthly listeners, or their name.") continue if guess_int == 1: guess_key = first_artist else: guess_key = second_artist # If user input is not a number, try to interpret it as an artist name except ValueError: guess_key = names_to_keys.get(guess) if guess_key is None or guess_key not in {first_artist, second_artist}: print("Invalid input. Please enter 1 or 2 for the number of the artist you think has more monthly listeners, or their name.") continue # Determine the correct answer and update score and last-used numbers if necessary if artists_listeners[first_artist] >= artists_listeners[second_artist]: correct_index = "1" if first_artist == guess_key else "2" if first_artist != second_artist: last_used_1 = first_artist if correct_index == "1" else second_artist last_used_2 = second_artist if correct_index == "1" else first_artist else: correct_index = "2" if second_artist == guess_key else "1" if first_artist != second_artist: last_used_1 = second_artist if correct_index == "1" else first_artist last_used_2 = first_artist if correct_index == "1" else second_artist if guess_key == first_artist or guess_key == second_artist: if guess_key == names_to_keys.get(first_artist.lower()): last_used_1 = first_artist elif guess_key == names_to_keys.get(second_artist.lower()): last_used_2 = second_artist if guess_key == names_to_keys.get(first_artist.lower()): guess_key = first_artist elif guess_key == names_to_keys.get(second_artist.lower()): guess_key = second_artist if guess_key == correct_index: print("Congratulations! You guessed correctly.") score += 1 else: print(f"Sorry, that's incorrect. The correct answer was {correct_index}.") score = 0 play_again = input("Would you like to play again? (y/n) ") if play_again.lower() == "n": print("Thanks for playing!") quit() # Print the current score print(f"Your current score is {score}.\n") - Assistant