0

Ahh

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. Python I can solve this , help A i still didn’t even right a code , I have no idea, sorry

18th Nov 2021, 8:08 PM
Joudy Ramy
Joudy Ramy - avatar
7 Respostas
+ 3
Joudy Ramy I will give you some hints. 1. You will need an integer input called N. 2. Create a variable called total and assign a value of 0 to it. 2. Create a range() and iterate through it. 3. As you iterate through the range, add the number to your total using the += trick. When you print your total, it will show the sum of all numbers up to N Remember that a range does not include the upper number, so you may need to adjust the range to suit. (+1)
18th Nov 2021, 9:43 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 3
You could approach the problem like this: * get input N and convert it to integer * create a result variable, set it to 0 * use a for loop and the range function to iterate over the numbers from 1 to N * on each iteration, add the current number to the result variable * after the loop: print result variable
18th Nov 2021, 9:40 PM
Lisa
Lisa - avatar
+ 2
Please tag the relevant programming language. If you can solve it, do it. If not, please link your code and explain at which point you are stuck.
18th Nov 2021, 8:11 PM
Lisa
Lisa - avatar
+ 1
hey maybe you could include your code? that way we can see what to help with.
18th Nov 2021, 8:11 PM
Jackson Jameson
Jackson Jameson - avatar
+ 1
Thanks so much everyone , i solved it
19th Nov 2021, 10:43 AM
Joudy Ramy
Joudy Ramy - avatar
+ 1
Great! 👍
19th Nov 2021, 10:44 AM
Lisa
Lisa - avatar
+ 1
Joudy Ramy Well done, great feeling! 🖐😁👍
19th Nov 2021, 10:53 AM
Rik Wittkopp
Rik Wittkopp - avatar