0

# Python for beginners - sum of consecutive numbers code problem

Help needed! I have no idea how to solve this and I’m getting tired and thinking of quitting. Codecademy is by far better than this app, but I like how it motivates me to do a little each day. Right now though I have no idea how to progress.

12 odpowiedzi

+ 3

N = input()
X = 0
For i in range(N+1):
X += i
Print(X)
#I encourage you to keep going on sololearn bro at some point such problems would be super easy

+ 5

Tina Hagar
I am glad you got a result to your query.
Here is another option for you to consider which shows some of the flexibility of Python
print(sum(range(int(input())+1)))

+ 1

Thanks!

+ 1

Haha glad to help keep it up !

+ 1

n = int(input())
x = 0
for i in range(n+1):
#this for will have values from 0 , if you want you can have i.e. eg : range(-2,2):
x += i
print(x)

0

Don't lose hope! I know the answer but I'm too tired :(

0

Well thats probably not a good response for me at this moment.

0

If you want my advice start learning something else like web development bcz you will be bored if you only study one language

0

I have already studied C++, HTML, CSS, Java Script (which I hated haha), now I want to add Python. Maths is not my strong point either so I’m also doing a maths course.

0

Well that's really cool ! Btw I just remembered you must replace the first line with "N = int(input())" or your input would be considered as a string not an integer

0

Thanks! That is exactly what was messing with me haha.

0

Let it be known, that this was a difficult exam. However, the answer is here:
N = input()
X = 0
For i in range(N+1):
X += i
Print(X)