How to think like a Computer Scientist: 课后习题第四章 2题

#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Author:      penglaixy
#
# Created:     27/07/2013
# Copyright:   (c) penglaixy 2013
# Licence:     <your licence>
#-------------------------------------------------------------------------------
import turtle
__import__("turtle").__tracealbe__=False
import time
__import__("time").__tracealbe__=False


def main():


    def make_window(colr, ttle):
        '''
        set up the window with the given background color and title
        '''
        w = turtle.Screen()
        w.bgcolor(colr)
        w.title(ttle)
        return w


    def make_turtle(colr, sz):
        '''
        set up a turtle with the given color and pensize
        '''
        t = turtle.Turtle()
        t.color(colr)
        t.pensize(sz)


        return t


    def draw_square(t, sz):
        ''' Make turtle t draw a square of sz'''
        for i in range(4):
            t.forward(sz)
            t.left(90)


    wn = make_window('lightgreen','''yuxiangyang's testing''')


    alex = make_turtle('navy blue', 5)


    for j in range(5):
        draw_square(alex, (j+1)*20)
        alex.penup()
        alex.right(90)
        alex.forward(10)
        alex.right(90)
        alex.forward(10)
        alex.right(180)
        alex.pendown()


    time.sleep(8)
    wn.bye()


if __name__ == '__main__':
    main()





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值