Please Help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Please Help

I’m having some trouble with my code. It’s a small assignment where it lets the user input a max number. Then my code will add every single number start at 0 up to that max number together and then output the sum of all those numbers. ### This is my code### https://code.sololearn.com/cI3jYgx5N7WS/?ref=app Now the issue with this code is that it does in fact output the sum, however it outputs every single time it adds one number to another. While I only want it to just output the last max sum.

30th Apr 2021, 7:42 PM
Victor Fernandez
Victor Fernandez - avatar
3 Answers
+ 5
De-indent line 10 so the print statement is outside the for loop and it will only print the sum when the loop has finished.
30th Apr 2021, 7:57 PM
Russ
Russ - avatar
+ 2
We've all been there, don't worry! Happy coding!
30th Apr 2021, 8:01 PM
Russ
Russ - avatar
+ 1
Thank you so much!!! Ive literally been hurting my brain for the past two hours, I’ve tried different fuctions and just to think, all that was wrong was the indenation!
30th Apr 2021, 7:59 PM
Victor Fernandez
Victor Fernandez - avatar