- 3

Some one help me out

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. You can iterate over a range and calculate the sum of all numbers in the range. Remember, range(a, b) does not include b, thus you need to use b+1 to include b in the range. N = int(input()) #your code goes here N = range(a,b) sum = 0 for x in range("a","b"): sum +=1 print(sum) This was my code on phthon

16th Apr 2022, 10:00 PM
Joseph Oyelami
10 Answers
+ 3
N=int(input()) print((N+1)*N//2)
17th Apr 2022, 6:52 AM
Ajit Kumar
Ajit Kumar - avatar
+ 1
Please tag the relevant programming language and link your code attempt
16th Apr 2022, 10:02 PM
Lisa
Lisa - avatar
+ 1
N = int(input()) #your code goes here sum = 0 for x in range(0,N+1): sum +=x print(sum)
17th Apr 2022, 4:16 AM
sangwon Lee
+ 1
N = int(input()) #your code goes here R = range(0 , N) print (sum(R)+N)
17th Sep 2022, 1:30 PM
Godwin Emerald
Godwin Emerald - avatar
0
Lisa how do i link my code attempt and example of a relevant programing language in details
16th Apr 2022, 10:21 PM
Joseph Oyelami
0
Copy your code. Then go to Code section, click +, select Python, insert Code, save. Then come back to the thread, click +, Insert Code, sort for My Code Bits, select your code
16th Apr 2022, 10:25 PM
Lisa
Lisa - avatar
0
* do not over-write the value of N * range(a,b) is only an example – you need to put your actual N there
16th Apr 2022, 10:27 PM
Lisa
Lisa - avatar
0
This is the answer for your problem
16th Apr 2022, 10:29 PM
Pablo PC
Pablo PC - avatar
0
If you dont want to use a loop you can directly calculate the sum by n(n+1)/2 this gives us the sum of first 'n' natural numbers
17th Apr 2022, 8:12 PM
HARISH
HARISH - avatar
16th Apr 2022, 10:29 PM
Pablo PC
Pablo PC - avatar