python定义函数

王亿万 2019-05-18 10:37:58
用python定义四个函数,加减乘除四个函数,怎么样让输入的不定长参数可以达到累加累减累乘累除,除的时候不能为零。求教大神!求抱大腿🦵
...全文
51 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
一笑程序猴 2019-05-20
  • 打赏
  • 举报
回复

def add(*args):
res = sum(args)
return res
print(add(1,2,3,4,5,6))

def chu(*args):
res = args[0]
for i in args:
if i != 0:
res /= i
return res
print(chu(1,2,3,4,5))


另外连个类似
ZhuCheng Xie 2019-05-20
  • 打赏
  • 举报
回复
累减 a = 100 b = 1 for b in range(1,10): a = a - b print(a)
ZhuCheng Xie 2019-05-20
  • 打赏
  • 举报
回复
累加: i = 1 total = 0 for i in range(1,10): total = total + i print(total)

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧