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
9 Antworten
+ 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])
+ 3
Angelo Abi Hanna Please try to avoid giving direct answers, especially with no explaination.
+ 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
+ 1
Justice sorry, i was just trying to help, but note that the code i gave is still missing error handling
+ 1
Try this
#output the corresponding game
print ( games [ choice - 1 ] )
0
choice = int(input())
selected = games[choice - 1]
print(selected)
0
#or just write
print(games[int(input())-1])
0
games = [
'Soccer', 'Tic Tac Toe', 'Snake',
'Puzzle', 'Rally']
choice = int(input())
print(games[choice])
0
I don't know.... 😅