首页 > 代码库 > 附加作业01

附加作业01

题目一:

写一个符号金字塔。

代码:

while True:
q=eval(input("请输入金字塔的层数:"))
for i in range(1,q):
for k in range(i,q-1):
print(" ",end=" ")
j=2
while j<=2*i-1:
print("*",end=" ")
j=j+1
print("*\n")


题目二:

写一个图形金字塔。

代码:

import turtle
g=eval(input("塔的边长:"))
turtle.begin_fill()
turtle.fillcolor("blue")
turtle.forward(3*g)
turtle.left(120)
turtle.forward(g)
turtle.left(60)
turtle.forward(g*2)
turtle.right(120)
turtle.backward(g)
turtle.right(60)
turtle.end_fill()

turtle.penup()
turtle.forward(g*3)
turtle.left(120)
turtle.forward(g)
turtle.pendown()

turtle.begin_fill()
turtle.fillcolor("red")
turtle.forward(g)
turtle.left(60)
turtle.forward(g)
turtle.right(120)
turtle.backward(g)
turtle.end_fill()

turtle.penup()
turtle.forward(g)
turtle.pendown()

turtle.begin_fill()
turtle.fillcolor("yellow")
turtle.forward(g)
turtle.left(60)
turtle.backward(g)
turtle.end_fill()

turtle.backward(g*2)

附加作业01