WSQ10

--Originally published at Site Title

Background

In this assignment you will write a function to calculate the square root of a number using the Babylonian method. You can search for that method, it will be easy to find.

What to Do

The function should receive a number and return floating point number. Obviously you should test your function, so create a main program that asks the user a value, calculates the square root and displays that.

 

Code/Código:

codebab

 

Python:

pybab


WSQ09

--Originally published at Site Title

So for this assignment I would like to see you create a function that receives as parameter the name of a file (this would be a string value like data.txt) and your function counts the number of lines and the number of characters in the file which it returns as a single value (but with two values). You will want to look at how to use and return a tuple from a function and how to open and read text files line by line.

 

Code/Código:

codetxt

Text/Texto:

pruebatxt

 

Python:

txtpy


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

 

 


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

 

 


WSQ03

--Originally published at Site Title

PICK A NUMBER

What to Do:

Write a program that picks a random integer in the range of 1 to 100.

There are different ways to make that happen, you choose which one works best for you.

It then prompts the user for a guess of the value, with hints of ’too high’ or ’too low’ from the program.

The program continues to run until the user guesses the integer. You could do something extra here including telling there user how many guesses they had to make to get the right answer.

You might want to check that your program doesn’t always use the same random number is chosen and you should also split your problem solving into parts. Perhaps only generate the random number and print that as a first step.

 

Qué hacer:

Escriba un programa que elija un número entero aleatorio en el rango de 1 a 100.

Hay diferentes maneras de hacer que suceda, usted elige cuál funciona mejor para usted.

A continuación, solicita al usuario una estimación del valor, con indicaciones de ‘demasiado alto’ o ‘demasiado bajo’ del programa.

El programa continúa funcionando hasta que el usuario adivina el entero. Usted podría hacer algo adicional aquí incluyendo decir allí al usuario cuántas conjeturas tuvieron que hacer para conseguir la respuesta correcta.

Es posible que desee comprobar que su programa no siempre utiliza el mismo número aleatorio es elegido y también debe dividir su resolución de problemas en partes. Tal vez sólo generar el número aleatorio e imprimir que como un primer paso.

 

Code/Código:

randomcode

 

Python:

randompy

 


WSQ02

--Originally published at Site Title

TEMPERATURE

What to Do:

Write a program that will prompt the user for a temperature in Fahrenheit and then convert it to Celsius. You may recall that the formula is C = 5 ∗ (F − 32)/9.

 

Qué hacer:

Escriba un programa que le pedirá al usuario una temperatura en Fahrenheit y luego lo convertirá en Celsius. Puede recordar que la fórmula es C = 5 * (F – 32) / 9.

 

Code/Código:

tempcode

 

Python:

tempy

 

 

 


WSQ-01

--Originally published at Site Title

Fun with numbers

What to Do

Ask the user for two integer values, then use those two values to calculate and show the following:

  • The sum of the two numbers.
  • The difference of the two numbers.
  • The product of the two numbers.
  • The integer based division of the two numbers (so no decimal point). First divided by second.
  • The remainder of integer division of the two numbers.

 

 Qué hacer:

Pida al usuario dos valores enteros, luego,  use esos dos valores para calcular y mostrar lo siguiente:

  • La suma de los dos números.
  • La diferencia de los dos números.
    El producto de los dos números.
  • La división basada en enteros de los dos números (no hay punto decimal). Primero dividido por segundo.
  • El resto de la división entera de los dos números.

 

 

Code/Código:

code

 

Python:

py

 

 

 

 

 


Tuplas y listas en Python

--Originally published at Site Title

En Python podemos crear listas y tuplas. Una lista no es lo mismo que una tupla. Ambas son un conjunto ordenado de valores, en donde este último puede ser cualquier objeto: un número, una cadena, una función, una clase, una instancia, etc. La diferencia es que las listas presentan una serie de funciones adicionales que permiten un amplio manejo de los valores que contienen. Basándonos en esta definición, puede decirse que las listas son dinámicas, mientras que las tuplas son estáticas.

Para crear una una lista usamos “[]”:

lista

listapy

Para crear una lista usamos “{}”:

tupla

tuplapy

 

Fuente: http://recursospython.com/guias-y-manuales/listas-y-tuplas/