AP的条款总和

时间:2018-04-01 19:54:29

标签: python

我写了一个代码来显示AP的编号,与输入的编号

的条件相关联
P = int(input())
R = int(input())
Q = int(input())
S = 0
Cont = 0
while Cont<=Q:
 print("Termo",Cont,"da PA = ",P)
 P = P+R
 Cont = Cont+1

它工作正常,但在这种情况下,我如何总结AP的所有条款?

1 个答案:

答案 0 :(得分:0)

在循环中添加计算的术语。

P = int(input())
R = int(input())
Q = int(input())
S = 0
Cont = 0
while Cont<=Q:
 print("Termo",Cont,"da PA = ",P)
 S = S + P
 P = P+R
 Cont = Cont+1

print("Sum:",S)