主程序
#!/usr/bin/python
#coding:utf8
import add,multipy,minus,divisi
if
__name__==
'__main__':
print
'您想做的运算是什么?'
flag=
True
while flag:
step1=
raw_input(
'jia,jian,chen,chu:')
if step1==
'jia':
var1=
raw_input(
'var:')
add.jiafa(var1)
elif step1==
'jian':
var2=
raw_input(
'var:')
minus.jian(var2)
elif step1==
'chen':
var3=
raw_input(
'var:')
multipy.chenfa(var3)
elif step1==
'chu':
var4=
raw_input(
'var:')
divisi.chufa(var4)
elif step1==
'exit':
falg=
False
else:
print
'您的输入有误,请重新输入:'
以下需要调用的四类函数需要放在与主函数同一project下:
#!/usr/bin/python
#coding:utf8
import string
def jiafa(var):
num1=var.split(
'+',
1)
print
'%s + %s = %s' % (
int(num1[
0]),
int(num1[
1]),
int(num1[
0])+
int(num1[
1]))
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import string
def chufa(var):
num1=var.split(
'/',
1)
print
'%s / %s = %s' % (
int(num1[
0]),
int(num1[
1]),
int(num1[
0])/
int(num1[
1]))
#!/usr/bin/python
#coding:utf8
import string
def jian(var):
num1=var.split(
'-',
1)
print
'%s - %s = %s' % (
int(num1[
0]),
int(num1[
1]),
int(num1[
0])-
int(num1[
1]))
#!/usr/bin/python
#coding:utf8
import string
def chenfa(var):
num1=var.split(
'*',
1)
print
'%s + %s = %s' % (
int(num1[
0]),
int(num1[
1]),
int(num1[
0])*
int(num1[
1]))
执行结果:
您想做的运算是什么?
jia,jian,chen,chu:jia
var:2+3
2 + 3 = 5
jia,jian,chen,chu:jian
var:5-6
5 - 6 = -1
jia,jian,chen,chu:chen
var:2*4
2 + 4 = 8
jia,jian,chen,chu:chu
var:24/3
24 / 3 = 8
jia,jian,chen,chu: