Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
75 changes: 75 additions & 0 deletions src/exerciseseven/calculadora.py
Original file line number Diff line number Diff line change
@@ -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')
11 changes: 9 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -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__':
Expand Down