+ 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?

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

0

Post your attempt first

0

N = int(input())
#your code goes here
for N in range(0, N+1):
print(N + N)

0

//Here is an example
l = [1, 3, 4, 5]
sum = 0
for i in l:
sum += i
print(sum)

0

Thank you 👍

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)

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

0

N = int(input())
t=0
for e in range(0,N+1):
t+=e
print(t)

- 1

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

Hot today

difference in while loop

2 Votes

Somebody help me please 🥺

0 Votes

Kotlin get if Var doesn't exist

-1 Votes

Open a web site in C#

0 Votes

What is input?

0 Votes