+ 1

can you help me with python practice game machine code?

the output is a bit confusing

8th Sep 2023, 9:54 AM
Edison Mlambo
Edison Mlambo - avatar
10 Antworten
+ 9
Edison Mlambo , The problem is as per your choice the game should be displayed...so you should use if condition for that... Here go through it...first code is based on nested if statements... second code is it's compacted solution.... https://code.sololearn.com/cQ64SUWTi3bx/?ref=app https://code.sololearn.com/c2EtQ8u1miLD/?ref=app
8th Sep 2023, 11:36 AM
Riya
Riya - avatar
+ 3
games = [ 'Soccer', 'Tic Tac Toe', 'Snake', 'Puzzle', 'Rally'] #taking player's choice as a number input choice = int(input()) #output the corresponding game print(games[choice]) #the variable 'choice', takes index of the list items as input, calling it in print statement with a square bracket, outputs the item in the list bearing the index number .
23rd Nov 2023, 2:22 PM
EZE VICTOR CHIDIOGO
EZE VICTOR CHIDIOGO - avatar
+ 2
Edison Mlambo , Can you show your code...?? So we could help you in it...
8th Sep 2023, 11:05 AM
Riya
Riya - avatar
+ 2
#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 print(game[0]) print(game[2]) print(game[4]) *the end result says my output is incorrect*
8th Sep 2023, 11:28 AM
Edison Mlambo
Edison Mlambo - avatar
+ 1
Thank you so much Riya, so those types of challenges you can approach them with previous topics like if-else statements?
8th Sep 2023, 5:13 PM
Edison Mlambo
Edison Mlambo - avatar
+ 1
Can u help me learn python pls
10th Sep 2023, 12:40 AM
Khalid
+ 1
#the variable 'choice', takes index of the list items as input, calling it in print statement with a square bracket, outputs the item in the list bearing the index number .
9th Dec 2023, 11:56 AM
EZE VICTOR CHIDIOGO
EZE VICTOR CHIDIOGO - avatar
0
EZE VICTOR CHIDIOGO Can you explain your amazing simple solution? I wrote a good code, with a long and complex if-elif - else souliton, but I'm very interested about your explanation Thanks
9th Dec 2023, 8:05 AM
Flóra-Szekeres Barbara
Flóra-Szekeres Barbara - avatar
0
#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 if choice == 0 : print('Soccer') elif choice == 2 : print('Snake') else: print('Rally')
8th Jan 2024, 12:12 PM
Mohammed Afzal Hussain
Mohammed Afzal Hussain - avatar
0
Thanks for the information
3rd Oct 2024, 8:17 AM
hgtmkop