互联网技术 / 互联网资讯 · 2023年12月30日

Python云计算开发:函数调用练习实例

题目:编写一个函数,输入n为偶数时,调用函数求1/2+1/4+…+1/n,当输入n为奇数时,调用函数1/1+1/3+…+1/n。

程序分析:Python里,整数除整数,只能得出整数,所以需要使用 浮点数 1.0。

程序源代码:

云计算开发:Python练习实例-函数调用

以上实例输出结果为:

云计算开发:Python练习实例-函数调用

OpenMagic API

Need more than content? Move into the product flow.

If you are here for model access, pricing, developer docs, or the future API console, the dedicated product path now lives on api.openmagic.ai.

登录免费注册