+ 21

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)

11th Apr 2021, 4:15 PM
Tasnas123
Tasnas123 - avatar
8 Respuestas
+ 5
N is the input
11th Apr 2021, 4:16 PM
shirja Beevi
shirja Beevi - avatar
+ 15
Try this👇👇 N = int(input()) print(N*(N+1)//2)
29th Apr 2021, 1:30 PM
Jackson Kairani Maina
Jackson Kairani Maina - avatar
+ 5
N=int(input()) n = sum(range(N+1)) print(n)
1st Sep 2021, 3:19 PM
Mutiat Akobi
Mutiat Akobi - avatar
+ 4
N=int(input()) n = sum(range(N+1)) print(n) Or N = int(input()) print(N*(N+1)//2) 👆👆 Both works perfectly 👍🏻
4th Oct 2021, 4:13 PM
Isha
+ 2
N = int(input()) #your code goes here sum = 0 for number in range(N+1): sum = sum + number print(sum)
15th Oct 2021, 1:56 PM
Wisjnu Judho
Wisjnu Judho - avatar
+ 1
N is the name of input variable which stores a value inside it.
12th Apr 2021, 5:07 AM
A J
A J - avatar
0
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?
12th Sep 2021, 12:09 PM
Atena Molaie
0
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
21st Jan 2022, 10:04 AM
Jackson Kairani Maina
Jackson Kairani Maina - avatar