练习
1.斐波那契数列
n = 8
n_1 = n_2 = result = 1
for x in range(3,n+1):
result = n_1 + n_2
n_2 = n_1
n_1 = result
print(result)
2.求100~200中间的素数
print('___________________')
sum1 = 0
for x in range(100,201):
count = 0
for y in range(2,x):
if x % y == 0:
count += 1
break
if count == 0:
print(x)
sum1 += 1
print('个数',sum1)
4.
fz = 2
fm = 1
for _ in range(20):
# print('%d/%d'%(fz,fm))
fz,fm = fz+fm,fz #fz,fm = 3,2 fz = 3, fm = 2
print('%d/%d'%(fz,fm))
5.
num = 12343543
count = 0
while num != 0:
count += 1
print(num%10)
num //=10
print(count)
day6 - 作业
1.
age = 30
if 0<age<=6:
print('幼儿')
elif 7<age<=12:
print('儿童')
elif 13<age<=24:
print('青年')
elif 25<age<=50:
print('中年')
else:
print('老年')
结果:
1.JPG
2.
print('______________')
num = 1
for x in range(1,6):
num *= x
print(num)
结果:
2.JPG
3.
print('3———————————————————————')
num = 1
sum1 = 0
for x in range(1,21):
num *= x
sum1 += num
print(sum1)
结果
3.JPG
4.
num = 1
sum1 = 0
for x in range(1,21):
num *= x
sum1 += 1/num
print(sum1)
结果:
4.JPG
5.
num = input('请输入一个大于0的数字(输入0结束):')
num = int(num)
sum1 = 0
while num != 0:
sum1 += num
num = input('请输入一个大于0的数字(输入0结束):')
num = int(num)
print('输入数字的和为:',sum1)
结果
5.JPG
6.
a = int(input('请输入a的值'))
n = int(input('请输入次数'))
m = 0
num = 0
sum1 = 0
sum2 = 0
while m < n:
while m < n:
num = a*10**m
sum1 += num
m += 1
print(sum1)
sum2 += sum1
m += 1
print('和:',sum2)
结果:
6.JPG
7.JPG
7.
a = int(input('输入第一个整数:'))
b = int(input('输入第二个整数:'))
c = int(input('输入第三个整数:'))
if a > b:
t = a
a = b
b = t
if b > c:
t = b
b = c
c = t
if a > b:
t = a
a = b
b = t
print(a,b,c)
结果:
8.JPG
8.
a.
n = 5
while n > 0:
# print('*')
m = n
while m > 0:
print('*',end = '')
m -= 1
n -= 1
print('\n')
结果:
9.JPG
n = 4
while n > 0:
# print('*')
m = n
while m > 0:
print('*',end = '')
m -= 1
n -= 1
print('\n')
结果
10.JPG
b.
网友评论