turtle模块的使用练习(例子是书本的)
2020-03-25 14:51 作者:一心想当网红的李老师 | 我要投稿
今天学习了一下《head first 编程之旅 python语言描述》这本书的函数、模块、类和对象的内容。
因为最初学的是C语言,所以没有这方面的概念。虽然感觉和C的数据结构有点类似,但是还是存在区别的。所以使用了一下书本的例子,稍微有点感觉。
import turtle
slowpoke=turtle.Turtle()
slowpoke.shape("turtle")
pokey=turtle.Turtle()
pokey.shape("turtle")
pokey.color('red')
####定义一个函数
def make_square(the_turtle):
for i in range (0,4):
the_turtle.forward(100)
the_turtle.right(90)
###定义第二个函数,并且套用了第一个函数。这次总算理解了一点,函数套用的方法。
def make_sprial(the_turtle):
for i in range (0,36):
make_square(the_turtle)
the_turtle.right(10)
make_sprial(slowpoke)
pokey.right(5)
make_sprial(pokey)
turtle.mainloop()