python实例(六)Numpy实现加减乘除

命题

实现加减乘除运算

思路

利用现成的numpy库

import numpy as np
#输入两个数
x=int(input("the fist number: "))
y=int(input("the second number: "))
#选择相应运算
print("1.add the two numbet")
print("2.subtract the two numbet")
print("3.mulitiply the two numbet")
print("4.divide the two numbet")
z=int(input("please choice the number:"))
#根据选择执行命令
if z==1:
    print("{0} + {1} = {2}".format(x,y,np.add(x,y)))
elif z==2:
    print("{0} - {1} = {2}".format(x,y,np.subtract(x,y)))
elif z==3:
    print("{0} * {1} = {2}".format(x,y,np.multiply(x,y)))
else:
    print("{0} / {1} = {2}".format(x,y,np.divide(x,y)))
    ```

你可能感兴趣的:(python3基础)