编程练习
使用map函数,求元组 (2,4,6,8,10,12)中各个元素的5次方
任务
- pow_five函数体内:计算元素的5次方
- 调用pow_five函数传入data,使用result接收
任务提示
- pow(x,y) 方法返回 x的y次方的值
- 计算结果:(32, 1024, 7776, 32768, 100000, 248832)
初始代码
| def pow_five(data): | |
| # 计算元素的5次方 | |
| result = | |
| return result | |
| if __name__ == '__main__': | |
| data = (2,4,6,8,10,12) | |
| # 调用pow_five函数传入data,使用result接收 | |
| result = map() | |
| print(tuple(result)) |
代码
| def pow_five(data): | |
| # 计算元素的5次方 | |
| result = map(lambda n: pow(n, 5), data) | |
| return result | |
| if __name__ == '__main__': | |
| data = (2, 4, 6, 8, 10, 12) | |
| # 调用pow_five函数传入data,使用result接收 | |
| result = pow_five(data) | |
| print(tuple(result)) |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 ZkeqのCoding日志!
评论








