SHARE
TWEET

Untitled

a guest Aug 20th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import operator
  2.  
  3. def operacion(x, y, op):
  4.     operadores = {
  5.          '+': operator.add,
  6.          '-': operator.sub,
  7.          '*': operator.mul,
  8.          '/': operator.truediv,
  9.           '=': operator.eq
  10.           }
  11.     fop = operadores.get(op)
  12.     if fop is not None:
  13.         print(fop(x, y))
  14.     else:
  15.         raise ValueError("Operador no valido")
  16.      
  17. >>> operacion(5, 4, "+")
  18. 9
  19. >>> operacion(5, 4, "-")
  20. 1
  21. >>> operacion(5, 4, "*")
  22. 20
  23. >>> operacion(5, 4, "/")
  24. 1.25
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top