Skip to content

Commit

Permalink
Merge pull request #6 from Jlopezjlx/master
Browse files Browse the repository at this point in the history
Endless loop and refactoring for the Assignment #2's solution by @Jlopezjlx
  • Loading branch information
KenanBek committed Apr 9, 2019
2 parents a2403af + 6b8c27f commit d0de84a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 24 deletions.
56 changes: 38 additions & 18 deletions assignments/calculator/solutions/Jlopezjlx/calc/calc.py
@@ -1,38 +1,58 @@
import maths
loop = True
def sumar(a,b):
return a + b

while loop == True:
def restar(a,b):
return a - b

print("-----------------------------------------------------------------")
print("OPCIONES: \n1-Suma\n2-Resta\n3-Multiplicar\n4-Dividir\n5-Restante")
def multiplicacion(a,b):
return a * b

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

def restante(a,b):
return a % b


while True:

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

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


if opcion == 6:
print ("Exitting...")
break


try:
valor1 = int(input("Inserte primer valor: "))
valor2 = int(input("Inserte segundo valor: "))

if opcion == 1:
resultado = maths.sumar(valor1,valor2)
print("La suma de %d + %d es %d" % (valor1, valor2, resultado))
resultado = 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))
resultado = 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))
resultado = 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)))
resultado = 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))
resultado = 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")
print( "Eror, no se puede dividir entre 0")
except ValueError:
print( "Value Error")
except NameError:
Expand Down
12 changes: 6 additions & 6 deletions assignments/calculator/solutions/Jlopezjlx/calc/testcalc.py
@@ -1,34 +1,34 @@
import unittest
import maths
import calc

class testing_calc(unittest.TestCase):


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


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


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


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


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

Expand Down

0 comments on commit d0de84a

Please sign in to comment.