+ 1

Please can you tell me why it doesn't work ?

It output all the numbers before the number we want to output . N = int(input()) sum=0 for number in range(1,N+1): sum = sum+number some=+sum print (some)

8th Feb 2022, 12:10 PM
Programer F_K
Programer F_K - avatar
6 Answers
+ 1
Do you want single output of 'some'? Then just take out print statement from loop.. N = int(input()) sum=0 for number in range(1,N+1): sum = sum+number print (sum) #single variable is enough.
8th Feb 2022, 12:20 PM
Jayakrishna šŸ‡®šŸ‡³
+ 2
Output all the numbers before <N> or output <sum> in each iteration? What's variable <some> for anyways?
8th Feb 2022, 12:19 PM
Ipang
+ 2
Output <sum> in each iteration Some is the sum of all the sums
8th Feb 2022, 12:20 PM
Programer F_K
Programer F_K - avatar
+ 1
8th Feb 2022, 12:24 PM
Programer F_K
Programer F_K - avatar
+ 1
You are idented print in loop. Take it out of loop. And single variable is enough, as both works same.. You're welcome.. Programer F_K
8th Feb 2022, 12:27 PM
Jayakrishna šŸ‡®šŸ‡³
+ 1
Looks like this has been solved, but I would recommend different variable namesā€¦in English, ā€œsomeā€ and ā€œsumā€ sound identical. So to avoid confusion when reciting through your code, you may find it benefical to have different sounding variable names. Keep up the good work! :)
9th Feb 2022, 1:27 PM
Andrew Johnson
Andrew Johnson - avatar