- 求1到100之间所有数的和、平均值
num = 1
sum1 = 0
while num <= 100:
sum1 += num
num += 1
print(sum1)
avg=sum1/100
print(avg)
![K`SU8{%I01A6T55NQ@@_]UY.png](https://img.haomeiwen.com/i14228690/d78054c5e108f681.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
sum1 = 0
for x in range(1,101):
sum1 += x
print(sum1)
avg=sum1/len(range(1,101))
print(avg)
5(5)M%G7SEIZOQ(FC6MH$~9.png
- 计算1-100之间能3整除的数的和
sum1=0
for x in range(1,101):
if x %3==0:
sum1+=x
x+=1
print(sum1)
n = 100
num = 1
sum1 = 0
while num <= n:
if num %3== 0:
sum1+=num
num += 1
print(sum1)
39J7D2_$`B%80G{3{S3V13U.png
- 计算1-100之间 不能被7整除的数的和
sum1=0
for x in range(1,101):
if x %7==1:
sum1+=x
x+=1
print(sum1)
QQ图片20180929205408.png
num=0
while num<=100:
if num%7==1:
sum1+=num
num+=1
print(sum1)
QQ图片20180929205408.png
网友评论