for i in range(20):
number *= 2
print(number)
20个2相乘
num = 1
while num<100:
if (num%3==0 or num%7==0) and num% 21!=0:
summation += 1
num += 1
print(summation)
找到1-100 不能被21整除且3和7的倍数的个数和
1.求出1到100所有数的和,平均值
for i in range(101):
sum1 += i
avr = sum1/len(range(100))
print(sum1)
print(avr)
number=1
sum2= 0
while number<101:
sum2 += number
number += 1
avr = sum1/len(range(100))
print(sum2)
print(avr)
2.计算1-100之间能3整除的数的和
sum3 =0
for i in range(3,101,3):
sum3 += i
print(sum3)
sum4 = 0
for i in range(1,101):
if i%3==0:
sum4 += i
print(sum4)
number =0
total= 0
while number<101:
total += number
number+=3
print(total)
number =0
total= 0
while number<101:
if number%3 ==0:
total += number
number+=1
print(total)
3.计算1-100之间不能被7整除的数的和
total2=0
for i in range(1,101):
if i%7==1:
total2 += i
print(total2)
number2 = 0
total3 = 0
while number2<101:
if number2%7==1:
total3 += number2
number2 += 1
print(total3)

1.png

2.png

3.png

4.png

5.png

6.png
网友评论