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:44] – [Hola Mundo] 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 106: | Line 106: | ||
emacs factorial.py | emacs factorial.py | ||
- | |||
- | # | ||
- | #este programa utiliza recursividad! para calcular el factorial! | ||
- | |||
- | def factorial(n): | ||
- | if n==0: | ||
- | reutrn 1 #factorial de 0 es 1. 0!=1 | ||
- | |||
- | else: | ||
- | 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.1473810246.txt.gz · Last modified: 2022/09/20 00:08 (external edit)