-
Notifications
You must be signed in to change notification settings - Fork 5
Added solutions from @mirpulatov, @Jlopezjlx, @Prrrince for calculator #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
||
| opcion=int(input("Inserte opcion deseada: ")) | ||
| valor1 = int(input("Inserte primer valor: ")) | ||
| valor2 = int(input("Inserte segundo valor: ")) | ||
| while loop == True: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this to: and remove the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
| 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 |
| 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() | ||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed