2018-07-19作业

读程序,总结程序的功能

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之间找出一个被21整除后不等于零同时能被3或者7整除的一个数


编程实现for和while各写一遍

1. 求1到100之间所有数的和、平均值

2. 计算1-100之间能3整除的数的和

3. 计算1-100之间不能被7整除的数的和

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)
    

你可能感兴趣的:(2018-07-19作业)