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. OS 中文斜体 Italic Font Chinese - iOS_Girl

    CGAffineTransform matrix =  CGAffineTransformMake(1, 0, tanf(15 * (CGFloat)M_PI / 180), 1, 0, 0); UI ...

  2. nyoj 628 小媛在努力 【搜索】

    第一次是直接建一个10^7的数组 结果  内存大的要死.! 是不是能够不建数组 这下好了 小媛在努力 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描写叙述 在多媒体数据处理 ...

  3. App 签名过期或泄露怎么办?别担心,Google 已经给出解决方案!

    一.序 在将 App 发布到市场之前,很重要的一个步骤就是为 APK 进行签名,大部分时候,这个操作隐藏在了打包的流程中,而不被我们注意到. 签名的作用,除了证明 App 的所有权之外,还可以帮助 A ...

  4. C#之Action和Func的用法(转自 https://www.cnblogs.com/LipeiNet/p/4694225.html)

    以前我都是通过定义一个delegate来写委托的,但是最近看一些外国人写的源码都是用action和func方式来写,当时感觉对这很陌生所以看起源码也觉得陌生,所以我就花费时间来学习下这两种方式,然后发 ...

  5. jq 方法函数(淡入淡出,查找元素,过滤)遍历

    淡入淡出:fadeIn fadeOut fadeToggle fadeTo 淡入:fadeIn(speed[,callback])   速度和回调函数 回调函数可以写匿名函数,或者方法名不加括号. s ...

  6. POJ 3255 Roadblocks (Dijkstra求最短路径的变形)(Dijkstra求次短路径)

    Roadblocks Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16425   Accepted: 5797 Descr ...

  7. Linux 清空缓存

    sync echo 1 > /proc/sys/vm/drop_caches echo 2 > /proc/sys/vm/drop_caches echo 3 > /proc/sys ...

  8. RocketMQ学习笔记(2)----Broker的集群四种方式

    RocketMQ推荐了几种Broker集群方式,这里的Slave不可写,但可读,类似于Mysql主备方式 1. 单个Master 这是一种风险比较大的集群方式,因为一旦Borker重启或宕机期间,将会 ...

  9. 常用类Object,String类详解

    -------------------- String -----------------------1.求字符串长度 public int length()//返回该字符串的长度 String st ...

  10. (转)Java 虚拟机体系结构

    来源:http://hxraid.iteye.com/blog/676235 众所周知,Java源代码被编译器编译成class文件.而并不是底层操作系统可以直接执行的二进制指令(比如Windows O ...