Skip to content

Commit

Permalink
Spanish Translation and solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignacio Avas committed May 4, 2017
1 parent 7e12291 commit 80d9edc
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 16 deletions.
74 changes: 69 additions & 5 deletions py101/modules/README.es.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,78 @@
Boilerplate
-----------
Módulos
-------

Insertar alguna introducción aquí.
Python ofrece una manera de incluir definiciones en un archivo y usarlos
desde otro script. Tal archivo es llamado un módulo. Las definiciones de un
módulo pueden ser importado en otros módulos o al programa principal. El
nombre del archivo es el nombre del módulo más la extensión ".py". Por
ejemplo suponiendo que existe un archivo en la carpeta actual con el
siguiente contenido:

.. sourcecode:: python

print('Some python code here')
# Cuenta cuantos números de fibonacci son menores que n
def how_many_fib(n):
a = 0
b = 1
result = 0
while b < n:
temp = a
a = b
b = temp + b
result = result + 1
return result

def say_hello():
print("Di mi nombre")

En otros archivos mymodule puede ser importado usando la siguiente sintaxis:

.. sourcecode:: python

import mymodule
print(mymodule.how_many_fib(1000) # prints 16

Módulos Estándar
----------------

Python viene con una biblioteca de módulos estándar, llamada "Python Library
Reference". Algunos módulos ya están provistos en el intérprete, que proveen
acceso a operaciones que no son parte del núcleo del lenguaje pero sin
embargo están incluidas, ya sea por eficiencia o para proveer acceso a
operaciones primitivas del sistema operativo, como las llamadas al sistema
("system calls").

Dos funciones muy importante a la hora de explorar módulos en Python son
"dir" y "help". La primera permite saber qué funciones están implementadas
en un módulo. Si se necesita ayuda, se puede utilizar la función "help" que
muestra un texto acerca de cierta función específica.


.. sourcecode:: python

import http
dir(http)
# imprime [ 'HTTPStatus','IntEnum','__all__','__builtins__','__cached__',
# '__doc__','__file__','__loader__','__name__','__package__','__path__',
# '__spec__']

help(http.HTTPStatus)
# Muestra una descripión larga de ese campo


Escribiendo un módulo
---------------------

Para crear un módulo, simplemente hay que crear un archivo .py con el nombre
del módulo y luego importándolo usando el nombre de archivo usando el
comando import.

Desafío
-------

Describir el desafío aquí.
Crea un módulo llamado "numbers" que defina una función tangent() que
compute la tangente usando las funciones "sin" (seno) y "cos" (coseno) desde
la biblioteca estándar "math", y luego un programa que imprima el valor de
tangent(1) desde el módulo numbers. El progama debería imprimir una línea
"1.557407724654902"

16 changes: 6 additions & 10 deletions py101/modules/README.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
Modules
-----------
-------

Python has a way to put definitions in a file and use them in another script.
Such a file is called a module. Definitions from a module can be imported into
other modules or into the main program file.

A module is a file containing Python definitions and statements. The file name
is the module name with the suffix .py appended. Within a module, the module’s
name (as a string) is available as the value of the global variable __name__.
For instance, supposing there is file called mymodule.py in the current
directory with the following contents:
other modules or into the main program file. The file name is the module
name with the suffix .py appended. For instance, supposing there is file
called mymodule.py in the current directory with the following contents:

.. sourcecode:: python

Expand Down Expand Up @@ -45,7 +41,7 @@ built in, either for efficiency or to provide access to operating system
primitives such as system call.

Two very important functions come in handy when exploring modules in
Python: the "dir"and "help" functions. One can look for which functions are
Python: the "dir" and "help" functions. One can look for which functions are
implemented in each module by using the "dir" function. If help is needed,
then the "help" function may be used.

Expand Down Expand Up @@ -74,5 +70,5 @@ Challenge
Create a module called "numbers" that defines a tangent() function that
computes the tangent using the functions "sin" and "cos" from the standard math
library, and then a program that prints the value of tangent(1) from the
numbers library. The program should print one line "1.557407724654902"
numbers module. The program should print one line "1.557407724654902"

16 changes: 15 additions & 1 deletion py101/modules/SOLUTION.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
numbers.py

.. sourcecode:: python

import math

def tangent(x):
return math.sin(x) / math.cos(x)


main.py

.. sourcecode:: python

print('Some solution here')
import numbers

print(numbers.tangent(1))

0 comments on commit 80d9edc

Please sign in to comment.