zoukankan      html  css  js  c++  java
  • TurtleWorld Exercises

    1. Write a function called square that takes a parameter named t, which is a turtle. It should use the turtle to draw a square.

    from TurtleWorld import *
    def square(t):
        for i in range(4):
            fd(t,100)
            lt(t)
    
    TurtleWorld()
    bob = Turtle()
    square(bob)

    2. Add a parameter , named length, to square. Modify the body so length of the sides is length, and then modify the function call to provide a second argument.

    from TurtleWorld import *
    def square(t,length):
        for i in range(4):
            fd(t,length)
            lt(t)
    
    TurtleWorld()
    bob = Turtle()
    square(bob,50)

    3. Provide an argument to that specify the numbers of degrees. For example lt(bob,45) turns bob 45 degrees to the left.

    from TurtleWorld import *
    def polygon(t,length,degree):
        n = int(360/degree)
        for i in range(n):
            fd(t,length)
            lt(t,degree)
    
    TurtleWorld()
    bob = Turtle()
    polygon(bob,100,60)

    4. Write a function called circle that draws an approximative circle.

    from TurtleWorld import *
    import math
    def circle(t,r):
        for i in range(360):
            fd(t,int((2*math.pi*r)/360))
            lt(t,1)
            
    TurtleWorld()
    bob = Turtle()
    bob.delay = 0.01 # speed up bob to draw the circle
    circle(bob,100)

     

        

  • 相关阅读:
    使用DragonFly进行智能镜像分发
    Operator部署Prometheus
    kubernetes中部署Jenkins并简单使用
    kubernetes常用控制器之DaemonSet
    kubernetes中部署nacos
    selenium自动化操作
    BeautifulSoup爬取网页分页
    细品BeautifulSoup节点访问
    再端一碗BeautifulSoup
    初试爬虫
  • 原文地址:https://www.cnblogs.com/ryansunyu/p/3685806.html
Copyright © 2011-2022 走看看