读程序,总结程序的功能:
1.打印一个数连续乘以2二十次
numbers=1
for i in range(0,20):
numbers*=2
print(numbers)
2.判断一个数是否能够被3或7整除,但是不能被21整除
summation=0
num=1
while num<=100:
if (num%3==0 or num%7==0) and num%21!=0:
summation += 1
num+=1
print(summation)
编程实现(for和while各写一遍)
1.求1打100之间所有数的和、平均值
sum1 = 0
for num in range(1,101):
sum1 += num
print(sum1,sum1/100)
num2 = 0
num3 = 0
while num3 <= 100:
num2 += num3
num3 += 1
print(num2,num2/100)
2. 计算1-100之间能3整除的数的和
sum2 = 0
x = 1
for x in range(101):
if x % 3 == 0:
sum2 += x
print(sum2)
num2 = 0
num3 = 0
while num3 <= 100:
if num3 % 3 ==0 :
num2 += num3
num3 += 1
print(num2)
3. 计算1-100之间不不能被7整除的数的和
sum = 0
x = 1
for x in range(101):
if x % 7 != 0:
sum += x
print(sum)
num2 = 0
num3 = 0
while num3 <= 100:
if num3 % 7 !=0 :
num2 += num3
num3 += 1
print(num2)
print('我是一条优雅的分割线')