- 1

Whats wrong with this code?

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

7th Apr 2021, 7:32 AM
Sajjad Samiei naserani
Sajjad Samiei naserani - avatar
6 Respuestas
- 1
N = int(input()) sum = 0 i=0 for i in range(N+1): sum = i+sum print(sum)
7th Apr 2021, 7:47 AM
Edgar
+ 3
Can u please tell that whats ur desired output. As while running this code runs without an error.
7th Apr 2021, 7:38 AM
Kǟrɨsɦmǟ ❥
Kǟrɨsɦmǟ ❥ - avatar
+ 2
Here's a O(1) N = int(input()) print((N/2)*(N+1))
7th Apr 2021, 8:03 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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.
7th Apr 2021, 7:46 AM
ChaoticDawg
ChaoticDawg - avatar
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
7th Apr 2021, 7:44 AM
Sajjad Samiei naserani
Sajjad Samiei naserani - avatar
0
print(sum(range(int(input()) + 1)))
7th Apr 2021, 7:52 AM
Per Bratthammar
Per Bratthammar - avatar