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)
TurtleWorld Exercises的更多相关文章
- [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 ...
- 46 Simple Python Exercises (前20道题)
46 Simple Python Exercises This is version 0.45 of a collection of simple Python exercises construct ...
- 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 ...
- 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 ...
- 100 numpy exercises
100 numpy exercises A joint effort of the numpy community The goal is both to offer a quick referenc ...
- 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 ...
- Python TurtleWorld configuration and simple test
TurtleWorld provides a set of functions for drawing lines by steering turtles around the screen. You ...
- Exercises for IN1900
Exercises for IN1900October 14, 2019PrefaceThis document contains a number of programming exercises ...
- Coroutine 练习 1 - Coroutine Exercises 1
Coroutine 练习 1 - Coroutine Exercises 1 字典中为动词 “to yield” 给出了两个释义:产出和让步.对于 Python 生成器中的 yield 来 说,这两个 ...
随机推荐
- HDU 4301 Contest 1
开始时设的是第一.二行前i,j列有k种的方法数,但是,这根本转移不了--! 难点在于1,2行的讨论啊... 设f[i][j][0]为前i列分成j个部分,且第i列的两个为同一部分的方法数. f[i][j ...
- Android内存优化之封装九宫格
随着市场上越来越多的APP上线,好多软件对手机的内存要求也是很大,所以我们在开发的时候一定要掌握如何去优化内存,将自己的APP尽可能优化.今天我们就一起看一下九宫格的优化.下面是软件的截图 1.为了达 ...
- Android Java 程序员必备开发工具
对于Java,有两种截然不同的观点:一种认为Java是最简单功能最强大的编程语言之一,另一种则表示这种编程语言既难用又复杂. 下面这些工具或许功能和作用不同,但是有着一个共同的主旨,那就是——它们都是 ...
- C++ Primer Plus的若干收获--(九)
这篇博文我接着上一篇来写,相同讲一些关于类的一些基础知识. 本篇将会继续使用上篇的股票类STock,这里给出接口 ifndef STOCKOO_H_ #define STOCKOO_H_ #inclu ...
- 朝花夕拾——finally/final/finalize拨云雾见青天
Java编程中.常常会使用到异常处理,而finally看似的是try/catch后对逻辑处理的完好,事实上里面却存在非常多隐晦的陷阱.final常见于变量修饰,那么你在内部类中也见过吧.finaliz ...
- POJ 题目3237 Tree(Link Cut Tree边权变相反数,求两点最大值)
Tree Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 6131 Accepted: 1682 Description ...
- ubuntu 下的文件校验(md5、sha256)
在本地使用 md5sum/sha256sum 生成某待测文件的 hash 值,以跟标准文件的 hash 值做对比验证,确定经网络传输过程得到的文件是否真实无损.一般而言,hash 值如果一致,大概率上 ...
- 91.Bower : ENOGIT git is not installed or not in the PATH 解决方法
转自:https://www.haorooms.com/post/bower_error 今天在用bower安装依赖的时候,出现了Bower : ENOGIT git is not installed ...
- iOS开发-Tools-CocoaPods
CocoaPods是什么? 当你开发iOS应用时,会经常使用到很多第三方开源类库,比如JSONKit,AFNetWorking等等.可能某个类库又用到其他类库,所以要使用它,必须得另外下载其他类库,而 ...
- 浏览器输入一个url的过程,以及加载完html文件和js文件的标志
简单理解: 当在浏览器地址栏输入一url时,浏览器会做以下几个步骤: 1.将url转化为ip地址,也就是DNS解析,(先找本地host文件中是否有对应的ip地址,如果有就直接用,没有的话,就按域名的二 ...