from PIL import Image import requests from io import BytesIO import random…
- User
from PIL import Image import requests from io import BytesIO import random
artists_listeners = { '21 Savage': 60358167, 'Cardi B': 30319082, 'Drake': 55693480, 'J. Cole': 36626203, 'Lil Baby': 30600740, 'Lil Durk': 20244848, 'Megan Thee Stallion': 23815306, 'NLE Choppa': 17472472, 'Polo G': 24374576, 'Pop Smoke': 24438919, 'Rod Wave': 8037875, 'Travis Scott': 46625716, 'Young Thug': 28887553, }
keys = list(artists_listeners.keys())
score = 0 while True: first_artist = random.choice(keys) second_artist = random.choice(keys)
while first_artist == second_artist: second_artist = random.choice(keys)
first_artist_image = Image.open(BytesIO(requests.get(f"https://source.unsplash.com/300x300/?{first_artist.replace(' ', '')}").content)) second_artist_image = Image.open(BytesIO(requests.get(f"https://source.unsplash.com/300x300/?{second_artist.replace(' ', '')}").content)) images = [first_artist_image, second_artist_image] random.shuffle(images)
print(f"\nWhich artist has more monthly Spotify listeners?") print(f"1. {second_artist.title()}") print(f"2. {first_artist.title()}") for image in images: image.show()
guess = input("\nEnter 1 or 2 (or 'quit' to end the game): ") guess_lower = guess.strip().lower()
while guess_lower not in ['1', '2', 'quit']: print("Invalid input. Please enter 1 or 2 to choose an artist, or 'quit' to end the game.") guess = input("Enter 1 or 2: ") guess_lower = guess.strip().lower()
if guess_lower == 'quit': print(f"Thanks for playing! Your final score is {score}.") break
if guess_lower == '1' and artists_listeners[second_artist] > artists_listeners[first_artist]: print(f"You guessed correctly! {second_artist.title()} had {artists_listeners[second_artist]:,} monthly Spotify listeners and {first_artist.title()} had {artists_listeners[first_artist]:,} monthly Spotify listeners.") score += 1
elif guess_lower == '2' and artists_listeners[first_artist] > artists_listeners[second_artist]: print(f"You guessed correctly! {first_artist.title()} had {artists_listeners[first_artist]:,} monthly Spotify listeners and {second_artist.title()} had {artists_listeners[second_artist]:,} monthly Spotify listeners.") score += 1
else: correct_artist_image = Image.open(BytesIO(requests.get(f"https://source.unsplash.com/300x300/?{first_artist.replace(' ', '')}").content)) print(f"\nYou guessed incorrectly. {first_artist.title()} had {artists_listeners[first_artist]:,}M monthly Spotify listeners and {second_artist.title()} had {artists_listeners[second_artist]:,}M monthly Spotify listeners.\n") score = 0
- Assistant