wsq04

--Originally published at Tomas Enciso

This program asks the user for two numbers, those numbers act as a range, this function grabs the two numbers and sums all the numbers between those two numbers including themselves.

Screen Shot 2017-05-04 at 6.25.48 AM.png

Screen Shot 2017-05-04 at 6.26.41 AM

In the first run I used 1 and 2 which the result is 3, and in the second run I used 5 and 10 and the result was 45. for the function I used a counter that kept adding 1 to the number the user inserted and each time that the while loop started again it kept adding to the sum until the lower bound number reached the higher bound.


WSQ-04

--Originally published at Program

Write a program that asks for a range of integers and then prints the sum of the numbers in that range (inclusive).

You can use a formula to calculate this of course but what we want you to do here is practice using a loop to do repetitive work.

For example, the sum from 6 to 10 would be 0 + 6 + 7 + 8 + 9 + 10.


# WSQ04 – Sum of Numbers

--Originally published at マルコ

What to Do

Write a program that asks for a range of integers and then prints the sum of the numbers in that range (inclusive).

You can use a formula to calculate this of course but what we want you to do here is practice using a loop to do repetitive work.

For example, the sum from 6 to 10 would be 0 + 6 + 7 + 8 + 9 + 10.

Notice our sum starts with zero (why?) and then we add each number in the range provided by the user. Just for fun, what is the mathematical formula to do this calculation?

Example Run

We will calculate the sum of integers in the range you provide.
Please give us the lower bound:  1
Please give us the upper bound: 10
The sum from 1 to 10 (inclusive) is: 55

squeares

squeares2

Featured image:

 


Sum of numbers

--Originally published at Programming

In our program we will ask for a range of numbers, and then prints the sum of the numbers. For example, if you introduce 6 as de lower and 10 as the higher, we will print 40. Because 6+7+8+9+10=40.

captura-de-pantalla-2017-02-27-a-las-11-07-22

First we declarate the low and the high input like int, because they will be integer numbers. Then, we declarate the result like cero to start. We need a counter to stop the loop when we raise the higher number. This is the a and we start like low, because we will start in the lower number that the user introduce. We also declarate new like low, because is the number we will be adding and it also going to star in the lower number. Top will be the number where we stop, but it doesn’t come into the loop, that’s the reason why we sum 1, to avoid stop 1 number before we want.

Inside the loop, all we are doing, is adding, incrementing  the counter a to comparate with the top, and also incrementing new to do the sum.

Finally, we print the result with a sentence. It also remember us the original numbers we introduced.


WSQ-04

--Originally published at Site Title

En esta ocasión se nos pide desarrollar un programa que reciba dos términos y calcule la suma de todos los números enteros entre los dos términos anteriormente dados.

Para hacerlo simplemente se piden los términos y se desarrolla un while que se repite hasta que la suma de la primera variable más uno alcance al término dos.

captura-de-pantalla-12

Ejecutado en Python:

captura-de-pantalla-13

Para realizar esta tarea me base en mis conocimientos de programación.


Sum of numbers: loops and conditionals

--Originally published at Python learning

Here I am going to show you a program that sums a range of numbers provided by the user. For this problem I used a loop, and I learned to do so in python from here: http://www.python-course.eu/python3_loops.php 

I also had to use conditionals to make sure the first number the user entered was lower than the second, in order for the program to work correctly. Here is a flowchart explaining how conditionals work:

flowchart_if_else

Which I got from another page that helped me understand both conditionals and loops:

http://www.openbookproject.net/books/bpp4awd/ch04.html

At the end, my program looked like this:

sum

And runned like this:

sum-run