+ 2

Finding the sum of consecutive numbers in python

I have been stuck on the consecutive numbers project in python for beginners and I was wondering if I could get help on it. Do I have to create a variable that adds all the numbers in range?

12th Apr 2021, 12:30 PM
tirth patel
tirth patel - avatar
9 Answers
+ 1
I tried this N = int(input()) #your code goes here sum = 0 for i in range(1, N+1): sum += i print(sum) But it still shows me the list instead of the last value, I tried indexing it but since it is an integer I am getting an error message
12th Apr 2021, 12:58 PM
tirth patel
tirth patel - avatar
0
Post your attempt first
12th Apr 2021, 12:33 PM
Atul [Inactive]
0
N = int(input()) #your code goes here for N in range(0, N+1): print(N + N)
12th Apr 2021, 12:36 PM
tirth patel
tirth patel - avatar
0
//Here is an example l = [1, 3, 4, 5] sum = 0 for i in l: sum += i print(sum)
12th Apr 2021, 12:39 PM
Apongpoh Gilbert
Apongpoh Gilbert - avatar
0
Thank you šŸ‘
12th Apr 2021, 12:39 PM
tirth patel
tirth patel - avatar
0
t=0#declaring variable and assign initial value zero to it for e in range(1,5): # calculate values from 1 to 4 t+=e # adding t and e print(t)
12th Apr 2021, 12:46 PM
A J
A J - avatar
0
No in the above code you will put print(sum) inside for loop but you will put it outside for loop. just run this below code then it will give output https://code.sololearn.com/cPE8igoIzUBH/?ref=app
12th Apr 2021, 1:09 PM
A J
A J - avatar
0
N = int(input()) t=0 for e in range(0,N+1): t+=e print(t)
17th Jun 2021, 2:03 PM
Patel Armin
Patel Armin - avatar
- 1
N = int(input()) count = N x = range(1, N +1) for i in x: N = i + N print(N - count)
18th May 2021, 8:09 AM
Š˜ŃŠ»Š°Š¼ ŠŠ»Š±
Š˜ŃŠ»Š°Š¼ ŠŠ»Š± - avatar