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.

9th Aug 2022, 11:19 PM
Tina Hagar
12 ответов
+ 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
9th Aug 2022, 11:47 PM
Djeddi Mohamed Islem
Djeddi Mohamed Islem - avatar
+ 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)))
10th Aug 2022, 12:43 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Thanks!
9th Aug 2022, 11:48 PM
Tina Hagar
+ 1
Haha glad to help keep it up !
10th Aug 2022, 12:07 AM
Djeddi Mohamed Islem
Djeddi Mohamed Islem - avatar
+ 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)
11th Aug 2022, 1:26 AM
Swaraj Soubhagya Khandai
Swaraj Soubhagya Khandai - avatar
0
Don't lose hope! I know the answer but I'm too tired :(
9th Aug 2022, 11:25 PM
ρү૨œdԌ૨ ×
ρү૨œdԌ૨ × - avatar
0
Well thats probably not a good response for me at this moment.
9th Aug 2022, 11:27 PM
Tina Hagar
0
If you want my advice start learning something else like web development bcz you will be bored if you only study one language
9th Aug 2022, 11:50 PM
Djeddi Mohamed Islem
Djeddi Mohamed Islem - avatar
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.
9th Aug 2022, 11:55 PM
Tina Hagar
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
10th Aug 2022, 12:02 AM
Djeddi Mohamed Islem
Djeddi Mohamed Islem - avatar
0
Thanks! That is exactly what was messing with me haha.
10th Aug 2022, 12:05 AM
Tina Hagar
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)
1st Feb 2023, 7:48 PM
Joshua Nichols
Joshua Nichols - avatar