Writing /var/lib/dokuwiki/data/meta/tutorials/guia_python.meta failed
tutorials:guia_python
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorials:guia_python [2016/09/13 23:29] – [Ejercicios extras:] dgarcia | tutorials:guia_python [2022/09/20 00:08] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 2: | Line 2: | ||
Guía para aprender conceptos básicos de programación junto al lenguaje de programación Python. | Guía para aprender conceptos básicos de programación junto al lenguaje de programación Python. | ||
- | Ejercicios tomados de [[http:// | + | Ejercicios tomados de [[http:// |
Para conocer algunos conceptos básicos previos, puede visitar: [[https:// | Para conocer algunos conceptos básicos previos, puede visitar: [[https:// | ||
===== Ejercicios sugeridos: ===== | ===== Ejercicios sugeridos: ===== | ||
- | - [[http:// | + | - [[http:// |
- | - [[http:// | + | - [[http:// |
- | - [[http:// | + | - [[http:// |
- | - [[http:// | + | - [[http:// |
- | - [[http:// | + | - [[http:// |
- | - [[http:// | + | - [[http:// |
- | - [[http:// | + | - [[http:// |
- | - [[http:// | + | - [[http:// |
- | - [[http:// | + | - [[http:// |
- | - [[http:// | + | - [[http:// |
- | - [[http:// | + | - [[http:// |
- | - [[http:// | + | - [[http:// |
- | - [[http:// | + | - [[http:// |
- | - [[http:// | + | - [[http:// |
- | - [[http:// | + | - [[http:// |
- | - [[http:// | + | - [[http:// |
- | - [[http:// | + | - [[http:// |
- | - [[http:// | + | - [[http:// |
- | - [[http:// | + | - [[http:// |
===== Ejercicios extras: ===== | ===== Ejercicios extras: ===== | ||
- | * [[http:// | + | * [[http:// |
- | * [[http:// | + | * [[http:// |
- | * [[http:// | + | * [[http:// |
===== Algunos Conceptos ===== | ===== Algunos Conceptos ===== | ||
Line 37: | Line 37: | ||
=====Temas===== | =====Temas===== | ||
- | 1- Hola mundo | + | * Hola mundo |
- | 2- Variable e imprimir | + | |
- | 3- Funcion | + | |
- | 4- Clase | + | |
- | 5- Import | + | |
Line 60: | Line 60: | ||
exit() | exit() | ||
+ | |||
+ | Vamos a clonar el material con el que se va a estar trabajando. | ||
+ | |||
+ | git clone https:// | ||
+ | |||
+ | ==== Loops, variables, listas==== | ||
Vamos a crear el primer programa en python. Vaya al directorio donde | Vamos a crear el primer programa en python. Vaya al directorio donde | ||
Line 69: | Line 75: | ||
# | # | ||
- | |||
#imprimir los primeros 100 terminos no triviales de la | #imprimir los primeros 100 terminos no triviales de la | ||
#serie de Fibonacci | #serie de Fibonacci | ||
- | |||
def main(): | def main(): | ||
#creamos la variable inicial | #creamos la variable inicial | ||
finonacci_last=1 | finonacci_last=1 | ||
fibonacci_last_last=1 | fibonacci_last_last=1 | ||
- | |||
for i in range(100): | for i in range(100): | ||
#creamos el nuevo termino de laserie | #creamos el nuevo termino de laserie | ||
fibonacci_current=fibonacci_last+fibonacci_last_last | fibonacci_current=fibonacci_last+fibonacci_last_last | ||
- | |||
#hacemos update de los ' | #hacemos update de los ' | ||
fibonacci_last=fibonacci_current | fibonacci_last=fibonacci_current | ||
fibonacci_last_last=fibonacci_last | fibonacci_last_last=fibonacci_last | ||
- | |||
#imprimir el resultado | #imprimir el resultado | ||
print fibonacci_current | print fibonacci_current | ||
- | |||
if __name__==" | if __name__==" | ||
| | ||
- | ejecute | + | Ejecute |
python fibonacci.py | python fibonacci.py | ||
- | Ahora vamos a trabajar con funciones. Recursividad! | + | Como reto. Escriba el programa de manera que se pueda guardar cada término de la serie en una lista. |
- | emacs factorial.py | + | ====Funciones==== |
- | # | ||
- | #este programa utiliza recursividad! para calcular el factorial! | ||
- | def factorial(n): | + | Ahora vamos a trabajar con funciones. Recursividad! |
- | if n==0: | + | |
- | reutrn 1 #factorial de 0 es 1. 0!=1 | + | |
- | else: | + | emacs factorial.py |
- | return n*factorial(n-1) # n!= n*(n-1)! | + | |
- | def main(): | ||
- | #le solicitamos al usuario un numero al cual calcular el factorial | ||
- | print " | ||
- | number=int(raw_input()) | ||
- | |||
- | #calculamos el factorial | ||
- | print str(factorial(number)) | ||
- | |||
- | if __name__==" | ||
- | main() | ||
Ahora vamos a crear nuestra primera clase | Ahora vamos a crear nuestra primera clase | ||
- | |||
- | # | ||
- | #En este programa creamos una clase | ||
- | #Numeros complejos | ||
- | |||
- | class complex(object): | ||
- | def __init__(self, | ||
- | #0 es el numero pro defecto | ||
- | self.real = real_input | ||
- | self.img | ||
- | |||
- | def get_real_part(self): | ||
- | return self.real | ||
- | |||
- | def get_imaginary_part(self): | ||
- | return self.img | ||
- | |||
- | def get_magnitude(self): | ||
- | return self.real**2+self.img**2 | ||
- | |||
- | def __add__ (self, other): | ||
- | #se suman self, y other. Ambos complejos | ||
- | #se reurna un nuevo complejo con el resultado | ||
- | real_result=self.real+other.get_real_part() | ||
- | img_result=self.img+other.get_imaginary_part() | ||
- | |||
- | return complex(real_result, | ||
Vamos a utilizar nuestra clase. Corramos python | Vamos a utilizar nuestra clase. Corramos python |
tutorials/guia_python.1473809357.txt.gz · Last modified: 2022/09/20 00:08 (external edit)