Skip to content

Commit d0de84a

Browse files
authored
Merge pull request #6 from Jlopezjlx/master
Endless loop and refactoring for the Assignment #2's solution by @Jlopezjlx
2 parents a2403af + 6b8c27f commit d0de84a

File tree

2 files changed

+44
-24
lines changed

2 files changed

+44
-24
lines changed

assignments/calculator/solutions/Jlopezjlx/calc/calc.py

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,58 @@
1-
import maths
2-
loop = True
1+
def sumar(a,b):
2+
return a + b
33

4-
while loop == True:
4+
def restar(a,b):
5+
return a - b
56

6-
print("-----------------------------------------------------------------")
7-
print("OPCIONES: \n1-Suma\n2-Resta\n3-Multiplicar\n4-Dividir\n5-Restante")
7+
def multiplicacion(a,b):
8+
return a * b
9+
10+
def division(a,b):
11+
return a / b
12+
13+
def restante(a,b):
14+
return a % b
15+
16+
17+
while True:
18+
19+
print ("-----------------------------------------------------------------")
20+
print ("OPCIONES: \n1-Suma\n2-Resta\n3-Multiplicar\n4-Dividir\n5-Restante\n6-Exit")
821
try:
922

1023
opcion = int(input("Inserte opcion deseada: "))
11-
valor1 = int(input("Inserte primer valor: "))
12-
valor2 = int(input("Inserte segundo valor: "))
1324
except:
1425
print("Valuer Error")
1526

27+
28+
if opcion == 6:
29+
print ("Exitting...")
30+
break
31+
32+
1633
try:
34+
valor1 = int(input("Inserte primer valor: "))
35+
valor2 = int(input("Inserte segundo valor: "))
36+
1737
if opcion == 1:
18-
resultado = maths.sumar(valor1,valor2)
19-
print("La suma de %d + %d es %d" % (valor1, valor2, resultado))
38+
resultado = sumar(valor1,valor2)
39+
print ("La suma de %d + %d es %d" % (valor1, valor2, resultado))
2040
elif opcion == 2:
21-
resultado = maths.restar(valor1,valor2)
22-
print("La resta de %d - %d es %d" % (valor1, valor2, resultado))
41+
resultado = restar(valor1,valor2)
42+
print ("La resta de %d - %d es %d" % (valor1, valor2, resultado))
2343
elif opcion == 3:
24-
resultado = maths.multiplicacion(valor1,valor2)
25-
print("La multiplicacion de %d * %d es %d" % (valor1, valor2, resultado))
44+
resultado = multiplicacion(valor1,valor2)
45+
print ("La multiplicacion de %d * %d es %d" % (valor1, valor2, resultado))
2646
elif opcion == 4:
27-
resultado = maths.division(valor1,valor2)
28-
print("La division de %d / %d es %d" % (valor1, valor2, float(resultado)))
47+
resultado = division(valor1,valor2)
48+
print ("La division de %d / %d es %d" % (valor1, valor2, float(resultado)))
2949
elif opcion == 5:
30-
resultado = maths.restante(valor1,valor2)
31-
print("El restante de %d y %d es %d" % (valor1, valor2, resultado))
50+
resultado = restante(valor1,valor2)
51+
print ("El restante de %d y %d es %d" % (valor1, valor2, resultado))
3252
else:
3353
print("Error en las entradas, Bye")
3454
except ZeroDivisionError:
35-
print( "Error, no se puede dividir entre 0")
55+
print( "Eror, no se puede dividir entre 0")
3656
except ValueError:
3757
print( "Value Error")
3858
except NameError:

assignments/calculator/solutions/Jlopezjlx/calc/testcalc.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
import unittest
2-
import maths
2+
import calc
33

44
class testing_calc(unittest.TestCase):
55

66

77
def test_sumar(self):
8-
result = maths.sumar(2,3)
8+
result = calc.sumar(2,3)
99
self.assertEqual(5,result)
1010

1111

1212
def test_restar(self):
13-
result = maths.restar(2,3)
13+
result = calc.restar(2,3)
1414
expected = 2 - 3
1515
self.assertEqual(expected,result)
1616

1717

1818
def test_multiplcacion(self):
19-
result = maths.multiplicacion(2,3)
19+
result = calc.multiplicacion(2,3)
2020
expected = 2 * 3
2121
self.assertEqual(expected, result)
2222

2323

2424
def test_division(self):
25-
result = maths.division(2,3)
25+
result = calc.division(2,3)
2626
expected = 2 / 3
2727
self.assertEqual(expected, result)
2828

2929

3030
def test_restante(self):
31-
result = maths.restante(2,3)
31+
result = calc.restante(2,3)
3232
expected = 2 % 3
3333
self.assertEqual(expected, result)
3434

0 commit comments

Comments
 (0)