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 来 说,这两个 ...
随机推荐
- scp报错:Host key verification failed. REMOTE HOST IDENTIFICATION HAS CHANGED!
1 scp报错:REMOTE HOST IDENTIFICATION HAS CHANGED! [root@xx ~]# scp yum-3.4.3.tar.gz 10.xx.xx.12:/root ...
- Yocto tips (19): Yocto SDK Toolchian的使用
在使用之前须要先source env,导入各种环境变量(注意将路径变更成你自己的): source ../qt5_sdk/environment-setup-cortexa9hf-vfp-neon-p ...
- video_capture模块分析
1. 对外接口 VideoCaptureModule 控制接口 VideoCaptureDataCallback Vie中的ViECapturer继承,用于响应抓包数据 2 ...
- Java知识点解析
JAVA 1:简述Java的基本历史 java起源于SUN公司的一个GREEN的项目,其原先目的是为家用消费电子产品 发送一个信息的分布式代码系统,通过发送信息控制电视机.冰箱等. 2:简单写出Jav ...
- UVA 1016 - Silly Sort 置换分解 贪心
Silly Sort Your younger brother has an assignment and needs s ...
- 07:清泉-改(prime+堆)
时间限制: 10000ms 单个测试点时间限制: 1000ms 内存限制: 512000kB 描述 华北电力大学可以抽象为一张有n个点m条边的无向图. 现在所有的边都断了. 修复每条边都有个不同 ...
- MySQL学习(三)——Java连接MySQL数据库
1.什么是JDBC? JDBC(Java DataBase Connectivity)就是Java数据库连接,说白了就是用Java语言来操作数据库.原来我们操作数据库是在控制台使用SQL语句来操作数据 ...
- 【转载】HTTP Session 内存到内存复制的拓扑结构
http://www.oschina.net/question/129540_23215 HTTP 协议本身是“连接 - 请求 - 应答 - 关闭连接”的模式,是一种无状态协议:然而随着 web 动态 ...
- cuda float atomic操作
atomic add.用第二个,暂时还没弄明白 #ifdef FLOAT #define T float #else #define T int #endif #ifdef FORUM __devic ...
- HDU 1338 Game Prediction【贪心】
解题思路: 给出 n m 牌的号码是从1到n*m 你手里的牌的号码是1到n*m之间的任意n个数,每张牌都只有一张,问你至少赢多少次 可以转化为你最多输max次,那么至少赢n-max次 而最多输max ...