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.
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.
+ 2
Show us your attempt.
+ 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?
0
N = int(input())
x = (list(range(N)))+[N]
print(sum(x))
0
N = int(input())
numbers = sum(list(range(1,N+1))) print(numbers)
Need your thoughts
0
Arinda Mark Alvin sum(list(i for i in range(1, N+1)))
0
Thank you people