0

We want sum all items in a range it is possible to do?

Help!

12th Aug 2020, 8:17 PM
Satyam Mishra
Satyam Mishra - avatar
5 Answers
+ 12
sum(range(10))
12th Aug 2020, 8:28 PM
Oma Falk
Oma Falk - avatar
+ 10
Oma Falk The answer is hidden in the question 😂
12th Aug 2020, 9:52 PM
Sebastian Keßler
Sebastian Keßler - avatar
+ 4
Yes it is possible and one such way is- print(sum(range(1,11))) It will add values from 1 to 10 and will result in 55. It takes 11-1 as last value.
12th Aug 2020, 8:30 PM
Avinesh
Avinesh - avatar
+ 4
n = int(input()) print((n*(n+1))//2)
12th Aug 2020, 8:42 PM
minirkk
minirkk - avatar
+ 1
but if do you want to do that in a complex way you can use Carl Gauss's method 😅
12th Aug 2020, 11:11 PM
Richar Lopez
Richar Lopez - avatar