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)

    

TurtleWorld Exercises的更多相关文章

  1. [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]Contents

    I find it may cost me so much time in doing such solutions to exercises and problems....I am sorry t ...

  2. 46 Simple Python Exercises (前20道题)

    46 Simple Python Exercises This is version 0.45 of a collection of simple Python exercises construct ...

  3. State Estimation for Robotics (Tim Barfoot) exercises Answers

    Here are some exercises answers for State Estimation for Robotics, which I did in June, 2017. The bo ...

  4. Linux command line exercises for NGS data processing

    by Umer Zeeshan Ijaz The purpose of this tutorial is to introduce students to the frequently used to ...

  5. 100 numpy exercises

    100 numpy exercises A joint effort of the numpy community The goal is both to offer a quick referenc ...

  6. 46 Simple Python Exercises-Very simple exercises

    46 Simple Python Exercises-Very simple exercises 4.Write a function that takes a character (i.e. a s ...

  7. Python TurtleWorld configuration and simple test

    TurtleWorld provides a set of functions for drawing lines by steering turtles around the screen. You ...

  8. Exercises for IN1900

    Exercises for IN1900October 14, 2019PrefaceThis document contains a number of programming exercises ...

  9. Coroutine 练习 1 - Coroutine Exercises 1

    Coroutine 练习 1 - Coroutine Exercises 1 字典中为动词 “to yield” 给出了两个释义:产出和让步.对于 Python 生成器中的 yield 来 说,这两个 ...

随机推荐

  1. Nginx系列(四)--工作原理

    上篇文章介绍了Nginx框架的设计之管理进程以及多个工作进程的设计.master进程用来管理通过fork子进程与子进程通信.子进程通过处理进程信号接到master的通信去处理请求. Nginx工作原理 ...

  2. Android笔记三十三.BroadcastReceiver使用

        广播是一种广泛运用在应用程序之间传输信息的机制,而BroadcastReceiver是对发送出来的广播进行过滤接收并响应的一类组件. BroadcastReceiver本质上是一种全局监听器. ...

  3. Combobox下拉框两级联动

    下拉框的两级联动是我们开发中经常遇到一种情况.比如一个学生管理系统中,根据年级.科目及姓名查询学生考试成绩,年级和科目都是硬盘中的有限数据(数据库)而学生则可以有用户手动指定,这时在数据库中有年级和科 ...

  4. shell编程笔记1

    参考文章:1 http://blog.csdn.net/wuwenxiang91322/article/details/9259877   通过chmod改变文件权限 补充知识: 1Linux文件的三 ...

  5. python中的json

    import json# dumps #一般处理字符串# dump #一般处理文件 #字符串和json之间的转换test_dict={"name":"fxh", ...

  6. SpringBoot学习笔记(1)----环境搭建与Hello World

    简介: Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配 ...

  7. [HNOI2008]越狱 快速幂 逆推

    考虑越狱的情况有些复杂,不如考虑总情况减去不越狱的情况. 显然,总情况为 $m^n$ 种,不越狱的情况为 $m*(m-1)*(m-1)*(m-1)....$ 即为 $m*(m-1)^(n-1)$. 做 ...

  8. ajax错误信息

    XMLHttpRequest.status状态码 1xx-信息提示 这些状态代码表示临时的响应.客户端在收到常规响应之前,应准备接收一个或多个1xx响应. 100-继续. 101-切换协议. 2xx- ...

  9. 模块 -logging

    模块 -logging 一:在控制台显示:默认 import logging logging.debug("debug") logging.info("debug&quo ...

  10. Vue 中 换行符获取

    当要获取到 vue 中 文本域的换行符时, 需要用到正则匹配. let reg = new RegExp('/n',"g"); let str = text.replace(reg ...