Python入门小程序:四则运算器

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/FUZHENQI/article/details/79794259

Python入门小程序:四则运算器

1.py

x = int(input("first:"))
o = input("operator:")
y = int(input("second:"))

operator = { 
            '+':x+y,
            '-':x-y,
            '*':x*y,
            '/':x/y,
            }                      

result = operator.get(o,'please input+|-|*|/')
print(result)

用字典构造简单的四则运算器,.get 用于operator输入超出字典范围后的报错。

猜你喜欢

转载自blog.csdn.net/FUZHENQI/article/details/79794259