100% ont trouvé ce document utile (1 vote)
980 vues4 pages

Introduction à Python pour 1ère année

Le document présente une introduction à la programmation avec le langage Python. Il décrit ce qu'est le code informatique et explique comment dessiner des formes géométriques de base à l'aide de la bibliothèque Turtle en Python.

Transféré par

Ahlem Kafela
Copyright
© All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PDF, TXT ou lisez en ligne sur Scribd
100% ont trouvé ce document utile (1 vote)
980 vues4 pages

Introduction à Python pour 1ère année

Le document présente une introduction à la programmation avec le langage Python. Il décrit ce qu'est le code informatique et explique comment dessiner des formes géométriques de base à l'aide de la bibliothèque Turtle en Python.

Transféré par

Ahlem Kafela
Copyright
© All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PDF, TXT ou lisez en ligne sur Scribd

CHAP3-INTRODUCTION A LA PROGRAMMAION 1ERE ANNEE

Introduction à la programmation
TP1- Python

• C’est quoi le code informatique ?


• Pourquoi programmer avec Python ?
• Que peut-on faire avec Python ?

1) Activité1 : Démarrer une recherche vidéo pour répondre à la question : ‘’C’est quoi le code
informatique’’

Savoir programmer, ou coder, c’est savoir créer des pages internet, des applications, des
logiciels, piloter des robots, des machines, des voitures, des trains, des outils…

Pour cette année le langage quand va utiliser s’appelle ………………………

2) Activité2 :
1) Lancer le l’éditeur de Python sur vos ordinateurs
2) Saisir les lignes (codes = instructions) ci-dessous:
# Code1
from turtle import*
color('red')
pensize(2)
speed(1)
Forward(100)
3) Enregistrer le fichier dans « D:\1S…G..\ essai1 »
4) Exécuter (visualiser) le résultat de ce code.
l’extension d’un fichier Python est ……
5) Ajouter au Code1 l’instruction suivante shape(‘turtle’) ,Que remarquez-vous ?

………………………………………………………………………………………………………………………….
6) Remplacer les instructions du code1 comme il est indiqué dans le tableau et en déduire le rôle
de chacune d’elle :
Code 1 Nouvelle instruction Rôle
color(‘red’) color(‘blue’) ……………………………………….
pensize(2) pensize(5) ……………………………………….
Speed(1) Speed(2) ……………………………………….
Forward(100) Circle(100)
Circle(100) Circle(100,180)

Lycée Gremda Page 1


CHAP3-INTRODUCTION A LA PROGRAMMAION 1ERE ANNEE
Activité3 : Référez-vous à la Mémoire de Turtle pour écrire le code qui permet de dessiner les
différents schémas demandés :

schéma code
Carré : From turtle import* ………………………………………………
Pensize(3) ………………………………………………………
Color(‘Blue’) ………………………………………………………
…………………………………………………… ………………………………………………………
……………………………………………………… ……………………………………………………
rectangle : ……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
triangle : ……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
L osange : ……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
Pentagone : ……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
Hexagone : ……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………

En déduire le code qui permet d’afficher une forme (carré, triangle, …) qui dépend de la valeur de x
(nombre de côtés)
Les entrées/sorties
x = int (……….('Donner le nombre de cotés')) forward(60)
for i in range(…….) left(…………….)

Lycée Gremda Page 2


CHAP3-INTRODUCTION A LA PROGRAMMAION 1ERE ANNEE
Aide-Mémoire Turtle

Instruction Rôle
From turtle import* Fait appel à la bibliothèque turtle
Shape(‘forme’) Définir la forme du curseur(tortue, fleche, cercle,….)
Color(‘coul’) Définir la couleur
speed(n) Definir la vitesse de la forme entre 0 et 10
Pensize(larg) Definir la taille du trait
Pencolor(‘coul’) Définir la couleur du pinceau
Left(angle)≠ Tourner à gauche/ droite
right(angle)
Goto(x,y) Se positionner selon les coordonnées x et y
up() ≠ down() Enlever / Reprendre le pinceau
Circle(rayon, angle) Dessiner un cercle de rayon R ou arc
Avancer x pixels
Forward(distance)

Backward(distance) Retour x pixels

Begin_fill() Démarre tracé du remplissage

Termine remplissage du tracé


End_fill()
Formes
Clear() Effacement de la zone de tracé arrow

Choisir la couleur de remplissage turtle


Fillcolor(coul)
circle
Va à la l’abscisse x
Setx(x) Square

Sety(y) Va à l’ordonné y triangle

Va à l’origine 0,0
Home()

Lycée Gremda Page 3


CHAP3-INTRODUCTION A LA PROGRAMMAION 1ERE ANNEE

étoile : ……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
Tableau : ……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
Arc : ……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………

Lune : ……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………

1. Créer le dodécagone suivant :

2. Créer le symbole des jeux olympique suivant :

3. Dessiner le drapeau japonais :

Lycée Gremda Page 4

Common questions

Alimenté par l’IA

Educators use exercises that involve drawing shapes with code to provide students with a practical application that combines logic, mathematics, and creativity. Drawing shapes requires understanding angles and lengths, implementing loops, and using conditionals, all core programming skills. Such exercises make abstract concepts more concrete, help visualize logical flow, and maintain student engagement through creativity .

Python code can be adapted to draw geometric shapes by adjusting the turtle's movements and the angles it turns. For instance, to draw a square, the code will include a loop where the turtle moves forward and turns 90 degrees four times. For a triangle, the turtle would turn 120 degrees instead. This adaptability demonstrates the use of loops and angle calculations to create various shapes .

Changing parameters in turtle graphics functions modifies the visual output. For instance, altering `color('red')` to `color('blue')` changes the drawing color, `pensize(2)` to `pensize(5)` makes the lines thicker, and increasing `speed(1)` to `speed(2)` results in faster drawing execution. These changes affect the appearance and speed of drawn images, allowing for precise control over graphic designs .

A logical approach involves running the code and observing the visual output and changes. By systematically modifying one instruction at a time, you can isolate and determine the effect of each. For example, changing `pensize` and noting line thickness, or altering `color` to see different drawing colors. Documenting observations facilitates understanding each command's purpose and its impact within the code structure .

Python is often chosen for introductory computer science courses because of its simplicity and readability, which makes it easier for beginners to grasp programming concepts. It is also versatile, allowing for the creation of web pages, applications, software, and control of machines and robots, as noted in activities related to its use . Its wide adoption in education is supported by its extensive libraries and community support, which enhance learning with practical tools and examples.

Saving and executing files facilitates comprehension of programming workflows, from writing code to executing and debugging it. It offers hands-on experience with file management, error handling, and seeing the relationship between code and output. This practice reinforces the understanding of development environments and the iterative nature of coding, where edits lead to improved results .

Teachers might employ visual learning through turtle graphics by illustrating how loops can automate repetitive tasks, like drawing shapes. Demonstrations where students alter loop parameters to see the impact on the drawing can enhance understanding. Educators can also use exercises where students manually code repeated sequences without loops, then refactor them with loops to appreciate efficiency gains and concept applicability .

The 'turtle' library is significant for beginners because it provides a visual and interactive way to understand programming concepts like loops, functions, and conditionals. It allows students to see immediate results of their code, making abstract concepts more tangible. This aids in learning by engaging students actively, as they receive direct feedback from the drawings they create .

Educators can assess students' comprehension by evaluating their ability to implement specific shapes using correct syntax and logic with turtle graphics. Assignments can include tasks that require compound shapes or customized parameters, reflecting deeper understanding of loops, conditionals, and functions. Feedback on creative projects can indicate the student's capacity to integrate programming concepts into artistic expressions, providing a holistic view of knowledge retention and application .

The statement `from turtle import*` imports all the functions and classes from the turtle module into the current namespace, allowing direct use of functions like `forward()`, `left()`, and others without prefixing them with `turtle.`. This simplifies code for beginners by reducing complexity and making the syntax easier to understand and use, fostering a smoother learning experience .

Vous aimerez peut-être aussi