1。乘法表
test2():
for i in range(1, 10):
print()
for j in range(1, i+1):
#print("%d*%d=%d" % (j, i, j*i),end='\t')
print("{}*{}={}".format(i,j,i*j), end="\t")
if __name__ == '__main__':
test2()
2。斐波那契数列
# 获取用户输入数据
nterms = int(input("你需要几项?"))
# 第一和第二项
n1 = 1
n2 = 1
count = 2
# 判断输入的值是否合法
if nterms <= 0:
print("请输入一个正整数。")
elif nterms == 1:
print("斐波那契数列:")
print(n1)
else:
print("斐波那契数列:")
print(n1,",",n2,end=" , ")
while count < nterms:
nth = n1 + n2
print(nth,end=" , ")
# 更新值
n1 = n2
n2 = nth
count += 1
3。微信智能回复机器人
4。python绘制五角星-turtle
import turtle #导入turtle库包
turtle.fillcolor("red") #填充颜色
turtle.begin_fill() #开始画,类似起笔
count = 1 #计时器,用于计录次数
while count <= 5: #控制绘制次数
turtle.forward(100) #画笔绘制的方向,向前移动指定的距离
turtle.right(144) #向右转144度
count += 1 #循环绘制
turtle.end_fill() #完成填充图片的绘制。