+ 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

3rd Feb 2022, 8:22 AM
Lenoname
17 Respuestas
+ 3
No. Do This way : [ a+1 for a in range(len(games)) if games[a]== max(games) ]
3rd Feb 2022, 11:56 AM
Jayakrishna 🇮🇳
+ 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')
3rd Feb 2022, 9:41 AM
Jayakrishna 🇮🇳
+ 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 .
4th Feb 2022, 5:56 PM
Abdulatif Mohamednor Mohamed
Abdulatif Mohamednor Mohamed - avatar
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
3rd Feb 2022, 8:53 AM
Muhammad Galhoum
Muhammad Galhoum - avatar
0
Muhammad they user gets -1 point for a wrong answer and +2 for a correct answer.
3rd Feb 2022, 9:05 AM
Lenoname
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)
3rd Feb 2022, 9:17 AM
Muhammad Galhoum
Muhammad Galhoum - avatar
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
3rd Feb 2022, 10:58 AM
Lenoname
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?
3rd Feb 2022, 11:09 AM
Jayakrishna 🇮🇳
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.
3rd Feb 2022, 11:17 AM
Lenoname
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')
3rd Feb 2022, 11:20 AM
Jayakrishna 🇮🇳
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
3rd Feb 2022, 11:24 AM
Lenoname
0
”The best game was game [x,y] with z points”
3rd Feb 2022, 11:26 AM
Lenoname
0
So use a+1, Is it solved then? Lenoname
3rd Feb 2022, 11:30 AM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 thats the problem, if i just add +1 the system crashes and says ”can only concatenate list (not ”int”) to list
3rd Feb 2022, 11:34 AM
Lenoname
0
Where you adding? Am getting it , no errors..
3rd Feb 2022, 11:45 AM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 at the end.wrong??
3rd Feb 2022, 11:50 AM
Lenoname
0
[a for a in range(len(games))if games[a]== max(games)]+1
3rd Feb 2022, 11:52 AM
Lenoname