+ 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
6 Answers
+ 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
+ 1
a = 0
for i in range(int(input())):a+=i
print(a)
This should be working.
+ 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)
+ 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
0
Use sum(range(start, end)) built-in function, imo.
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.