Sum of Consecutive Numbers | Sololearn: Learn to code for FREE!


Sum of Consecutive Numbers

What's the purpose "N" in this assignment? N = int(input()) sum = 0 #your code goes here for i in range (1, N + 1): sum += i print(sum)

4/11/2021 4:15:16 PM


8 Answers

New Answer


N is the input


Try thisπŸ‘‡πŸ‘‡ N = int(input()) print(N*(N+1)//2)


N=int(input()) n = sum(range(N+1)) print(n)


N=int(input()) n = sum(range(N+1)) print(n) Or N = int(input()) print(N*(N+1)//2) πŸ‘†πŸ‘† Both works perfectly πŸ‘πŸ»


N = int(input()) #your code goes here sum = 0 for number in range(N+1): sum = sum + number print(sum)


N is the name of input variable which stores a value inside it.


Mutiat Akobi what does n+1 mean in this code? πŸ€”does this mean: count from zero to one more than the input? and what is function sum() doing here?


Mutiat Akobi N is a variable that has a value of what the user inputs and n +1 means for every input add one simple as that