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,
}
while True: score = 0 # reset score at the beginning of each game first_artist, second_artist = random.sample(list(artists_listeners.keys()), 2)
while True: 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_listeners[first_artist] > artists_listeners[second_artist]: print(f"You guessed correctly! {first_artist.title()} had {artists_listeners[first_artist] / 1e6:.1f}M monthly Spotify listeners and {second_artist.title()} has {artists_listeners[second_artist] / 1e6:.1f}M monthly Spotify listeners.”) score += 1 first_artist, second_artist = random.sample(list(artists_listeners.keys()), 2) # select new artists for the next round continue
elif guess_lower == second_artist.lower() or guess_lower == ‘2’ and artists_listeners[second_artist] > artists_listeners[first_artist]: print(f"You guessed correctly! {second_artist.title()} had {artists_listeners[second_artist] / 1e6:.1f}M monthly Spotify listeners and {first_artist.title()} has {artists_listeners[first_artist] / 1e6:.1f}M monthly Spotify listeners.“) score += 1 first_artist, second_artist = random.sample(list(artists_listeners.keys()), 2) # select new artists for the next round continue
else: print(f”\nSorry, you guessed incorrectly. {first_artist.title()} had {artists_listeners[first_artist] / 1e6:.1f}M monthly Spotify listeners and {second_artist.title()} has {artists_listeners[second_artist] / 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_listeners.keys()), 2) # select new artists for the next round break
how can i change it so the game asks what music genre you want to play the game with and based on that it should only show those artists
- Assistant
- User
first_artist, second_artist = random.sample(list(artists_listeners.keys()), 2) # select new artists for the next round is this code part not neccesary?
- Assistant
The code
first_artist, second_artist = random.sample(list(artists_listeners.keys()), 2)is used to randomly select two artists for each round of the game. Since the game involves comparing the monthly Spotify listeners of two artists, you need to select two different artists randomly for each round.So, yes, this code is necessary to ensure that the game selects different artists for each round and keeps the game interesting and unpredictable.
- User
but you took it away , mine code : elif guess_lower == first_artist.lower() or guess_lower == ‘1’ and artists_listeners[first_artist] > artists_listeners[second_artist]: print(f"You guessed correctly! {first_artist} had {artists_listeners[first_artist] / 1e6:.1f}M monthly Spotify listeners and {second_artist} has {artists_listeners[second_artist] / 1e6:.1f}M monthly Spotify listeners.”) score += 1 first_artist, second_artist = random.sample(list(artists_listeners.keys()), 2) # select new artists for the next round continue
yours : elif guess_lower == first_artist.lower() or guess_lower == ‘1’ and artists_listeners[first_artist] > artists_listeners[second_artist]: print(f"You guessed correctly! {first_artist} had {artists_listeners[first_artist] / 1e6:.1f}M monthly Spotify listeners and {second_artist} has {artists_listeners[second_artist] / 1e6:.1f}M monthly Spotify listeners.”) score += 1 continue
- Assistant
You are correct. In my previous response, I mistakenly omitted the line that selects new artists for the next round:
codeelif guess_lower == first_artist.lower() or guess_lower == ‘1’ and artists_listeners[first_artist] > artists_listeners[second_artist]: print(f"You guessed correctly! {first_artist} had {artists_listeners[first_artist] / 1e6:.1f}M monthly Spotify listeners and {second_artist} has {artists_listeners[second_artist] / 1e6:.1f}M monthly Spotify listeners.") score += 1 first_artist, second_artist = random.sample(list(artists_listeners.keys()), 2) # select new artists for the next round continueThe line
first_artist, second_artist = random.sample(list(artists_listeners.keys()), 2)is necessary to select two new artists for the next round of the game. Without it, the same two artists would be compared again, which would make the game less interesting.