Skip to content

Commit

Permalink
Merge pull request mouredev#3930 from NoMeLlamoDante/main
Browse files Browse the repository at this point in the history
#1- Python
  • Loading branch information
Roswell468 committed May 28, 2024
2 parents dda6090 + e8de413 commit 06fda48
Show file tree
Hide file tree
Showing 2 changed files with 221 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#### EJERCICIO: ###
"""- Crea ejemplos utilizando todos los tipos de operadores de tu lenguaje:
Aritméticos, lógicos, de comparación, asignación, identidad, pertenencia, bits...
(Ten en cuenta que cada lenguaje puede poseer unos diferentes)
"""

# Arithmetic Operators
print(f"Addition 9 + 6 = {9 + 6}")
print(f"Subtraction 9 - 6 = {9 - 6}")
print(f"Multiplication 9 * 6 = {9 * 6}")
print(f"Exponentiation 9 ** 6 = {9 ** 6}")
print(f"Division 9 / 6 = {9 / 6}")
print(f"Floor_division 9 // 6 = {9 // 6}")
print(f"Modulus 9 % 6 = {9 % 6}")

#Logic Operators
print(f" True And False : {True and False}")
print(f"True Or False : {True or False}")
print(f"Not False : {not False}")

#Comparison Operators
print(f"Equal: 10 == 10 {10 == 10}")
print(f"Not Equal: 10 != 5 {10 != 5}")
print(f"Greater than 5 > 10 {5 > 10}")
print(f"Greater than or equal to 5 >= 10 {5 >= 10}")
print(f"Less than 5 < 10 {5 < 10}")
print(f"Less than or equal to 5 > 10 {5 <= 10}")

#Bitwise Operators
x = 10
y = 7
print(f"x({x}, {bin(x)}) & y({y}, {bin(y)}) = {x & y}, {bin(x & y)}")
print(f"x({x}, {bin(x)}) | y({y}, {bin(y)}) = {x | y}, {bin(x | y)}")
print(f"x({x}, {bin(x)}) ^ y({y}, {bin(y)}) = {x ^ y}, {bin(x ^ y)}")
print(f"~ ( x({x}, {bin(x)}) ) = {~x}, {bin(~x)}")
print(f"x ({x},{bin(x)} >> 2 = {x >> 2}, {bin(x>>2)}")
print(f"x ({x},{bin(x)} << 2 = {x << 2}, {bin(x<<2)}")

#Assignment Operators
x = 10
print(f"x = 10: {x}")
x += 10
print(f"x = x + 10: {x}")
x -= 10
print(f"x = x - 10: {x}")
x *= 10
print(f"x = x * 10: {x}")
x /= 5
print(f"x = x / 5: {x}")
x %= 11
print(f"x = x % 11: {x}")
x //= 3
print(f"x = x // 3: {x}")
x **=2
print(f"x = x ** 2: {x}")

#Assignment Bitwise Operators
x = int(x)
print(f"x = {bin(x)}")
print(f"8 = {bin(3)}")
x &= 8
print(f"x = x &= 8: {bin(x)}: {x}")
print(f"7 = {bin(7)}")
x |= 7
print(f"x = x &= 7: {bin(x)}: {x}")
print(f"5 = {bin(5)}")
x ^= 5
print(f"x = x ^= 5: {bin(x)}: {x}")
x>>=2
print(f"x >>= 2 = {x}, {bin(x)}")
x<<=2
print(f"x <<= 2 = {x}, {bin(x)}")

#Identity Operators
x = [1,2,3]
y = [1,2,3]
z = x
print(f"x= {x}, y= {y}, z= x")
print(f"x is z? {x is z} || x is y? {x is y}")
print(f"x is not z? {x is not z} || x is not y? {x is not y}")

#Membership Operators
text = "refrigerator"
print(f"text = {text}")
print(f"'t' in {text}= {'t' in text}")
print(f"'z' not in {text}= {'z' not in text}")
"""- Utilizando las operaciones con operadores que tú quieras, crea ejemplos
que representen todos los tipos de estructuras de control que existan
en tu lenguaje:
Condicionales, iterativas, excepciones...
"""
text = "digital"
for char in text:
if char == "a":
index = 5
while index >=0:
index-=1
if index %3 == 0 and index!=0:
continue
try:
print(f"5 / index = {5/index}")
except Exception as e:
print(f"error: {e}")
else :
print("end while")
elif char == "g":
while True:
print("other while")
break
else:
print(f"char: {char}")

"""- Debes hacer print por consola del resultado de todos los ejemplos."""


"""DIFICULTAD EXTRA (opcional):
Crea un programa que imprima por consola todos los números comprendidos
entre 10 y 55 (incluidos), pares, y que no son ni el 16 ni múltiplos de 3.
Seguro que al revisar detenidamente las posibilidades has descubierto algo nuevo.
"""
for index in range(10,56):
if index % 2 == 0 and index != 16 and not index%3 == 0:
print(f"index = {index}")
98 changes: 98 additions & 0 deletions Roadmap/02 - FUNCIONES Y ALCANCE/python/NoMeLlamoDante.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#02 FUNCIONES Y ALCANCE
"""EJERCICIO:
- Crea ejemplos de funciones básicas que representen las diferentes posibilidades del lenguaje:
Sin parámetros ni retorno, con uno o varios parámetros, con retorno...
- Comprueba si puedes crear funciones dentro de funciones.
- Utiliza algún ejemplo de funciones ya creadas en el lenguaje.
- Pon a prueba el concepto de variable LOCAL y GLOBAL.
- Debes hacer print por consola del resultado de todos los ejemplos.
(y tener en cuenta que cada lenguaje puede poseer más o menos posibilidades)
"""
#Functions
def simple_function():
print("funcion simple")
simple_function()

def return_function():
return "funcion con retorno"
print(return_function())

def multiple_return_function():
return "funcion", "multiple","retorno"
print(multiple_return_function())

def one_parameter_function(parameter):
print(f"funciones con un solo {parameter}")
one_parameter_function("parametro")


def multiple_paramater_function(parameter_one="1", parameter_two= "2", *another_parameters):
print(f"parameter one: {parameter_one} || parameter two:{parameter_two}")
for parameter in another_parameters:
print(parameter)
multiple_paramater_function()
multiple_paramater_function(parameter_two="two",parameter_one="one")
multiple_paramater_function("hola", "mundo", "hecho", "en", "python")

def multiple_named_parameters(**parameters):
for index, parameter in parameters.items():
print(f"index: {index}, value: {parameter}")

multiple_named_parameters(
one= "hola",
two= "mundo",
three= "python")

#Function in functions
def extern_function(param_1,param_2, param_3):

def intern_function(_param_2, _param_3):
return _param_2+ _param_3

return lambda param_4, param_5:param_4+param_5+intern_function(param_2,param_3)+param_1

print(extern_function(1,2,3)(4,5)) #15

#Built in Functions
print(len("hola mundo")) # Character count
print(type("String"))
print(9.9)
print(10)
print(bin(111111))
print(int("45"))

#Local and Global Variables
variable = "Global"
def printable(variable):
print(variable)

print(variable)
printable("Local")
print(variable)

"""DIFICULTAD EXTRA (opcional):
Crea una función que reciba dos parámetros de tipo cadena de texto y retorne un número.
- La función imprime todos los números del 1 al 100. Teniendo en cuenta que:
- Si el número es múltiplo de 3, muestra la cadena de texto del primer parámetro.
- Si el número es múltiplo de 5, muestra la cadena de texto del segundo parámetro.
- Si el número es múltiplo de 3 y de 5, muestra las dos cadenas de texto concatenadas.
- La función retorna el número de veces que se ha impreso el número en lugar de los textos.
Presta especial atención a la sintaxis que debes utilizar en cada uno de los casos.
Cada lenguaje sigue una convenciones que debes de respetar para que el código se entienda."""

def two_strings(_string_one, _string_two):
count = 0
for index in range(1, 101):
text = ""
if index%3 == 0:
text+=_string_one
if index%5 == 0:
text+=_string_two
if text == "":
print(index)
count+=1
else:
print(text)
return count

print(two_strings("one","two"))

0 comments on commit 06fda48

Please sign in to comment.