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.

  1. from TurtleWorld import *
  2. def square(t):
  3. for i in range(4):
  4. fd(t,100)
  5. lt(t)
  6.  
  7. TurtleWorld()
  8. bob = Turtle()
  9. 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.

  1. from TurtleWorld import *
  2. def square(t,length):
  3. for i in range(4):
  4. fd(t,length)
  5. lt(t)
  6.  
  7. TurtleWorld()
  8. bob = Turtle()
  9. 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.

  1. from TurtleWorld import *
  2. def polygon(t,length,degree):
  3. n = int(360/degree)
  4. for i in range(n):
  5. fd(t,length)
  6. lt(t,degree)
  7.  
  8. TurtleWorld()
  9. bob = Turtle()
  10. polygon(bob,100,60)

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

  1. from TurtleWorld import *
  2. import math
  3. def circle(t,r):
  4. for i in range(360):
  5. fd(t,int((2*math.pi*r)/360))
  6. lt(t,1)
  7.  
  8. TurtleWorld()
  9. bob = Turtle()
  10. bob.delay = 0.01 # speed up bob to draw the circle
  11. 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. UNIX环境高级编程(6):文件I/O(2)

    文件共享: UNIX系统支持在不同进程间共享打开的文件. 内核使用三种数据结构表示打开的文件.他们之间的关系决定了在文件共享方面一个进程对还有一个进程可能产生的影响: (1)每一个进程在进程表中都有一 ...

  2. 开源ETL工具kettle--数据迁移

    背景 因为项目的需求,须要将数据从Oracle迁移到MSSQL,不是简单的数据复制,而是表结构和字段名都不一样.甚至须要处理编码规范不一致的情况,例如以下图所看到的 watermark/2/text/ ...

  3. Android_通过Bugtags平台,方便測试人员提交bug及整个bug系统的管理

    Bugtags 是什么? Bugtags 是一款缺陷发现及管理工具. 当您的 App 集成了 Bugtags SDK 后,測试人员就可直接在 App 里所见即所得的提交 Bug. SDK 会自己主动截 ...

  4. Android-Volley网络通信框架(自己定义Request 请求:实现 GsonRequest)

    1.回想 上篇学习了android 通过 volley 网络通信框架 实现 请求图片的三种方法! 2.重点 (1)复习和熟悉 StringRequest ,JsonObjectRequest 方法 ( ...

  5. POJ 3657 并查集

    题意: 思路: 1.二分+线段树(但是会TLE 本地测没有任何问题,但是POJ上就是会挂--) 2.二分+并查集 我搞了一下午+一晚上才搞出来----..(多半时间是在查错) 首先 如果我们想知道这头 ...

  6. Sql Server创建外键失败

    问题: 已成功保存“PPR_BasicInformation”表“PPR_PS”表- 无法创建关系“FK_PPR_PS_PPR_BasicInformation”. ALTER TABLE 语句与 F ...

  7. jQuery学习(三)——选择器总结

    1.基本选择器 id选择器:$(“#id名称”); 元素选择器:$(“元素名称”); 类选择器:$(“.类名”); 通配符:* 多个选择器共用(并集) 案例代码: <!DOCTYPE html& ...

  8. SQL 的stuff函数

    1.作用 删除指定长度的字符,并在指定的起点处插入另一组字符. 2.语法 STUFF ( character_expression , start , length ,character_expres ...

  9. UWP连接mysql 实现数据远程备份

    昨晚吃饭的时候突然觉得我们这个UWP应该添个数据备份的功能,不然换手机,换电脑之后数据库就全没了... 一开始是想用微软提供的AZURE的,没想到这玩意又没什么资料而且申请试用的时候还让我交身份证照片 ...

  10. HDU 1754 I Hate It【线段树 单点更新】

    题意:给出n个数,每次操作修改它的第s个数,询问给定区间的数的最大值 把前面两道题结合起来就可以了 自己还是敲不出来------------- #include<iostream> #in ...