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!')is this functional
- Assistant
Yes, this code is functional. However, there is an indentation error on line 19 that needs to be fixed in order for the code to run properly.
- User
what should be done
- Assistant
The code should be indented properly for the
elseblock to be a part of thewhileloop. Here's the corrected code: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!') - 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 ** what does this mean
- Assistant
This error message means that there is an indentation error in the code at the line mentioned (line 37). It is saying that Python is expecting an indented block of code following that line, but it is not present.
In this specific case, it looks like the previous block of code (
ifstatement) is not properly indented, which is causing the error. Theifstatement should be indented by one level so it is inside thewhileloop.