-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalcu.py
More file actions
47 lines (39 loc) · 1.28 KB
/
Calcu.py
File metadata and controls
47 lines (39 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import re
import xdrlib
print(" Calculadora.py")
print("OPERACIONES ARIMETICAS")
x = input("Ingrese el primer valor de la operacion:->>")
#verifica si (x) es numero entero o decimal
if (not re.match('^-?[0-9]+[\.,]?[0-9]*$',x)):
print("Formato invalido. Debe ingresar un numero entero o decimal:->>")
exit()
oper=input("Ingrese la operacion a relizar (+,-,*,/,^):->>")
#verifica si la operacion es valida
if (not re.match('^[\+\-\*\/\^]$',oper)):
print("Operacion Invalida debe ingresar (+,-,*,/,^)")
exit()
y=input("Ingrese e; segundo valor de la operacion:->>")
#verifica si (y) es numero entero o decimal
if (not re.match('^-?[0-9]+[\.,]?[0-9]*$',y)):
print("Formato invalido. Debe ingresar un numero entero o decimal")
exit()
#Converted el str a un numero entero o decimal
if (x.find('.') > -1 or x.find(',')):
x = float(x.replace(',', '.'))
else:
x = int(x)
if (y.find('.')>-1 or y.find(',')):
y=float(y.replace(',','.'))
else:
y=int(y)
#Realize y muestra el resulted de la operacion
if (oper=='+'):
print(f"{x} {oper} {y} = {x+y}")
elif (oper=='-'):
print(f"{x} {oper} {y} = {x-y}")
elif (oper=='*'):
print(f"{x} {oper} {y} = {x*y}")
elif (oper=='/'):
print(f"{x} {oper} {y} = {x/y}")
elif (oper=='^'):
print(f"{x} {oper} {y} = {x**y}")