forked from davidbcaro/curso_Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5227fb2
Showing
155 changed files
with
2,383 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import this |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
print ("Hola mundo en Python 🐍") | ||
print ("Hola mundo en Python") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
''' | ||
Una variable es un espacio en memoria que puede almacenar algún tipo de dato: | ||
Número | ||
Coma flotante | ||
Texto | ||
Booleano: Falso o Verdadero | ||
Además vamos a aprender el tipado dinámico. | ||
''' | ||
# Declaramos e imprimimos una variable de tipo numero y su tipo | ||
numero = 10 | ||
print(numero) | ||
print(type(numero)) | ||
print("-------------") | ||
# Declaramos e imprimimos una variable y su tipo | ||
numero_flotante = 10.25 | ||
print(numero_flotante) | ||
print(type(numero_flotante)) | ||
print("-------------") | ||
texto = "Hola mundo en Python 🐍" | ||
print (texto) | ||
print(type(texto)) | ||
print("-------------") | ||
booleano = True | ||
print (booleano) | ||
print(type(booleano)) | ||
print("-------------") | ||
suma = numero + numero_flotante | ||
print(suma) | ||
print(type(suma)) | ||
print("-------------") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
num1 = 5 | ||
num2 = 3 | ||
# Operador suma | ||
resultado = num1+num2 | ||
print("La suma es: ", resultado) | ||
# Operador resta | ||
resultado = num1-num2 | ||
print("La resta es: ", resultado) | ||
# Operador multiplicación | ||
resultado = num1*num2 | ||
print("La multiplicación es: ", resultado) | ||
# Operador división | ||
resultado = num1/num2 | ||
print("La división es: ", resultado) | ||
# Operador división parte entera | ||
resultado = num1//num2 | ||
print("La división entera es: ", resultado) | ||
# Operador módulo | ||
resultado = num1 % num2 | ||
print("El modulo es: ", resultado) | ||
# Operador exponente | ||
resultado = num1**num2 | ||
print("El exponente es: ",resultado) | ||
# Operación | ||
resultado=3**3*(13/(5*8)) | ||
# resultado = 3**3*(20.8) | ||
#r1 = ((13/5)*8) | ||
#r2 = 3**3*20.8 | ||
# 3**3*0.325 | ||
# 27*0.325 = 8.75 | ||
|
||
# 3**3*20.8 | ||
# 561.6 | ||
|
||
|
||
#print("El resultado es: ",r1) | ||
#print("El resultado es: ",r2) | ||
print("El resultado es: ",resultado) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
num1 = 10 | ||
num2 = 20 | ||
num3 = 30 | ||
resultado = num1<num2 | ||
print(num1, "es < que ", num2, ":", resultado) | ||
# 10 es < que 20: True | ||
resultado = num1>num2 | ||
print(num1, "es > que ", num2, ":", resultado) | ||
# 10 es > que 20: False | ||
resultado = num1==num2 | ||
print(num1, "es == que ",num2, ":", resultado) | ||
# 10 es = que 20: Flase | ||
resultado = num1<=num2 | ||
print(num1, "es <= que ",num2, ":", resultado) | ||
# 10 es <= 20: True | ||
resultado = num1>=num2 | ||
print(num1, "es >= que ", num2, ":", resultado) | ||
# 10 es >= 20: Flase | ||
resultado = num1!=num2 | ||
print(num1, "es != que ", num2, ":", resultado) | ||
# 10 es >= 20: True | ||
resultado = num1+num2==num3 | ||
print(num1+num2, "es == que ", num3,":", resultado) | ||
# 30 es == que 30: True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
''' | ||
AND | ||
0 0 = 0 | ||
1 0 = 0 | ||
0 1 = 0 | ||
1 1 = 1 | ||
OR | ||
0 0 = 0 | ||
1 0 = 1 | ||
0 1 = 1 | ||
1 1 = 1 | ||
NOT | ||
0 = 1 | ||
1 = 0 | ||
''' | ||
imc = 26 | ||
if imc > 19.9 or imc <= 25: | ||
print("Su peso es normal") | ||
|
||
a = 10 | ||
b = 15 | ||
c = 20 | ||
resultado = ((a<b) and (b<c)) | ||
print(a<b , " and ", b<c," : ", resultado) | ||
# True and True | ||
# resultado = True | ||
resultado = ((a>b) and (b<c)) | ||
print(a>b, " and ", b<c," : ", resultado) | ||
# Flase and True | ||
# resultado = False | ||
resultado = ((a>b) or (b<c)) | ||
print(a>b, " or ", b<c, " : ", resultado) | ||
# False or True | ||
# resultado = True | ||
resultado_negado = not resultado | ||
print("Not ", resultado,":", resultado_negado) | ||
# resultado = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
a = 1 | ||
b = 1 | ||
c = 1 | ||
d = 1 | ||
e = 1 | ||
f = 1 | ||
#a=a+1 a+=1 | ||
a += 1 | ||
print("a+=1=", a) | ||
b -= 1 | ||
print("b-=1=", b) | ||
c *= 1 | ||
print("c*=1=", c) | ||
d /= 1 | ||
print("d/=1=", d) | ||
e **= 1 | ||
print("e**=1=", e) | ||
f %= 1 | ||
print("f%=1=", f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
nombre = "Elon" | ||
edad = 30 | ||
print ("Hola tu nombre es", nombre, " y tu edad es", edad) | ||
#print("Hola tu nombre es {0} y tu edad es {1:10.3f} adios {0}".format(nombre,edad)) | ||
print(f"Hola tu nombre es {nombre} y tu edad {edad:2.0f} años. ¡Hasta la próxima {nombre}!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
nombre = input("Ingresa tu nombre: ") | ||
edad = int(input("Ingresa tu edad: ")) | ||
print(f"Tu nombre es: {nombre} y tu edad es de {edad} años") | ||
dias = edad*365 | ||
print(f"Hace {dias:,} dias que naciste") | ||
|
||
# Ejercicios del 1 al 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
''' | ||
bin() | ||
hex() | ||
abs() | ||
round() | ||
pow() | ||
''' | ||
import math | ||
|
||
valor = bin(10) | ||
print("El número en binario es: ",valor) | ||
|
||
valor = int('0b1010',2) | ||
print("El número en entero es: ",valor) | ||
|
||
valor = hex(10) | ||
print('El número en hexadecimal es: ',valor) | ||
|
||
valor = int('0xa',16) | ||
print("El número entero es: ",valor) | ||
|
||
valor = abs(-5) | ||
print("El valor absoluto es: ",valor) | ||
|
||
valor = round(6.6) | ||
print("El número redondeado es: ",valor) | ||
|
||
valor = pow(81, 0.5) | ||
print("El valor de potencia es: ",valor) | ||
|
||
# Librería math | ||
valor = math.sqrt(2) | ||
print("El valor de raíz cuadrada es: ",valor) | ||
|
||
valor = math.pi | ||
print("El valor de pi es: ", valor) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
numero = float(input("Ingresa un número entero positivo: ")) | ||
|
||
if numero < 0: | ||
print("Incorrecto, por favor ingresa un número válido") | ||
elif numero == 0: | ||
print("El número ingresado es cero") | ||
else: | ||
print("Correcto, el número", numero, "es positivo") | ||
print("Fin del condicional") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
edad = int(input("Ingresa tu edad:")) | ||
#if edad >= 0 and edad < 100: | ||
#if 0 <= edad < 120: | ||
if edad >= 0 and edad <= 150: | ||
if edad >= 18: | ||
print("El es mayor de edad", edad) | ||
else: | ||
print("El es menor de edad", edad) | ||
else: | ||
print("Edad incorrecta") | ||
|
||
# Ejercicios del 6 al 12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
''' | ||
Primer elemento | ||
Último elemento | ||
Un elemento que no está en la lista. | ||
Rango del primero al tercero. | ||
Rango del tercero al último. | ||
''' | ||
lista = ["Enero", "Febrero", "Marzo", "Abril", 1, 2, 3.33, [4, 5, 6]] | ||
print(lista) | ||
print(lista[1]) | ||
# print("Primer elemento:", lista[0]) | ||
# print("Tercer elemento:", lista[2]) | ||
# print("Último elemento:", lista[-1]) | ||
# #print("Un elemento que no está en la lista:",lista[9]) | ||
# print("Rango del primero al tercero:", lista[:3]) | ||
# print("Rango del tercero al último:", lista[3:]) | ||
# print("Imprimir desde el último elemento al primero", lista[::-1]) | ||
# lista[3] = "Noviembre" | ||
# print(lista) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
lista = [1, 1, 2, 3] | ||
#lista[0] = "Enero" | ||
print(lista) | ||
print("len(lista)=", len(lista)) | ||
lista.append(4) | ||
print("list.append(4)=", lista) | ||
lista.insert(0,0) | ||
print("list.insert(0,0)=", lista) | ||
lista.extend([5, 6, 7]) | ||
print("list.extend([5,6,7])=", lista) # [0, 1, 1, 2, 3, 4, 5, 6, 7] | ||
lista += [8,9,10] | ||
print("list+=[8,9,10]=", lista) | ||
num = 5 | ||
if num in lista: | ||
print(f"El numero {num} si esta en la lista") | ||
else: | ||
print(f"El numero {num} no esta en la lista") | ||
print("lista.index(5)=", lista.index(5)) | ||
print("lista.count(1)=", lista.count(1)) | ||
i = 3 | ||
lista.pop(i) | ||
print("lista.pop(0)=", lista) | ||
lista.remove(5) | ||
print("lista.remove(5)=", lista) | ||
lista.reverse() | ||
print("lista.reverse()=", lista) | ||
lista.sort() | ||
print("lista.sort()=", lista) | ||
lista.clear() | ||
print("lista.clear()=", lista) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
tupla = (1, 2, 3, "Hola", "mundo") | ||
#tupla.append(5) | ||
#tupla[1] = 5 | ||
print(tupla) | ||
print("tupla[1]=", tupla[1]) | ||
print("tupla[0:3]=", tupla[0:3]) | ||
print("3 in tupla=", 3 in tupla) | ||
print("tupla.index(0)=", tupla.index("Hola")) | ||
print("tupla.count(0)=", tupla.count(1)) | ||
print("len(tupla)=", len(tupla)) | ||
|
||
lista = list(tupla) | ||
print(lista) | ||
tupla2 = tuple(lista) | ||
print(tupla2) | ||
# Tuplas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
conjuntos = set() | ||
conjuntos = {1, 2, 3, "Hola", "mundo", 1, 2, 3} | ||
print(conjuntos) | ||
#conjuntos.append(5) | ||
conjuntos.add(5) | ||
print(conjuntos) | ||
print("3 in conjuntos=", 3 in conjuntos) | ||
conjuntos.discard(1) | ||
print("conjuntos.discard(1)=", conjuntos) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#set es una colección sin orden y sin índices, no permite elementos repetidos | ||
#y los elementos no se pueden modificar, pero si agregar nuevos o eliminar | ||
planetas = { | ||
"Marte", | ||
"Júpiter", | ||
"Venus" | ||
} | ||
print(planetas) | ||
#longitud | ||
print(len(planetas)) | ||
#revisar si un elemento está presente | ||
print("Marte" in planetas) | ||
#agregar | ||
planetas.add("Tierra") | ||
print(planetas) | ||
planetas.add("Tierra")#no se pueden agregar elementos duplicados | ||
print(planetas) | ||
#eliminar con remove posiblemente arroja excepción | ||
planetas.remove("Tierra") | ||
print(planetas) | ||
#descarta con discard no arroja excepción | ||
planetas.discard("Júpiter") | ||
print(planetas) | ||
#limpiar el set | ||
planetas.clear() | ||
print(planetas) | ||
#eliminar el set | ||
del planetas | ||
#print(planetas) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
a = {1, 2, 3, 4} | ||
b = {4, 5, 6, 7} | ||
d = {1, 2, 3, 4, 5, 6} | ||
e = {11, 12, 13, 14, 15, 16} | ||
print("a==b:", a==b) | ||
c = a|b | ||
print("c=a|b=", c) | ||
c = a&b | ||
print("c=a&b=", c) | ||
c = a-b | ||
print("c=a-b=", c) | ||
c = a^b | ||
print("c=a^b=", c) | ||
print("a.issubset(d)=", a.issubset(d)) | ||
print("d.issubset(a)=", d.issubset(a)) | ||
print("d.issubset(a)=", d.issuperset(a)) | ||
print("a.isdisjoint(e)=", a.isdisjoint(e)) | ||
f = frozenset({1, 2, 3}) | ||
#f.add(2) |
Oops, something went wrong.