Skip to content

Instantly share code, notes, and snippets.

@ramalho
Created July 18, 2012 16:04
Show Gist options
  • Select an option

  • Save ramalho/3137159 to your computer and use it in GitHub Desktop.

Select an option

Save ramalho/3137159 to your computer and use it in GitHub Desktop.
# coding: utf-8
from operator import add, sub, mul, div
operadores = {'+': add, '-': sub, '*':mul, '/':div}
x = input('Entre com o operando 1: ')
y = input('Entre com o operando 1: ')
operacao = raw_input('Entre com a operação: ')
operador = operadores.get(operacao)
if operador:
resultado = operador(x, y)
print 'Resultado:', resultado
else:
print 'Operação inválida'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment