第5章-3 四则运算(用字典实现) res = {'+': 'x+y', '-': 'x-y', '*': 'x*y', '/': "x/y if y!=0 else 'divided by zero'"} x = int(input()) operator = input() y = int(input()) r = eval(res[operator]) if type(r) != str: print(format(r, '.2f')) else: print(r)