numbers=1
for i in range(0,20):
numbers*=2
print(numbers)
求2的20次方
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)
求1到100中能被3或者7整除但不能被3和7同时整除的数的个数
- 求1到100之间所有数的和、平均值
for循环
sum1 = 0
for num in range(1,101):
sum1+=num
print(sum1)
average=sum1/100
print(average)
while循环
sum1 = 0
num = 1
while num<=100:
sum1+=num
num+=1
print(sum1)
average=sum1/100
print(average)
2. 计算1-100之间能3整除的数的和
for循环
sum1=0
for num in range(1,101):
if num%3==0:
sum1+=num
print(sum1)
while循环
num=1
sum1=0
while num<=100:
if num%3==0:
sum1+=num
num+=1
print(sum1)
计算1-100之间不能被7整除的数的和
for循环
sum1=0
for num in range(1,101):
if num%7!=0:
sum1+=num
print(sum1)
while循环
num=1
sum1=0
while num<=100:
if num%7!=0:
sum1+=num
num+=1
print(sum1)