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
+ 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
+ 3
Angelo Abi Hanna Please try to avoid giving direct answers, especially with no explaination.
13th Dec 2023, 3:23 PM
Justice
+ 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
+ 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
+ 1
Try this #output the corresponding game print ( games [ choice - 1 ] )
15th Dec 2023, 6:59 AM
Anshika
0
choice = int(input()) selected = games[choice - 1] print(selected)
13th Dec 2023, 2:04 PM
Angelo Abi Hanna
0
#or just write print(games[int(input())-1])
13th Dec 2023, 2:16 PM
Angelo Abi Hanna
0
games = [ 'Soccer', 'Tic Tac Toe', 'Snake', 'Puzzle', 'Rally'] choice = int(input()) print(games[choice])
17th Apr 2024, 9:56 AM