python基础运用画彩虹,打印99乘法表,打印金字塔
程序员文章站
2022-03-11 12:44:22
...
#打印金字塔
ceng = eval(input("请输入要打印的层数"))
for x in range(ceng):
for y in range(ceng-x):
print("",end=' ')
for z in range(x+1):
print("*",end="")
for l in range(x):
print("*",end="")
print("\n",end="")
``
```python
#输出9*9乘法表
for i in range(9):
x = i + 1
for y in range(i+1):
l = y + 1
print("%d*%d=%2d"%(x,l,x*l),end=" ")
print("")
#画彩虹
import turtle
turtle.speed(10)
c = ['red','orange','yellow','green','Cyan','blue','Purple']
for i in range(7):
y=6-i
turtle.pencolor(c[y])
turtle.pensize(20)
turtle.penup()
turtle.right(90)
turtle.goto(-20*(i+1),0)
turtle.down()
turtle.circle(20*(i+1),-180)
turtle.right(-(90+(180)))
turtle.done()
上一篇: 有关vw单位的文章推荐10篇