Ai
1 Star 0 Fork 0

zq_online/python-math

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
dengbishulie.py 839 Bytes
一键复制 编辑 原始数据 按行查看 历史
zq_online 提交于 2024-01-27 13:11 +08:00 . Initial commit
# 在Python中,等比数列的通项公式可以表示为:
# [ a_n = a_1 \times r^{(n - 1)} ]
# 其中:
# ( a_n ) 是第n项的值,
# ( a_1 ) 是首项(第一项),
# ( n ) 是项数,
# ( r ) 是公比。
# 以下是一个简单的函数实现
def geometric_sequence_term(n, first_term, common_ratio):
"""
计算等比数列的第n项
参数:
n -- 需要求解的项数(从1开始计数)
first_term -- 等比数列的首项
common_ratio -- 等比数列的公比
返回值:
第n项的数值
"""
return first_term * (common_ratio ** (n - 1))
# 示例:计算首项为2,公比为3的等比数列的第5项
first_term = 2
common_ratio = 3
nth_term = 5
result = geometric_sequence_term(nth_term, first_term, common_ratio)
print(f"等比数列的第{nth_term}项是:{result}")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/createmaker/python-math.git
git@gitee.com:createmaker/python-math.git
createmaker
python-math
python-math
master

搜索帮助