+ 1
How to print out the total points and which game was the best?
Btw I wrote the code to get the games with the best points but they are indexes meaning they start with 0 and when i try to add 1 i get error for some reason And also i cant print out the total points received after all the games played. https://code.sololearn.com/cbqHp5U9kd1Y/?ref=app
17 Answers
+ 3
No. Do This way :
[ a+1 for a in range(len(games)) if games[a]== max(games) ]
+ 1
Your asking 10 trials, but it's rare to guess the correct. So when I try, it's always wrong so score is -10 always..
So list is like [-10, -10, -10,.. ] , if on success 2 score is added to list.
max(games) is either 2 or -10
It have duplicate values of 2 and -10
So try to reduce trials..
Is your difficulty in Total print? Use
sum function..
And
print('Total points: ' , sum(games) )
print('Games played :' , len(games))
print('The best game was game ' , games.index(max(games))+1, 'with' , max(games) ,'points')
+ 1
Lenoname
Hi , I made at sane game ( guess the number ) and I hope to help you .
https://code.sololearn.com/c9AzZ1kKyO0V/?ref=app
Flow it and compare .
0
I think the better for you to run this code on PC or online editor because of you are using while loop and this program will not run correctly on sololearn
But I have question , why u subtract 1 from c variable when the condition is false , my opinion is to leave the value of c variable = 0 and change it only if the condition is true
0
Muhammad they user gets -1 point for a wrong answer and +2 for a correct answer.
0
Lenoname
Already , I understand this before your comment but if the user fail in 4 attempts then the value of c will be -4 ok , finally the player win the game and didn't want to continue playing then the value of c = -4 + 2 = -2
Are you want to tell the player that his result = negative Number in some attempts🤔 that's wrong 😊
So my opinion is to pin the value of c or use if condition to check if the value of c > 0 in this attempt you can subtract 1 from the value of c and if c = 0 let the value c = 0
Also you can give fixed times for any player like 3 times of attempts if the user didn't guess the right value before 3 times of attempts then he will lose the game, otherwise he will earn the game (this is my opinion)
0
Jayakrishna🇮🇳 it has to be 10 trials, i didnt use games.index(max(games))+1 because maybe 2 or more games have the same score
0
If you want all, then your way will work.. If you use max function then it will return first max index..
You can keep to 10 trials.. But test with less trials.. Is there any other problem now?
0
Jayakrishna🇮🇳 now i can get the total points but still if i use max function it will only get one game printed out even if multiple games have the same value, Thanks anyway! If u have more suggestions please do tell.
0
Then, Your this way works!!?
print('The best game was game ' , [a for a in range(len(games))if games[a]== max(games)] , 'with' , max(games) ,'points')
0
Jayakrishna🇮🇳 yes but i only get the index number like [0] or [1] or [0,1], if i can only add 1 to them they would be fine
0
”The best game was game [x,y] with z points”
0
So use a+1,
Is it solved then? Lenoname
0
Jayakrishna🇮🇳 thats the problem, if i just add +1 the system crashes and says ”can only concatenate list (not ”int”) to list
0
Where you adding? Am getting it , no errors..
0
Jayakrishna🇮🇳 at the end.wrong??
0
[a for a in range(len(games))if games[a]== max(games)]+1