1 / 4

from turtle import* for i in range(5): rt (72) fd (100)

We start by importing the turtle command library from turtle import*. This programming loop uses the FOR instruction. This works like the REPEAT command. The i is a variable which is used to count the steps in the loop don’t confuse i with a 1

daxia
Télécharger la présentation

from turtle import* for i in range(5): rt (72) fd (100)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. We start by importing the turtle command library from turtle import* This programming loop uses the FOR instruction. This works like the REPEAT command. The iis a variable which is used to count the steps in the loop don’t confuseiwith a 1 For i in range (4)Is the same as saying Repeat 4 Notice that the repeat 5 [rt72 fd 100] We use the TAB key to indent from turtle import* for i in range(5): rt(72) fd(100) We then start programming the turtle using the Command instructions and parameters Lets look at a blockly example to compare loops

  2. a= 0 for i in range(5): a=a+1 print a from turtle import* import turtle import time import random turtle.up turtle.begin_fill() pencolor('blue') turtle.color(random.random(),random.random(), random.random()) i=0 while (i<5): rt(72) fd(100) i=i+1 turtle.end_fill() time.sleep(2) turtle.bye()

  3. from turtle import * color('red', 'yellow') begin_fill() while True: forward(200) left(170) if abs(pos()) < 1: break end_fill() done() Use this for help sheet. http://www.eg.bucknell.edu/~hyde/Python3/TurtleDirections.html

  4. print ("This program draws shapes based on the number you enter in a uniform pattern.") num_str = input("Enter the side number of the shape you want to draw: ") if num_str.isdigit(): squares = int(num_str) angle = 180 - 180*(squares-2)/squares turtle.up x = 0 y = 0 turtle.setpos(x,y) numshapes = 8 for x in range(numshapes): turtle.color(random.random(),random.random(), random.random()) x += 5 y += 5 turtle.forward(x) turtle.left(y) for i in range(squares): turtle.begin_fill() turtle.down() turtle.forward(40) turtle.left(angle) turtle.forward(40) print (turtle.pos()) turtle.up() turtle.end_fill() turtle.begin_fill() # Begin the fill process. turtle.down() # "Pen" down? for i in range(squares): # For each edge of the shape turtle.forward(40) # Move forward 40 units turtle.left(angle) # Turn ready for the next edge turtle.up() # Pen up turtle.end_fill() # End fill.

More Related