+ 1

What's wrong?

No one likes homework, but your math teacher has given you an assignment to find the sum of the first N numbers. Let’s save some time by creating a program to do the calculation for you! 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 Explanation: The sum of all numbers from 1 to 100 is equal to 5050. Solution: N = int(input()) sum=0 for i in range(1,N+1,1): sum+=i print(sum)

7th Oct 2021, 3:57 PM
Valeriia Esaulenko
2 Respuestas
0
N = int(input()) sum=0 for i in range(1, N+1): sum+=i print(sum)
7th Oct 2021, 4:05 PM
zexu knub
zexu knub - avatar
+ 1
sum = (n*(n+1)/2) 🙄
8th Oct 2021, 12:02 AM
Amine Laaboudi
Amine Laaboudi - avatar