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 来 说,这两个 ...
随机推荐
- Linux操作系统是如何工作的
<实验五——Linux操作系统是如何工作的?破解操作系统的奥秘> 姓名:方超 学号:SA12**6201 Linux操作系统工作的基础 存储程序计算机.堆栈(函数调用堆栈)机制和中断机制是 ...
- POJ 3368 线段树
思路: 先统计在第i个位置当前数字已经出现的次数. 维护两个数组,一个是当前位置的数字最后一次出现的位置,另一个是当前位置的数字第一次出现的位置 查找的时候分为两种情况: 没有和边界相交(意会意会)的 ...
- Fork and Join: Java Can Excel at Painless Parallel Programming Too!---转
原文地址:http://www.oracle.com/technetwork/articles/java/fork-join-422606.html Multicore processors are ...
- ASP页面的执行顺序
http://hi.baidu.com/yanjiezhu/item/29c113c3912e2a0ac710b2d3 1.对象初始化(OnInit方法) 页面中的控件(包括页面本身)都是在它们最初的 ...
- Appserv 2.5.10 升级PHP from version 5.2 to 5.3
解决方案查看 该文章:http://blog.csdn.net/dull_boy2/article/details/43927363
- HTML 导航框架
首页效果图 点击链接一效果图 代码结构 index.jsp <%@ page language="java" import="java.util.*" p ...
- GDOI2016酱油记(补发)
这篇酱油记是前年发在MCHacker一个叫code-hub的博客上的(已崩),现在来补发一下... GDOI2016扯淡(爆零记) 大家好,我是巨弱DCDCBigBig,在五一期间和一群神牛去考GDO ...
- SP687 REPEATS - Repeats(后缀数组)
一个初步的想法是我们枚举重复子串的长度\(L\).然后跑一遍SA.然后我们枚举一个点\(i\),令他的对应点为\(i+L\),然后求出这两个点的LCP和LCS的长度答案就是这个点的答案就是\((len ...
- 安装 glusterfs yum源报错
yum install glusterfs-server yum 一直报错 把/etc/yum.repos.d 备份 删除了所有文件,从测试机192..168.59.128上同步过来 一直报错 已加载 ...
- 紫书 习题 8-15 UVa 1617 (贪心)
先排序, 然后每个线段先放右端点, 然后往下放, 如果不能放就整体往左移动, 当不能往左移动的时候就ans++ 开始下一个整块.判断能不能向左移动要用一个变量储存每个已经放了的区间中线段与左端点距离的 ...