+ 1
can you help me with python practice game machine code?
the output is a bit confusing
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
+ 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 .
+ 2
Edison Mlambo ,
Can you show your code...??
So we could help you in it...
+ 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*
+ 1
Thank you so much Riya, so those types of challenges you can approach them with previous topics like if-else statements?
+ 1
Can u help me learn python pls
+ 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 .
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
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')
0
Thanks for the information