Skip to content

Commit 7a99cb2

Browse files
authored
Merge pull request mouredev#6747 from juliand89/main
#1 - Python
2 parents 34d71b8 + 69aa9eb commit 7a99cb2

File tree

2 files changed

+197
-0
lines changed

2 files changed

+197
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#operadores aritmeticos
2+
3+
print(f"Suma: 10 + 3 = {10 + 3}")
4+
print(f"Resta: 10 - 3 = {10 - 3}")
5+
print(f"Multiplicacion: 10 * 3 = {10 * 3}")
6+
print(f"Division: 10 / 3 = {10 / 3:2f}")
7+
print(f"Modulos: 10 % 3 = {10 % 3:2f}")
8+
print(f"Exponenciacion: 10 ** 3 = {10**3}")
9+
print(f"Division entera : 10 // 3 = {10 // 3}")
10+
11+
#Operadores de comparacion
12+
print(f"Igualdad: 2 == 3 = {2==3}")
13+
print(f"Desigualdad 2 != 3 = {2!=3}")
14+
print(f"Mayor que: 2 > 3 = {2>3}")
15+
print(f"Menor que: 2 < 3 = {2<3}")
16+
print(f"Moyor o igual que: 2 >= 3 = {2>=3}")
17+
print(f"Menor o igual que: 2 <= 3 = {2<=3}")
18+
19+
# operadores Logicos
20+
print(f"AND: 10 + 3 == 13 and 5 - 1 == 4 es {10+3 == 13 and 5-1 == 4}")
21+
print(f"OR: 10 + 3 == 13 or 5 - 1 == 5 es {10+3 == 13 or 5-1 == 5}")
22+
print(f"NOT: not 10 + 3 == 13 es {not(10+3 == 13)}")
23+
24+
#operadores de asignacion
25+
number = 89
26+
print(number)
27+
number += 1
28+
print(number)
29+
number -= 2
30+
print(number)
31+
number *= 2
32+
print(number)
33+
number /= 2
34+
print(number)
35+
number %= 2
36+
print(number)
37+
number //= 1
38+
print(number)
39+
number **= 1
40+
print(number)
41+
42+
#operadores de identidad
43+
new_number = number
44+
print(f"IS: new_number is number es {new_number is number}")
45+
print(f"IS NOT: new_number is not number es {new_number is not number}")
46+
47+
#operadores de menbresia
48+
print(f"IN: 'j' in 'julian' = {'j' in 'julian'}")
49+
print(f"NOT IN: 'y' not in 'julian' = {'y' not in 'julian'}")
50+
51+
#Operadores de Bit
52+
a = 10 # 1010
53+
b = 3 # 0011
54+
print(f"AND: 10 & 3 = {10 & 3}") # Establece cada bit en 1 si ambos bits son 1 0010 = 2
55+
print(f"OR: 10 | 3 = {10 | 3}") # Establece cada bit en 1 si uno de los dos bits es 1 1011 = 11
56+
print(f"XOR: 10 ^ 3 = {10 ^ 3}") # Establece cada bit en 1 si solo uno de los dos bits es 1 1001 = 9
57+
58+
#Estructuras de control
59+
60+
# if, elif y else
61+
edad = 15
62+
if edad >= 30:
63+
print("Puede ver la pelicula con descuento")
64+
elif edad >= 18:
65+
print("Puede ver la pelicula")
66+
else:
67+
print("No puede ingresar")
68+
69+
# For
70+
buscar = 4
71+
for numero in range(5):
72+
print(numero)
73+
if numero == buscar:
74+
print (f"Encontre el numero {buscar}")
75+
break
76+
else:
77+
print(f"No encontre el numero {buscar}")
78+
79+
#while
80+
numero = 1
81+
while numero < 10:
82+
print(numero)
83+
numero +=1
84+
# ejercicio
85+
c = 10
86+
while c < 56:
87+
if (c % 2 == 0 and c != 16 and c % 3 != 0):
88+
print(c)
89+
c +=1
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#funciones
2+
3+
4+
# sin parametro
5+
6+
def saludo():
7+
print("Esta es una funcion sin parametros")
8+
saludo()
9+
10+
# con 1 parametro
11+
12+
def nombre(name):
13+
print(f"Hola {name} esta es una funcion con 1 parametro")
14+
nombre("Julian")
15+
16+
17+
# con 2 parametros
18+
19+
def mostrar_mayores(lista,n):
20+
for i in lista:
21+
if i > n:
22+
print(i)
23+
mostrar_mayores([1, 2, 3, 4, 5], 2)
24+
25+
# con retorno
26+
27+
def suma(a,b):
28+
return a + b
29+
print(suma(89,2))
30+
31+
# con valores por defecto
32+
33+
def resta(a=0,b=0,c=0):
34+
print(a+b+c)
35+
resta(10, 5, 2)
36+
resta(3)
37+
38+
# anotacion en funcion
39+
def multiplica_por_3(numero: int):
40+
return numero*3
41+
print(multiplica_por_3(6)) # 18
42+
43+
44+
# Con un número variable de argumentos
45+
def sume(*numeros):
46+
total = 0
47+
for n in numeros:
48+
total += n
49+
return total
50+
sume(1, 3, 5, 4) # 13
51+
52+
# Con un número variable de argumentos con palabra clave
53+
54+
def variable_key_arg_greet(**names):
55+
for key, value in names.items():
56+
print(f"{value} ({key})!")
57+
58+
variable_key_arg_greet(
59+
language="Python",
60+
name="Brais",
61+
alias="MoureDev",
62+
age=36
63+
)
64+
65+
66+
#funcion dentro de funcion
67+
def nombres(nom):
68+
def apellidos(ape):
69+
print(f"su nombre es {nom} {ape}" )
70+
apellidos("salamanca")
71+
nombres("Julian")
72+
73+
74+
# Funciones del lenguaje (built-in)
75+
76+
print(len("MoureDev"))
77+
print(type(36))
78+
print("MoureDev".upper())
79+
80+
# Variables locales y global
81+
82+
global_1 = "Python"
83+
print(global_1)
84+
85+
def hello_python():
86+
local_1 = "Hola"
87+
print(f"{local_1} {global_1}")
88+
print(global_1)
89+
#print(local_1) da error porque esta definida de forma local en la funcion
90+
hello_python()
91+
92+
#Ejercicio
93+
94+
def extra(cadena1,cadena2):
95+
count = 0
96+
for i in range(1,101):
97+
if i % 3 == 0 and i % 5 == 0:
98+
print(cadena1 + cadena2)
99+
elif i % 3 == 0:
100+
print(cadena1)
101+
elif i % 5 == 0:
102+
print(cadena2)
103+
else:
104+
print(i)
105+
count += 1
106+
return count
107+
108+
print(extra("Fizz", "Buzz"))

0 commit comments

Comments
 (0)