- 1

# Whats wrong with this code?

N = int(input()) sum = 0 for sum in range(0,N+1): print(sum)

6 Answers

- 1

N = int(input())
sum = 0
i=0
for i in range(N+1):
sum = i+sum
print(sum)

+ 3

Can u please tell that whats ur desired output.
As while running this code runs without an error.

+ 2

Here's a O(1)
N = int(input())
print((N/2)*(N+1))

+ 1

You aren't adding the numbers together in the loop and then output the total after the loop, but just outputting each number in the range.
Note: you shouldn't use 'sum' as a variable name, as it will overwrite the built-in sum() functions name.

0

Take a number N as input and output the sum of all numbers from 1 to N (including N).
Sample Input
100
Sample Output
5050

0

print(sum(range(int(input()) + 1)))