Help the python | Sololearn: Learn to code for FREE!

-2

Help the python

Wach the code?? 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.

2/28/2021 11:59:42 PM

Ilyass Nafi

33 Answers

New Answer

+27

N=100 sum=0 for i in range(1, N+1): sum+=i print(sum) If we input 100 the result is 5050

+18

Ilyass Nafi Try this: N = int(input()) #your code goes here num_list = list(range(N+1)) print(sum(num_list))

+9

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

+7

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

+4

https://www.sololearn.com/Discuss/2710522/?ref=app

+4

print(n*(n+1)/2)

+2

print(sum([x for x in range(N+1)]))

+2

N = int(input()) the_sum= sum(list(range(N+1))) print(the_sum)  consider this story about the mathematician Carl Friedrich Gauss. When Gauss was a boy, a teacher wanted to give the class some busywork. The teacher told them to add up all the numbers from 0 to 100. Young Gauss came up with a clever trick to figure out the answer in a few seconds, but you can write a Python program with a for loop to do this calculation for you.  total = 0  for num in range(101):      total = total + num  print(total) (Young Gauss figured out a way to solve the problem in seconds. There are 50 pairs of numbers that add up to 101: 1 + 100, 2 + 99, 3 + 98, and so on, until 50 + 51. Since 50 × 101 is 5,050, the sum of all the numbers from 0 to 100 is 5,050. Clever kid!)

+2

Andrew Malenga You should post your problem in Q&A Section. And show your attempts.

+1

https://www.dynamiccoding.tech/python-iterative-structure-python-loops/ Check out this blog so you will understand the working of range function and also get where do we add 100

+1

num = int(input()) nums = list(x for x in range(1, num+1)) print(sum(nums))

+1

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

+1

# You are given N = int(input()) #your code goes here Total = 0 for x in range(1,N+1) Total+=x print(Total)

+1

num_list = list(range(N+1)) print(sum(num_list))

+1

Try this N=int(input()) Print(int(N*(N+1)/(2)))

0

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

0

num = int(input()) nums = list(x for x in range(1, num+1)) print(sum(nums))

0

N = int(input()) #your code goes here print(N*(N+1)//2)

0

sum = 0 for num in range(100): sum += num+1 print(sum)

0

#your code goes here