0

Solve this I have got stuck in it

#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

13th Dec 2023, 12:43 PM
vankudoth vittal
vankudoth vittal - avatar
9 Réponses
+ 1
Well the user gives the number, and you can have the input statement like - choice = int(input("Enter 0 for soccer, 1 for Tic Tac Toe, 2 for Snake, 3 for Puzzle or 4 for Rally") Then you just do - Print(games[choice])
15th Dec 2023, 10:19 AM
Tejas Shyam
Tejas Shyam - avatar
+ 3
Angelo Abi Hanna Please try to avoid giving direct answers, especially with no explaination.
13th Dec 2023, 3:23 PM
Justice
Justice - avatar
+ 2
vankudoth vittal If you are trying to output a game in the list, when the user enters a number, you can check what number the user entered as input, and output the game by its index. lets say we want the first game to be outputed. I would want to type 1 for input. You check if I typed 1. After that, you output the first game by its index. List indexes start at 0. https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/python_conditions.asp Just look at the first example here: https://www.w3schools.com/python/python_lists_access.asp
13th Dec 2023, 1:09 PM
Junior
Junior - avatar
+ 1
Justice sorry, i was just trying to help, but note that the code i gave is still missing error handling
13th Dec 2023, 3:39 PM
Angelo Abi Hanna
Angelo Abi Hanna - avatar
+ 1
Try this #output the corresponding game print ( games [ choice - 1 ] )
15th Dec 2023, 6:59 AM
Anshika
Anshika - avatar
0
choice = int(input()) selected = games[choice - 1] print(selected)
13th Dec 2023, 2:04 PM
Angelo Abi Hanna
Angelo Abi Hanna - avatar
0
#or just write print(games[int(input())-1])
13th Dec 2023, 2:16 PM
Angelo Abi Hanna
Angelo Abi Hanna - avatar
0
games = [ 'Soccer', 'Tic Tac Toe', 'Snake', 'Puzzle', 'Rally'] choice = int(input()) print(games[choice])
17th Apr 2024, 9:56 AM
Gennady Korjos
Gennady Korjos - avatar
0
I don't know.... 😅
16th Jul 2024, 9:14 AM
SIVA
SIVA - avatar