- 1

Please help me to understand this briefly

N = int(input()) count = N x = range(1, N +1) for i in x: N = i + N print(N - count)

4th Jul 2021, 5:51 AM
Chinmaya Chiranjibi Lenka IX-B - 34
Chinmaya Chiranjibi Lenka IX-B - 34 - avatar
7 Answers
+ 3
Chinmaya Chiranjibi Lenka IX-B - 34 sum is a function and count is a variable. I have used sum as a variable in previous reply but we should not use any identifier as a variable.
4th Jul 2021, 12:49 PM
A͢J
A͢J - avatar
+ 4
Chinmaya Chiranjibi Lenka IX-B - 34 This is the solution to sum integer value 1 to N. So if N is 10 then range(1, N + 1) will give 55 but you are adding N to this range output so total means N will be N = N + 55 = 10 + 55 = 65. But you have printed N - count so output will be 65 - 10 = 55. But your this solution is confusing for new learner so here is easy solution sum1 = 0 for i in range(1, N + 1): sum1 = sum1 + i print (sum1)
4th Jul 2021, 6:24 AM
A͢J
A͢J - avatar
+ 4
Chinmaya Chiranjibi Lenka IX-B - 34 because range(1, N + 1) means range (1, 11) will return a list with values (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) and the sum of this list will be 55. Try this in code playground l = range(1, 11) print (list(l)) print (sum(l))
4th Jul 2021, 7:50 AM
A͢J
A͢J - avatar
+ 3
that's a weird solution to sum up the integers from 1 to N ^^
4th Jul 2021, 5:57 AM
visph
visph - avatar
0
If N is 10 how range (1,N+1) will give 55? plz briefly explain I am time....
4th Jul 2021, 7:47 AM
Chinmaya Chiranjibi Lenka IX-B - 34
Chinmaya Chiranjibi Lenka IX-B - 34 - avatar
0
Is sum a variable? Is count a variable?
4th Jul 2021, 12:42 PM
Chinmaya Chiranjibi Lenka IX-B - 34
Chinmaya Chiranjibi Lenka IX-B - 34 - avatar
0
Thnx
4th Jul 2021, 12:50 PM
Chinmaya Chiranjibi Lenka IX-B - 34
Chinmaya Chiranjibi Lenka IX-B - 34 - avatar