您的位置:首页 > 其它

创建一个模块calculator.py,完成任意两个数的加(add)、减(sub)、乘(mult)、除(div)运算;导入该模块,分别调用其中的函数,完成如下操作: 1、25+56 2、86-68 3

2017-10-15 15:06 645 查看
 模块calculator.py

#-*- coding:UTF-8 -*-
__author__ = "zhangguodong"
__time__ ="2017.09.29"

def add(a,b):
return a+b

def sub(a,b):
return a-b

def mult(a,b):
return a*b

def div(a,b):
return a/b
主文件程序14.py

#-*- coding:UTF-8 -*-
__author__ = "zhangguodong"
__time__ ="2017.09.29"

from calculator import add, sub, mult, div
# a = float(raw_input("Input the first number:"))
# b = float(raw_input("Input the second number:"))

operator = {'+':add,'-':sub,'*':mult,'/':div}

def Input(a,o,b):
print "%s%s%s=%s"%(a,o,b,operator.get(o)(a,b))

Input(25,"+",56)
Input(86,"-",68)
Input(50,"*",60)
Input(99,"/",25)

输出结果和截图:

25+56=81
86-68=18
50*60=3000
99/25=3
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐