+ 1

Total sum of numbers

Please I need help on getting the total sum of numbers For example if I take a user input of any integer like 12 I have to get the total of 1+2+3……. till the end Please if you understand my question help me out Thanks

14th Jun 2022, 10:48 PM
Dayveed_ Chukz
Dayveed_ Chukz - avatar
6 Réponses
+ 1
You can use the range(start,end) function to get the required range of numbers and then use sum() function to get the sum of all numbers in that range. Ex. sum(range(0,11)). It will give the sum 0+1+2....+10
15th Jun 2022, 2:31 AM
Pavan Barve
Pavan Barve - avatar
+ 1
a = 0 for i in range(int(input())):a+=i print(a) This should be working.
15th Jun 2022, 5:07 AM
Satyam Mishra
Satyam Mishra - avatar
+ 1
Easy: https://www.wikihow.com/Find-the-Sum-of-an-Arithmetic-Sequence a = int(input(' :-> ')) s = -~a/2*a s0 = sum(range(a+1)) print(s,s0)
15th Jun 2022, 5:48 AM
Ervis Meta
Ervis Meta - avatar
+ 1
Here is the answer. Hope this will help you: # Adarsh Addee # Add all numbers # 16 June, 2022 num = int(input("Enter digit: ")) print(sum(range(1, num+1))) def add(num): sum = 0 for val in range(1, num+1): sum += int(val) return sum print(add(13)) https://code.sololearn.com/cpPTJFy5q6w6/?ref=app
16th Jun 2022, 4:19 PM
Adarsh Addee
Adarsh Addee - avatar
0
Use sum(range(start, end)) built-in function, imo.
16th Jun 2022, 10:13 AM
Adrian Alvarez Abaigar
Adrian Alvarez Abaigar - avatar
0
You can write a for loop using range function from 1 to n + 1 (n is the number whose sum from 1 to it is to be found) and sum it over that range. You need to initialize your sum at 0.
16th Jun 2022, 4:36 PM
Sobola Gabriel
Sobola Gabriel - avatar