From 70be018ff35b9991bb7ca20d7f961fb1ecdc2775 Mon Sep 17 00:00:00 2001 From: Izri Toufali Lapaz Date: Wed, 9 Nov 2022 11:41:01 +0100 Subject: [PATCH 1/2] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index fa0237d..c3479d1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # OpenBootCampPython Repository to store Python boot camp. + +Ejercicio 7.A: En este ejercicio tendréis que crear un módulo que contenga las operaciones básicas de una calculadora: sumar, restar, multiplicar y dividir. + +Este módulo lo importaréis a un archivo python y llamaréis a las funciones creadas. Los resultados tenéis que mostrarlos por consola. From a34d85fc4cad68ae9ddb7db4d3e418deceea7dc0 Mon Sep 17 00:00:00 2001 From: tlizri Date: Wed, 9 Nov 2022 12:10:15 +0100 Subject: [PATCH 2/2] Completed exercise seven A --- src/exerciseseven/calculadora.py | 75 ++++++++++++++++++++++++++++++++ src/main.py | 11 ++++- 2 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 src/exerciseseven/calculadora.py diff --git a/src/exerciseseven/calculadora.py b/src/exerciseseven/calculadora.py new file mode 100644 index 0000000..fbe4c4e --- /dev/null +++ b/src/exerciseseven/calculadora.py @@ -0,0 +1,75 @@ +def _mostrar(a, b, c, operacion): + """Function to show the operation and its result + :param a: first operand + :type a: numerical + :param b: second operand + :type b: numerical + :param c: result of the operation + :type c: numerical + :param operacion: type of the operation + :type operacion: str + :return: None + :rtype: NoneType + """ + print(a, operacion, b, '=', c) + + +def sumar(a, b): + """Function to calculate addition of two numbers + :param a: first operand + :type a: numerical + :param b: second operand + :type b: numerical + :return: addition of two operands + :rtype: numerical + """ + c = a + b + _mostrar(a, b, c, '+') + return c + + +def restar(a, b): + """Function to calculate subtraction of two numbers + :param a: first operand + :type a: numerical + :param b: second operand + :type b: numerical + :return: subtraction of two operands + :rtype: numerical + """ + c = a - b + _mostrar(a, b, c, '-') + return c + + +def multiplicar(a, b): + """Function to calculate multiplication of two numbers + :param a: first operand + :type a: numerical + :param b: second operand + :type b: numerical + :return: multiplication of two operands + :rtype: numerical + """ + c = a * b + _mostrar(a, b, c, '*') + return c + + +def dividir(a, b): + """Function to calculate division of two numbers + :param a: first operand + :type a: numerical + :param b: second operand + :type b: numerical + :return: division of two operands, infinite if divide by zero + :rtype: numerical + """ + if b != 0: + c = a / b + _mostrar(a, b, c, '/') + return c + else: + c = float('inf') + _mostrar(a, b, c, '/') + return float('inf') diff --git a/src/main.py b/src/main.py index a47b6a3..283445f 100644 --- a/src/main.py +++ b/src/main.py @@ -1,9 +1,16 @@ +import exerciseseven.calculadora as s + + def main(): - """Main script for pythonBootCamp project + """Main script for exercise seven A :return: None :rtype: NoneType """ - pass + s.sumar(5, 6) + s.restar(2, 10) + s.multiplicar(-1, 32) + s.dividir(5, 2) + s.dividir(5, 0) if __name__ == '__main__':