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. Picking up Jewels

    Picking up Jewels There is a maze that has one entrance and one exit.  Jewels are placed in passages ...

  2. [JZOJ 4307] [NOIP2015模拟11.3晚] 喝喝喝 解题报告

    题目链接: http://172.16.0.132/senior/#main/show/4307 题目: 解题报告: 题目询问我们没出现坏对的连续区间个数 我们考虑从左到有枚举右端点$r$,判断$a[ ...

  3. requireJS实现原理分析

    下面requireJS实现的基本思路  项目地址https://github.com/WangMaoling/require var require = (function(){ //框架版本基本信息 ...

  4. Win7 如何禁用“切换用户”功能

    1.按win+r,输入gpedit.msc,点击确定: 2.依次点击计算机配置--管理模块--系统--登录,右侧列表中找到“隐藏“快速用户切换”的入口点”: 3.双击隐藏“快速用户切换”的入口点,点击 ...

  5. spline interpolation and draw image by matplotlib

    1 # spline interpolation and draw image by matplotlib from scipy import interpolate import matplotli ...

  6. lua中调用C++函数

    lua中调用C++函数 我们产品中提供了很多lua-C API给用户在lua中调用,之前一直没用深究其实现原理,只是根据已有的代码在编码.显然这不是一个好的习惯,没用达到知其所以然的目的. 一.基本原 ...

  7. span文本自动换行

    .span{ word-wrap: break-word; word-break: break-all; overflow: hidden; }

  8. Unable to load annotation processor factory

    很多人在项目开发中都会遇到项目名称左上角有个红叉,有些是Jar问题,有些是代码问题,有些是编译问题,对于我这种强迫症的是受不了这种情况发生的,如果不影响项目启动还好,废话少说,今天工作就出现了一个问题 ...

  9. c标签迭代Map

    <%@ page import="java.util.Map" %> <%@ page import="java.util.HashMap" ...

  10. php xml 的基本操作类

    class xmlMessage{ protected $doc; protected $rootKey; public function __construct() { $this->doc ...