Skip to content
Merged
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
60 changes: 38 additions & 22 deletions assignments/calculator/solutions/Jlopezjlx/calc/calc.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
print("CALCULADORA")
print("OPCIONES: \n1-Suma\n2-Resta\n3-Multiplicar\n4-Dividir\n5-Restante")
import maths
loop = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need this, check comment below.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


opcion=int(input("Inserte opcion deseada: "))
valor1 = int(input("Inserte primer valor: "))
valor2 = int(input("Inserte segundo valor: "))
while loop == True:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to:

while True:

and remove the loop variable. To stop the execution of the endless loop add one more operation (6-Exit) and when you get 6 as an operation stop the loop (example https://wiki.python.org/moin/WhileLoop).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


print("-----------------------------------------------------------------")
print("OPCIONES: \n1-Suma\n2-Resta\n3-Multiplicar\n4-Dividir\n5-Restante")
try:

opcion = int(input("Inserte opcion deseada: "))
valor1 = int(input("Inserte primer valor: "))
valor2 = int(input("Inserte segundo valor: "))
except:
print("Valuer Error")

try:
if opcion == 1:
resultado = maths.sumar(valor1,valor2)
print("La suma de %d + %d es %d" % (valor1, valor2, resultado))
elif opcion == 2:
resultado = maths.restar(valor1,valor2)
print("La resta de %d - %d es %d" % (valor1, valor2, resultado))
elif opcion == 3:
resultado = maths.multiplicacion(valor1,valor2)
print("La multiplicacion de %d * %d es %d" % (valor1, valor2, resultado))
elif opcion == 4:
resultado = maths.division(valor1,valor2)
print("La division de %d / %d es %d" % (valor1, valor2, float(resultado)))
elif opcion == 5:
resultado = maths.restante(valor1,valor2)
print("El restante de %d y %d es %d" % (valor1, valor2, resultado))
else:
print("Error en las entradas, Bye")
except ZeroDivisionError:
print( "Error, no se puede dividir entre 0")
except ValueError:
print( "Value Error")
except NameError:
print( "Name Error")

if opcion == 1:
resultado = valor1 + valor2
print("La suma de %d + %d es %d" %(valor1, valor2, resultado))
elif opcion == 2:
resultado = valor1 - valor2
print("La resta de %d - %d es %d" %(valor1, valor2, resultado))
elif opcion == 3:
resultado = valor1 * valor2
print("La multiplicacion de %d * %d es %d" %(valor1, valor2, resultado))
elif opcion == 4:
resultado = valor1 / valor2
print("La division de %d / %d es %d" %(valor1, valor2, float(resultado)))
elif opcion == 5:
resultado = valor1 % valor2
print("El restante de %d y %d es %d" %(valor1, valor2, resultado))
else:
print("Error en las entradas, Bye")
14 changes: 14 additions & 0 deletions assignments/calculator/solutions/Jlopezjlx/calc/maths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def sumar(a,b):
return a + b

def restar(a,b):
return a - b

def multiplicacion(a,b):
return a * b

def division(a,b):
return a / b

def restante(a,b):
return a % b
40 changes: 40 additions & 0 deletions assignments/calculator/solutions/Jlopezjlx/calc/testcalc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import unittest
import maths

class testing_calc(unittest.TestCase):


def test_sumar(self):
result = maths.sumar(2,3)
self.assertEqual(5,result)


def test_restar(self):
result = maths.restar(2,3)
expected = 2 - 3
self.assertEqual(expected,result)


def test_multiplcacion(self):
result = maths.multiplicacion(2,3)
expected = 2 * 3
self.assertEqual(expected, result)


def test_division(self):
result = maths.division(2,3)
expected = 2 / 3
self.assertEqual(expected, result)


def test_restante(self):
result = maths.restante(2,3)
expected = 2 % 3
self.assertEqual(expected, result)


if __name__ == '__main__':
unittest.main()