讀程序耸弄,總結(jié)程序的功能
1.
numbers=1
for x in range(0,20):
numbers*=2
print(numbers)
功能:求出number的range()次方
2.
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之間找出一個(gè)被21整除后不等于零同時(shí)能被3或者7整除的一個(gè)數(shù)
編程實(shí)現(xiàn)for和while各寫一遍
1. 求1到100之間所有數(shù)的和、平均值
2. 計(jì)算1-100之間能3整除的數(shù)的和
3. 計(jì)算1-100之間不能被7整除的數(shù)的和
1.
number1=0
for x in range(1,101):
number1+=x
print(number1)
number = 1
sum1 = 0
while number <= 100:
sum1 += number
number += 1
print(sum1)
print(number1/100)
print(sum1/100)
mmm=0
for x in range(1,100):
if x % 3 ==0:
mmm+=x
print(mmm)
num=0
number=1
while number<=100 :
if number % 3 ==0:
num+=number
num+=1
print(num)
num=0
for x in range(1,100):
if x% 7 !=0:
num+=x
print(num)
num=0
number=1
while number<=100:
if number %7 !=0:
num+=number
num+=1
print(num)