0
Sum of consecutive numbers
What is problem with my code N=int(input()) Sum=0 for Sum in range(,N+1): Sum=Sum+N print(Sum)
4 odpowiedzi
+ 2
Hi Hamza!
You have to make small changes in your for loop.
Here is corrected code
N=int(input())
Sum=0
for i in range(N+1):
Sum=Sum+i
print(Sum)
+ 2
print(sum(i for i in range(int(input()) + 1)))
https://code.sololearn.com/cDS5NDL7CDV1
+ 2
Hamza How about this one? :-
print(sum(range(int(input()) + 1)))
Or just this one? :-
print((n := int(input())) * (n + 1) // 2)
# Hope this helps
+ 1
N=100
sum=0
for i in range(1, N+1):
sum+=i
print(sum)