(1)运用过程性语言求和
sum = 0
for i in range(501):
sum += i
print(sum)
(2)高斯求和
n=500
s=(1+n)*(n//2)
print(s)
(3)定义函数执行求和
def qh():
qh=0
for i in range(501):
qh += i
print(qh)
qh()
(1)运用过程性语言求和
sum = 0
for i in range(501):
sum += i
print(sum)
(2)高斯求和
n=500
s=(1+n)*(n//2)
print(s)
(3)定义函数执行求和
def qh():
qh=0
for i in range(501):
qh += i
print(qh)
qh()