python使用字典实现switch功能

def result():
  a = float(input("Please input a:"))


while 1:
  ope = input("please input ope:")
  b = float(input("Please input b:"))
  result = {
    "+":a + b,
    "-":a - b,
    "*":a * b,
    "/":a / b
  }
  a = result.get(ope)
  print(a)

posted on 2017-08-07 10:50  sunshine_zhf  阅读(161)  评论(0编辑  收藏  举报

导航