Está en la página 1de 5

UNIVERSIDAD DE SAN CARLOS DE GUATEMALA

FACULTAD DE INGENIERIA

PROYECTOS DE COMPUTACION APLICADOS A LA INGENIERIA ELECTRONICA

ING. JOSE ANIBAL SILVA

CALCULADORA EN PYTHON

NOMBRE: RICARDO XAVIER SANDOVAL BALCARCEL

CARNE: 201904055

FECHA: JUEVES 10 DE ENERO DE 2022


1. MENU DE OPCIONES DE OPERACIÓN DISPONIBLES A REALIZAR:

2. EJECUTANDO UNA OPERACIÓN:

3. TRY-CATCH FUNCIONANDO:

4. FINALIZACION DEL PROGRAMA:


5. CODIGO:
6. import os
7. import math
8.
9. #operaciones
10. def suma(a, b):
11. return a + b
12.
13. def resta(a, b):
14. return a - b
15.
16. def multiplicacion(a, b):
17. return a * b
18.
19. def division(a, b):
20. return a / b
21.
22. def potencia(a, b):
23. a=a**b
24.
25. return a
26.
27. def raiz(a, b):
28. return a**(1/b)
29.
30. input()
31. os.system('cls')
32.
33. while True:
34.
35. try:
36. print("Calculadora")
37. print("1 - Sumar")
38. print("2 - Restar")
39. print("3 - Multiplicar")
40. print("4 - Division")
41. print("5 - Potencia")
42. print("6 - Raiz")
43. opcion = input("ingrese el numero de la operacion a realizar o
presione (7) para finalizar la calculadora: ")
44.
45. if (opcion == "1" or opcion == "2" or opcion == "3" or opcion ==
"4" or opcion == "5" or opcion == "6" or opcion == "7"):
46. opcion = opcion
47. tipo_de_dato = 1
48. else:
49. tipo_de_dato = opcion
50.
51. tipo = isinstance(tipo_de_dato,str)
52.
53. if(tipo == True) :
54. raise ArithmeticError("No puede ingresar datos de tipo
caracter")
55.
56. except ArithmeticError:
57. print ("No puede ingresar datos de tipo caracter")
58. else:
59. if opcion=="1":
60. numero1 = float(input("Numero 1: "))
61. numero2 = float(input("Numero 2: "))
62.
63. print("El resultado de la suma es: ",suma(numero1, numero2))
64.
65. elif opcion=="2":
66. numero1 = float(input("Numero 1: "))
67. numero2 = float(input("Numero 2: "))
68.
69. print("La resta es: ",resta(numero1, numero2))
70.
71. elif opcion=="3":
72. numero1 = float(input("Numero 1: "))
73. numero2 = float(input("Numero 2: "))
74.
75. print("La Multiplicacion es: ",multiplicacion(numero1,
numero2))
76.
77. elif opcion=="4":
78. numero1 = float(input("Numero 1: "))
79. numero2 = float(input("Numero 2: "))
80.
81. print("La division es: ",division(numero1, numero2))
82.
83. elif opcion=="5":
84. numero1 = int(input("Ingrese la base de la potencia: "))
85. numero2 = int(input("Ingrese el exponente de la potencia: "))
86.
87. print("La potencia del numero es: ",potencia(numero1,
numero2))
88.
89. elif opcion=="6":
90. numero1 = float(input("Ingrese el numero al cual desea sacar
la raiz: "))
91. numero2 = float(input("Ingrese el valor de la raiz que desea
obtener del numero: "))
92.
93. print("La raiz del numero es: ",raiz(numero1, numero2))
94.
95. elif opcion=="7":
96. exit()

También podría gustarte