1、将一个列表的数据复制到另一个列表中。
a = [1, 2, 3]
b = a[:]
print (a)
print (b)
![](/i/l/?n=22&i=blog/1189851/202211/1189851-20221114114108408-1318839238.png)
2、输出 9*9 乘法口诀表
for i in range(1, 10):
print()
for j in range(1, i+1):
print ("%d*%d=%d" % (i, j, i*j), end=" " )
![](/i/l/?n=22&i=blog/1189851/202211/1189851-20221114151127220-439521282.png)
for i in range(9,0,-1):
print()
for j in range(1, i+1):
print ("%d*%d=%d" % (i, j, i*j), end=" " )
![](/i/l/?n=22&i=blog/1189851/202211/1189851-20221114151210253-13606332.png)
for i in range(1,10):
for j in range(i,9):
print(" ",end=" ")
for k in range(1,i+1):
print("%d*%d=%2d" % (i, k, i * k), end=" ")
print()
![](/i/l/?n=22&i=blog/1189851/202211/1189851-20221114151245017-1889146321.png)
for i in range(9,0,-1):
for j in range(i,9):
print(" ",end=" ")
for k in range(1,i+1):
print("%d*%d=%2d" % (i, k, i * k), end=" ")
print()
![](/i/l/?n=22&i=blog/1189851/202211/1189851-20221114151315422-592563119.png)
3、暂停一秒输出。
import time
my_dict = {1:'A',2:'B'}
for key,value in dict.items(my_dict):
print(key,value)
time.sleep(1)
![](/i/l/?n=22&i=blog/1189851/202211/1189851-20221114152305930-1812504208.png)
4、暂停一秒输出,并格式化当前时间。
import time
time.sleep(1)
print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))
![](/i/l/?n=22&i=blog/1189851/202211/1189851-20221114152246332-319512942.png)
5、有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少??
兔子的规律为数列1,1,2,3,5,8,13,21....
f1 = 1
f2 = 1
for i in range(1,22):
print('%12ld %12ld' %(f1,f2),end=" ")
if(i % 3) == 0:
print(' ')
f1 = f1+f2
f2 = f2+f1
6、判断101-200之间有多少个素数,并输出所有素数。
def Ispri(n):
if n <= 1:
return False
for i in range(2,n):
if n%i == 0:
return False
return True
list = []
for i in range(101,201):
if Ispri(i) == True:
list.append(i)
print(list)
7、打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。
例如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方。
for i in range(100,1000):
ge = i % 10
shi = i // 10 % 10
bai = i // 100
if i == ge ** 3 + shi ** 3 + bai ** 3 :
print(i,end=" ")
8、将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5。
分解质因数需要从最小的质数2开始除,直到最后一个因数相除结果为1(即除以本身)
num = int(input("请输入一个数:"))
n = num
list = []
while num != 1:
for i in range(2,num+1):
if num % i == 0:
list.append(i)
num = int(num / i)
if num == 1:
break
print(n,"=","*".join('%s' %id for id in list))
标签:10,end,题二,f1,练练,没事,range,num,print From: https://www.cnblogs.com/liyongmei/p/16888520.html