+ 2
Program for sum of consecutive numbers. My code does not work. It displays error " File size too large" Explain plz.
N = int(input()) #your code goes here sum=0 while sum<=N : if sum==N : print(sum) else: sum += 1
13 Respuestas
+ 3
Hey guys I finally managed to do it using while loop.
https://code.sololearn.com/cdBu9vLS05mm/?ref=app
+ 6
Frank ,
your code is running in an infinite loop, as soon as condition 'if sum == N' is evaluated to True. to get rid of this, you can add a 'break' in the next line after 'print(sum)'
+ 3
Frank ,
sorry, in my last post i have not noticed that you are talking about "building the sum of consecutive nunbers". i only saw the infinite loop.
if your input is 5, the result should be: 1+ 2 + 3 + 4 + 5 which is 15.
to get this task done, it would be better to use a range() object, iterate over it and build the sum from all numbers coming from the range.
+ 3
Frank ,
that is great - do your own try. if you get stuck somewhere come back.
happy coding and good success!
+ 1
U are getting this error because u are not increment your while loop because of this your code work for infinite
+ 1
Thanks bro
+ 1
Added a break , now it justs prints the input number
+ 1
Yes bro i know I can use range I had already googled it but i wanted to do some other way. I could use the program from one of those websites but i want to practice.
+ 1
Frank try this
N = int(input())
print(int((N/2)*(N+1)))
+ 1
Better you can use n*(n+1)/2 it will be good
0
How do i resolve this issue
0
N = int(input())
#your code goes here
x=0
for i in range(1,N+1):
x += i
print (x)
- 1
LIKE ,SHARE AND REPLY 😊🤗 https://code.sololearn.com/WxA7X279c8yM/?ref=app