WSQ04

--Originally published at Site Title

SUM OF NUMBERS

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?

 

Qué hacer:

Escriba un programa que solicite un rango de números enteros y luego imprime la suma de los números en ese rango (inclusive).

Puedes usar una fórmula para calcular esto por supuesto pero lo que queremos que hagas aquí es practicar usando un bucle para hacer un trabajo repetitivo.

Por ejemplo, la suma de 6 a 10 sería 0 + 6 + 7 + 8 + 9 + 10.

Observe que nuestra suma comienza con cero (¿por qué?) Y luego agregamos cada número en el rango proporcionado por el usuario. Sólo por diversión, ¿cuál es la fórmula matemática para hacer este cálculo?

 

Code/Código:

 

sumacode

 

Python:

 

sumapy