函数:两个数的计算加减乘除:
def jisuan(a,b,c):
x=a
y=b
if c=="+":
end = a + b
elif c=="-":
end=a-b
elif c=="*":
end=a*b
elif c == "/":
end = a / b
else:
print("输入错误")
end=None
return end
end=jisuan(10,20,'+')
print("end=",end)
end=jisuan(10,20,'-')
print("end=",end)
end=jisuan(10,20,'*')
print("end=",end)
end=jisuan(10,20,'/')
print("end=",end)
运行结果:
#return 返回函数值
# 从函数中提取
def add(a,b):
i=a
sum=0
while i<=b: