diff --git a/python-ofensivo/00_ejercicios/07_modulos/main.py b/python-ofensivo/00_ejercicios/07_modulos/main.py new file mode 100644 index 0000000..75a1785 --- /dev/null +++ b/python-ofensivo/00_ejercicios/07_modulos/main.py @@ -0,0 +1,6 @@ +from math_operations import suma, resta, multiplicacion, division + +print(suma(5, 2)) +print(resta(4, 2)) +print(multiplicacion(7, 2)) +print(division(2, 2)) diff --git a/python-ofensivo/00_ejercicios/07_modulos/math_operations.py b/python-ofensivo/00_ejercicios/07_modulos/math_operations.py new file mode 100644 index 0000000..7bbcf40 --- /dev/null +++ b/python-ofensivo/00_ejercicios/07_modulos/math_operations.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +""" +Modulos +""" + +def suma(x, y): + return x + y + +def resta(x, y): + return x - y + +def multiplicacion(x, y): + return x * y + +def division(x, y): + + if y == 0: + raise ValueError('[!] No se puede dividir por cero') + else: + return x / y + diff --git a/python-ofensivo/00_ejercicios/07_modulos01.py b/python-ofensivo/00_ejercicios/07_modulos01.py new file mode 100644 index 0000000..921c11a --- /dev/null +++ b/python-ofensivo/00_ejercicios/07_modulos01.py @@ -0,0 +1,26 @@ +""" +Se puede ver con dir() las funciones que tiene un módulo + +Con builtin_module_names se puede ver los módulos que vienen por defecto en python + +Por supuesto, se pueden ver todos los módulos descargados con pip con: +pip freeze + +Se puede ver la ubicación de un módulo externo con __file__ + +""" + +import math +import sys +import hashlib + + +print(dir(math)) +print() +print(sys.builtin_module_names) +print() +print(hashlib.__file__) +print() + +# Ejemplo de uso hashlib +print(hashlib.md5(b'Hello World').hexdigest())