import random from PIL import Image Define the artists and their monthly Spotify…
- User
import 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 a few reasons why the pictures are not showing up. Here are some possible solutions:
-
Check if the image file formats are supported by PIL. PIL only supports certain image file formats such as JPEG, PNG, BMP, etc. If your image file format is not supported, you may need to convert it to a supported format.
-
Make sure the image files are in the correct directory. Double-check the file path to ensure that the images are in the correct directory and folder.
-
Check the file names. Make sure that the file names match the names in the artists dictionary. If the file names do not match, PIL will not be able to load the images.
-
Check if the images are corrupted or damaged. Try opening the images in another photo editing software to see if they can be opened and displayed correctly. If the images are corrupted or damaged, you may need to obtain new image files.
-
Try displaying the images separately. Instead of displaying both images simultaneously, try displaying them one by one using the method from the PIL library. This may help debug the issue and identify which image is not displaying correctly.
-