+ 2

Hi I have an issue with this code

#installed games games = [ 'Soccer', 'Tic Tac Toe', 'Snake', 'Puzzle', 'Rally'] #taking player's choice as a number input choice = int(input()) #output the corresponding game

19th Jan 2025, 3:10 PM
stefan lucchesi
stefan lucchesi - avatar
4 Antworten
+ 6
This is from Introduction to Python -> Working With Lists -> Game Machine. Up until this point, the lesson has shown you examples of indexing into a list by using a fixed constant integer number. For example: devices = ["TV", "Notebook", "PC"] print(devices[1]) # index 1 is "Notebook" The exercise is asking you to use a variable as an index instead of a constant number. Example: devices = ["TV", "Notebook", "PC"] num = 1 print(devices[num]) # prints the same result as above The code in the exercise defines a list of games. Then it prompts the user to type in a game number. It stores the integer value of the input into a variable named choice. Your job is to write a line of code that uses the choice variable as an index into the games list and print out the name of the selected game.
19th Jan 2025, 3:40 PM
Brian
Brian - avatar
+ 1
If you want to output the corresponding game you should do this games =['Soccer','Tic Tac Toe','Snake','Puzzle','Rally'] choice=int(input()) print(games[choice])
21st Jan 2025, 11:04 AM
ROHAN PATIL
ROHAN PATIL - avatar
0
Hello, Here's a short comment for your code: https://www-whataburgervisit.com python #installed games games = [ 'Soccer', 'Tic Tac Toe', 'Snake', 'Puzzle', 'Rally'] #taking player's choice as a number input choice = int(input("Enter the number corresponding to your game choice: ")) #output the corresponding game print("You chose:", games[choice]) Best regards, Fapem Henry
30th Jan 2025, 6:27 AM
Fapem Henry