+ 4

What is the error?

I can't find my mistake help me to find my mistake https://code.sololearn.com/cxzyEdbQJBZr/?ref=app

8th Apr 2020, 6:06 AM
Utsav Singh
Utsav Singh - avatar
8 Respostas
+ 4
Thanks Russ for your kind help and also next time i keep things in mind while coding.🎉
8th Apr 2020, 10:34 AM
Utsav Singh
Utsav Singh - avatar
+ 3
Its okay Russ Thank you for the correction you have made in this code. As i am student i want to ask you which book you prefer for to improvise the code. If you assist me to improve my coding it would be a great help.
8th Apr 2020, 11:08 AM
Utsav Singh
Utsav Singh - avatar
+ 3
Its okayRuss thank you again😊
8th Apr 2020, 11:25 AM
Utsav Singh
Utsav Singh - avatar
+ 3
Thanks Code Crasher this is useful 😊
8th Apr 2020, 3:28 PM
Utsav Singh
Utsav Singh - avatar
+ 2
There are a few issues with your code. Firstly, for loops do not require you to manually increment the iterator variable. for i in range(5): ... does not require you to put i = i + 1 inside. It increments automatically. Secondly, the variable in your while loops only need to be altered at the end of each for loop, not with every iteration of it. Thirdly, your if statement (line 33) was throwing an IndexError because you were referencing an index beyond its range. Here is your amended code. https://code.sololearn.com/cV0Y7paK2Qj2/?ref=app
8th Apr 2020, 9:03 AM
Russ
Russ - avatar
+ 2
Coder Singh♋ Just a piece of advice for the future; it makes a huge difference if either your code is documented in order to help someone else reading it to understand what it's trying to achieve, or if you name your variables with a more-meaningful name than 'r' or 'e'. The truth is that you would have gotten an answer here much, much quicker had you done either of these. It's only because I'm sitting here with no work to do that I had the time or inclination to try and pick apart your code and what each section was trying to do. It all may look obvious to you, but for a fresh pair of eyes, trust me it looks like a random jumble. Document and/or name variables properly. It's a very good habit to get into. 👍 Happy coding!
8th Apr 2020, 9:10 AM
Russ
Russ - avatar
+ 2
Apologies Coder Singh♋ : when I saved my amended code, I didn't notice that it reset itself to your original code đŸ€ŠđŸŒâ€â™‚ïž Code updated now.
8th Apr 2020, 10:47 AM
Russ
Russ - avatar
+ 2
Coder Singh♋ I've never taken any CS class nor have I used any books to learn. All my knowledge pretty much comes from SL and partaking in challenges and stuff. Sorry I can't help you in that respect. If you need help in future with a problem, I'm happy to accept PMs 😉
8th Apr 2020, 11:22 AM
Russ
Russ - avatar