mport random from PIL import Image Define the artists and their monthly Spotify…
- User
mport random from PIL import Image
Define the artists and their monthly Spotify listeners
artists = {
'NOT': {"image":"./fotos/NOT_1.jpeg", “listeners”: 7781046},
‘21 Savage’: {“image”:“./fotos/21 Savage_1.jpeg”, “listeners”: 60358167},
}
while True: score = 0 # reset score at the beginning of each game first_artist, second_artist = random.sample(list(artists.keys()), 2)
Load the images for the artists
first_artist_image = Image.open(artists[first_artist][“image”]) second_artist_image = Image.open(artists[second_artist][“image”])
while True:
Display the images
image.show(first_artist_image) image.show(second_artist_image)
guess = input(f"\nWhich artist has more monthly Spotify listeners - 1. {first_artist.title()} or 2. {second_artist.title()}? “) guess_lower = guess.strip().lower()
if guess_lower == ‘quit’: print(“Thanks for playing!”) quit()
elif guess_lower not in [‘1’, ‘2’, first_artist.lower(), second_artist.lower()]: print(“Invalid input. Please enter the name of one of the two artists or ‘quit’ to end the game.”)
elif guess_lower == first_artist.lower() or guess_lower == ‘1’ and artists[first_artist][“listeners”] > artists[second_artist][“listeners”]: print(f"You guessed correctly! {first_artist.title()} had {artists[first_artist][‘listeners’] / 1e6:.1f}M monthly Spotify listeners and {second_artist.title()} has {artists[second_artist][‘listeners’] / 1e6:.1f}M monthly Spotify listeners.”) score += 1 first_artist, second_artist = random.sample(list(artists.keys()), 2) # select new artists for the next round
Load the images for the new artists
first_artist_image = Image.open(artists[first_artist][“image”]) second_artist_image = Image.open(artists[second_artist][“image”]) continue
elif guess_lower == second_artist.lower() or guess_lower == ‘2’ and artists[second_artist][“listeners”] > artists[first_artist][“listeners”]: print(f"You guessed correctly! {second_artist.title()} had {artists[second_artist][‘listeners’] / 1e6:.1f}M monthly Spotify listeners and {first_artist.title()} has {artists[first_artist][‘listeners’] / 1e6:.1f}M monthly Spotify listeners.“) score += 1 first_artist, second_artist = random.sample(list(artists.keys()), 2) # select new artists for the next round
Load the images for the new artists
first_artist_image = Image.open(artists[first_artist][“image”]) second_artist_image = Image.open(artists[second_artist][“image”]) continue
else: print(f”\nSorry, you guessed incorrectly. {first_artist.title()} had {artists[first_artist][‘listeners’] / 1e6:.1f}M monthly Spotify listeners and {second_artist.title()} has {artists[second_artist][‘listeners’] / 1e6:.1f}M monthly Spotify listeners.\n") print(f"Your final score is {score}.") play_again = input("Would you like to play again? (y/n) ") if play_again.lower() == ‘n’: print(“Thanks for playing!”) quit() else: score = 0 first_artist, second_artist = random.sample(list(artists.keys()), 2) # select new artists for the next round
- Assistant
There could be multiple reasons why the pictures are not showing up. Here are a few things you can check:
- Make sure that the image format is supported by the PIL library. The commonly supported formats are PNG, JPEG/JPG, BMP, TIFF, and GIF.
- Check if the images are corrupted. Try opening them in an image viewer to make sure they can be opened and displayed correctly.
- Verify if the path to the images is correct. You can print the path to both images and check if they are pointing to the right location.
- Check if the images are hidden or have different permissions that prevent opening them. Try changing the permissions of the image files or copying them to a new location and see if the issue persists.
If none of these solutions work, try googling for other solutions or seek help from a developer community forum.