条件、循环、函数定义 练习
a.
import turtle turtle.fillcolor("yellow") turtle.begin_fill() for i in range(5): turtle.forward(100) turtle.right(144) turtle.end_fill() turtle.hideturtle()
b.
import turtle for i in range(5): turtle.up() turtle.goto(0,-20*(i+1)) turtle.down() turtle.circle(20*(i+1)) turtle.hideturtle()
c.
from turtle import* color('red','yellow') begin_fill() while True: forward(300) left(170) if (abs(pos()))<1: break end_fill() done()
d.
import turtle turtle.bgcolor('red') def m_goto(x,y): turtle.up() turtle.goto(x,y) turtle.down() def m_draw(r): turtle.pencolor('yellow') turtle.fillcolor('yellow') turtle.begin_fill() for i in range(5): turtle.forward(r) turtle.right(144) turtle.end_fill() m_goto(-550,180) m_draw(150) m_goto(-295,250) turtle.left(50) m_draw(50) m_goto(-220,173) turtle.left(44) m_draw(50) m_goto(-190,80) turtle.left(50) m_draw(50) m_goto(-250,50) turtle.left(50) m_draw(50) turtle.hideturtle() turtle.done()
e.
import turtle turtle.speed(10) turtle.fillcolor("yellow") turtle.pencolor("red") turtle.begin_fill() def draw_leng(): for i in range(1,3): turtle.forward(100) turtle.right(45) turtle.forward(100) turtle.right(135) for i in range(1,37): draw_leng() turtle.right(10) turtle.end_fill() turtle.right(90) turtle.forward(300) turtle.hideturtle()