+ 2

HELP (python)

pls dont copy my idea,can somoenoe tell how can this code works? https://code.sololearn.com/cW4xdO7KGYt1/?ref=app

19th Jul 2018, 11:47 PM
I Am Arthur
I Am Arthur - avatar
10 Réponses
+ 3
OK, part 2 b/c I found other mistakes (which should be updated in the code I posted) . 1. I don't know if it is purposeful, but the instances of "nothing happened in this round" (which is actually a good catch-all-mistakes code, good job) are because there are gaps in the if-elif 's. For example: you have if chance == 15 and then if chance <14, so then if chance==14, there isn't a condition for it so it goes to the else statement. I fixed that, I reversed the order of the if-else's so that you don' t have to specify the top bound since it checks and if the condition isn't true it goes to the next one. 2) I put the if statement checking if there's only one person left at the top, because this is something that should be checked for at the start of every turn, that way you don't have the instances of somebody dying in the last turn and then winning because they were the last person alive when the turn started
20th Jul 2018, 2:54 PM
Maria
+ 5
Can you give us your code so that we can help you.
19th Jul 2018, 11:58 PM
JTLZ
+ 3
I made it work, but strange things still happen in the output, improve your code. https://code.sololearn.com/cvQ4MyrJTYG3/?ref=app
20th Jul 2018, 2:56 AM
Satyam
+ 3
S. C. is right, except they didn't always remove the same players as the original code (sometimes player2 has to be removed instead) . But yeah, commas make tuples, even without the parentheses, and tuples are immutable so you can't change or replace anything. Instead, if you turn them into lists, which are mutable, you still can't use the replace method, because I believe it is only for strings? (I may be wrong about that) but you can use the remove method to get rid of the elements you don't want anymore. Here's my code removing the players that you had set to remove in the original (any questions just ask): https://code.sololearn.com/c2IB12hnP1JK/?ref=app
20th Jul 2018, 2:39 PM
Maria
+ 2
🐲JTLZ 🐲 Sorry,i totally forgot this 😂
20th Jul 2018, 12:26 AM
I Am Arthur
I Am Arthur - avatar
+ 2
I changed the tuples to lists.
20th Jul 2018, 3:09 AM
Satyam
+ 2
Arthur Tuple has no method of replace this method use for string and you are using a tuple in your code so you can't use replace method for tuple. you need to change your code.
20th Jul 2018, 11:38 AM
Maninder $ingh
Maninder $ingh - avatar
+ 2
(part 3 because I ran out of chars) : 3) probably a typo mistake: every time somebody died at the hands of somebody else it printed that person1 killed person2, and then it printed person1 killed (killed being the specific statement chosen) so I changed that to printing person1 killed person2 and then person2 died. Also, I noticed that there are times when a person kills themselves in some way. Unless that's okay with you, you should find out how to keep that from happening. I haven't come up with how to prevent that yet, but I'll think about it and see what I can come up with.
20th Jul 2018, 2:57 PM
Maria
+ 1
S. C. Good try but doesn't work,is the same as erase the errors.Thx anyway
20th Jul 2018, 3:08 AM
I Am Arthur
I Am Arthur - avatar
+ 1
Maninder Singh explained what I did. Tuples are IMMUTABLE, meaning they can't be changed. Lists however can be.
20th Jul 2018, 11:40 AM
Satyam