WSQ05

--Originally published at Site Title

ON TO FUNCTIONS

What to Do:

You will go back and do WSQ01 – Fun with Numbers again.

But this time, write a function for each calculation. Each function should define two parameters (in this example of type int) and return the correct value as an integer as well.

You main program needs to ask the user for the input and then call each function to calculate the answer for each of the parts.

 

Qué hacer:

Volverá a hacer WSQ01 – Diversión con números de nuevo.

Pero esta vez, escriba una función para cada cálculo. Cada función debe definir dos parámetros (en este ejemplo de tipo int) y devolver el valor correcto como un entero también.

El programa principal debe preguntar al usuario por la entrada y luego llamar a cada función para calcular la respuesta para cada una de las partes.

 

Code/Código:

 

5code

 

 

Python:

 

5py

 

 


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