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?
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
Post your attempt first
N = int(input()) #your code goes here for N in range(0, N+1): print(N + N)
//Here is an example l = [1, 3, 4, 5] sum = 0 for i in l: sum += i print(sum)
Thank you 👍
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)
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
N = int(input()) t=0 for e in range(0,N+1): t+=e print(t)
N = int(input()) count = N x = range(1, N +1) for i in x: N = i + N print(N - count)
Why are my users being logged as [object Object] when logging my array/user instead of giving me the values [name, age]?
JS in sololear is latest version or older? What do we use often VAR or LET and CONST?? I Have VAR is no longer used is it true??
difference in while loop
Somebody help me please 🥺
Kotlin get if Var doesn't exist
Open a web site in C#
What is input?