import random artistslisteners = { 'Lil Baby’: 58738173, 'Roddy Ricch’: 34447081,…
- User
import random
artists_listeners = { 'Lil Baby’: 58738173, 'Roddy Ricch’: 34447081, 'DaBaby’: 29659518, 'Polo G’: 27204041, 'NLE Choppa’: 11423582, 'Lil Tjay’: 16873693, 'Lil Durk’: 19827615, 'Megan Thee Stallion’: 26685725, 'Pop Smoke’: 32169881, 'Lizzo’: 9236657, 'Migos’: 23242076, 'Doja Cat’: 33556496, 'Tyler, The Creator’: 11459242, 'Saweetie’: 10217413, 'Cordae’: 4026278, 'Juice WRLD’: 42092985, 'Travis Scott’: 52627586, 'Post Malone’: 65466387, 'Drake’: 71588843, 'Kendrick Lamar’: 33841249, 'J. Cole’: 38726509, 'Kanye West’: 29204328, 'Lil Nas X’: 23824455, '21 Savage’: 26764030, ‘Lil Uzi Vert’: 40941950 }
Select a random artist and its listener count
artist, count = random.choice(list(artists_listeners.items()))
Game loop
while True:
Ask player to guess higher or lower
guess = input(f"Is the listener count for {artist} higher or lower than {count}? (h/l): “)
Select a new artist and listener count
new_artist, new_count = random.choice(list(artists_listeners.items()))
Check player’s guess
if (guess == ‘h’ and new_count > count) or (guess == ‘l’ and new_count < count): print(‘Correct!’) artist, count = new_artist, new_count else: print(‘Incorrect!’) print(f"The correct answer was {artist} with {count} listeners.’) break
print(‘Thanks for playing!’) can this work
- Assistant
Yes, this code can work assuming that there are no syntax errors and that the indentation is correct. However, it is missing a closing quotation mark on the second line after 'Lil Baby'. It should be 'Lil Baby': 58738173 instead of 'Lil Baby’: 58738173.
- User
'Lil Baby': 58738173, like this
- Assistant
Yes, that is correct.
- User
import random
artists_listeners = { 'Lil Baby': 58738173, 'Roddy Ricch': 34447081, 'DaBaby': 29659518, 'Polo G': 27204041, 'NLE Choppa': 11423582, 'Lil Tjay': 16873693, 'Lil Durk': 19827615, 'Megan Thee Stallion': 26685725, 'Pop Smoke': 32169881, 'Lizzo': 9236657, 'Migos': 23242076, 'Doja Cat': 33556496, 'Tyler, The Creator': 11459242, 'Saweetie': 10217413, 'Cordae': 4026278, 'Juice WRLD': 42092985, 'Travis Scott': 52627586, 'Post Malone': 65466387, 'Drake': 71588843, 'Kendrick Lamar': 33841249, 'J. Cole': 38726509, 'Kanye West': 29204328, 'Lil Nas X': 23824455, '21 Savage': 26764030, 'Lil Uzi Vert': 40941950 }
Select a random artist and its listener count
artist, count = random.choice(list(artists_listeners.items()))
Game loop
while True:
Ask player to guess higher or lower
guess = input(f"Is the listener count for {artist} higher or lower than {count}? (h/l): “)
Select a new artist and listener count
new_artist, new_count = random.choice(list(artists_listeners.items()))
Check player's guess
if (guess == 'h' and new_count > count) or (guess == 'l' and new_count < count): print('Correct!') artist, count = new_artist, new_count else: print('Incorrect!') print(f"The correct answer was {artist} with {count} listeners.') break
print('Thanks for playing!')
like this?
- Assistant
Yes, this code should work as intended. Just note that there is a mismatch between the quotation marks used in the input prompt (the first ones are “ instead of the regular " ones). It is recommended to use the regular " quotation marks for consistency and readability.
- User
File "main.py", line 37 guess = input(f"Is the listener count for {artist} higher or lower than {count}? (h/l): ") ^ IndentationError: expected an indented block
** Process exited - Return Code: 1 **
- Assistant
The error message suggests that there is an indentation issue on the line where
guessis assigned. Make sure that the line is indented properly according to the code block it belongs to. It should be indented one level deeper than thewhileloop block, like this:# Game loop while True: # Ask player to guess higher or lower guess = input(f"Is the listener count for {artist} higher or lower than {count}? (h/l): ") # Select a new artist and listener count new_artist, new_count = random.choice(list(artists_listeners.items())) # Check player's guess if (guess == 'h' and new_count > count) or (guess == 'l' and new_count < count): print('Correct!') artist, count = new_artist, new_count else: print('Incorrect!') print(f"The correct answer was {artist} with {count} listeners.") break print('Thanks for playing!')Make sure that all the print statements and code statements within the
whileloop are properly indented like the examples above.