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)

2nd Aug 2021, 6:01 PM
Hamza Abdul Wahab
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)
2nd Aug 2021, 6:06 PM
Python Learner
Python Learner - avatar
+ 2
print(sum(i for i in range(int(input()) + 1))) https://code.sololearn.com/cDS5NDL7CDV1
3rd Aug 2021, 2:51 AM
David Ashton
David Ashton - avatar
+ 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
3rd Aug 2021, 6:26 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
N=100 sum=0 for i in range(1, N+1): sum+=i print(sum)
2nd Aug 2021, 6:05 PM
ጠ Ø λ 千 ₳ ℝ
ጠ Ø λ 千 ₳ ℝ - avatar