tortue_2de_tp3.py

Created by jean-luc-poncin

Created on September 25, 2021

1.11 KB

Dessins avec la tortue où on répète plusieurs fois un motif de base :
- un escalier
- une étoile à 8 branches
- des pointillés
- des lignes parallèles
- un quadrillage
On utilise pour cela une boucle bornée (for) qui s’écrit en Python :

for i in range(...):     
    instruction 1      
    instruction 2      


from turtle import *

# Exercice 3.1

def dm():
  left(90)
  forward(20)
  right(90)
  forward(20)
  left(90)
  forward(20)
  right(90)
  forward(20)
  
# Exercice 3.2
    
def escalier():
  for i in range(4):
    left(90)
    forward(20)
    right(90)
    forward(20)

# Exercice 3.3

def etoile():
  for i in range(8):
    forward (70)
    backward(70)
    left(45)

# Exercice 3.4

def pointilles():
  for i in range(7):
    forward(10)
    penup()
    forward(10)
    pendown()
    
# Exercice 3.5

def lignes():
  for i in range(5):
    forward(140)
    backward(140)
    left(90)
    penup()
    forward(20)
    right(90)
    pendown()
    
# Exercice 3.6
    
def quadrillage():
  penup()
  left(180)
  forward(140)
  left(90)
  forward(80)
  left(90)
  pendown()
  for i in range(9):
    forward(280)
    backward(280)
    left(90)
    penup()
    forward(20)
    right(90)
    pendown()
  penup()
  right(90)
  forward(180)
  right(180)
  pendown()
  for i in range(15):
    forward(160)
    backward(160)
    penup()
    right(90)
    forward(20)
    left(90)
    pendown()
    
    
    
 
  
  

    
  
  

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.