Created
June 28, 2019 17:44
-
-
Save joelibaceta/c97bb681abe3dd06b1f08729b418f332 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
print("\n\033[38;1mCalcular +, , *, / de 2 números:\033[0m\n") | |
def solve(str_operation): | |
pattern = re.compile("([0-9]+)[\s]*([\+\-\/\*])[\s]*([0-9]+)") | |
match = pattern.match(str_operation) | |
(operator1, operation, operator2) = match.groups() | |
if operation == "+": | |
return int(operator1) + int(operator2) | |
elif operation == "-": | |
return int(operator1) - int(operator2) | |
elif operation == "/": | |
return int(operator1) / int(operator2) | |
elif operation == "*": | |
return int(operator1) * int(operator2) | |
else: | |
return None; | |
# Loop Infinito | |
while True: | |
operation = input("Ingerese una oparacion o q para salir: ") | |
if operation == "q": | |
break; | |
else: | |
result = solve(operation) | |
if result == None: | |
print ("Operacion no permitida\n") | |
else: | |
print("\033[38;1m" + str(result) + "\033[0m\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment