day4作业

基础

1.求1x2的20次方,并打印结果;

2.求1到100中,能被3或者7整除但是不能被21整除的的数的个数

sum1 = 0
for x in range(1, 101):
    sum1 += x
avg1 = sum1 / 100
print('和:{},平均值:{}'.format(sum1, avg1))

x = 0
sum2 = 0
while 1:
    x += 1
    sum2 += x
    if x == 100:
        break
avg2 = sum2 / x
print('和:{},平均值:{}'.format(sum2, avg2))
sum3 = 0
for x in range(1, 101):
    if x % 3 == 0:
        sum3 += x
print('和:', sum3)

x = 1
sum4 = 0
while 1:
    x += 1
    if x % 3 == 0:
        sum4 += x
    elif x == 100:
        break
print('和:', sum4)
sum5 = 0
for x in range(1, 101):
    if x % 7 != 0:
        sum5 += x
print('sum5和:', sum5)

x = 0
sum6 = 0
while 1:
    x += 1
    if x == 101:
        break
    elif x % 7 != 0:
        sum6 += x
print('sum6和:', sum6)
提高
age = int(input('请输入年龄:'))
if age <= 0 or age >= 150:
    print('年龄不合法')
elif age <= 8:
    print('儿童')
elif age <= 16:
    print('未年人')
elif age <= 35:
    print('青壮年')
elif age <= 50:
    print('中年')
else:
    print('老年')
x = 1
for i in range(1,6):
    x *= i
print(x)
x = 1
sum1 = 0
for i in range(1,21):
    x *= i
    sum1 += x
print(sum1)
x = 1
sum2 = 0
for i in range(1,21):
    x *= i
    sum2 += 1/x
print(sum2)
sum3 = 0
while 1:
    x = int(input('请输入大于0的数:'))
    if x == 0:
        break
    elif x > 0:
        sum3 += x
    else:
        print('请输入大于0的数')

你可能感兴趣的:(day4作业)