Skip to content

Commit dd5bf99

Browse files
authored
几何数级代码
1 parent b3c127e commit dd5bf99

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
a = int(input("请输入首项a:"))
2+
q = int(input("请输入公比q:"))
3+
n = int(input("请输入项数n:"))
4+
5+
sum = 0 #sum 为和
6+
for i in range(n): #从0到n-1
7+
sum += a*(q**i) #加上每一项
8+
print('几何数级为:',sum)#输出和

0 commit comments

Comments
 (0)