0

I really have no clue about the rest of all this program. Please need help on consecutive numbers (SOLVED)

Find sum of the first N numbers. Take numbers N as input and output the sum of all numbers from 1 to N(including N) SAMPLE INPUT 100 SAMPLE OUTPUT 5050 EXPLANATION : The sum of all numbers from 1 to 100 is 5050.

31st Aug 2021, 4:54 PM
McAlvin
McAlvin - avatar
7 Answers
+ 1
To understand better write it like this :- N = int(input()) numbers = sum(range(N+1)) print(numbers) Here, the range() function returns a consecutive sequence of numbers, starting from 0 by default, and increments by 1 (by default), and stops BEFORE a specified number(N). write (N+1) to include the number aswell. and the sum() function is adding up all the elements of the object returned by range() function.
31st Aug 2021, 5:23 PM
CodeSmith
CodeSmith - avatar
+ 2
Show us your attempt.
31st Aug 2021, 4:56 PM
CodeSmith
CodeSmith - avatar
+ 2
N = int(input()) numbers = sum(list(range(1,N+1))) print(numbers) Need your thoughts ☝ you attempt,this one is correct !! What's the problem?
31st Aug 2021, 5:21 PM
Myo Thuzar
Myo Thuzar - avatar
0
N = int(input()) x = (list(range(N)))+[N] print(sum(x))
31st Aug 2021, 5:07 PM
McAlvin
McAlvin - avatar
0
N = int(input()) numbers = sum(list(range(1,N+1))) print(numbers) Need your thoughts
31st Aug 2021, 5:14 PM
McAlvin
McAlvin - avatar
0
Arinda Mark Alvin sum(list(i for i in range(1, N+1)))
31st Aug 2021, 5:17 PM
Abhay
Abhay - avatar
0
Thank you people
1st Sep 2021, 4:06 AM
McAlvin
McAlvin - avatar