Skip to content

Commit

Permalink
solutions while
Browse files Browse the repository at this point in the history
  • Loading branch information
LoicGrobol committed Feb 27, 2024
1 parent 0b9c1c0 commit 5b6964c
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 5 deletions.
3 changes: 3 additions & 0 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ courant si vous n'avez pas le choix et je ferai de mon mieux pour vous permettre

- {% notebook_badges slides/03-turtle/turtle.py.md %}
[Notebook `turtle`]({{site.url}}{{site.baseurl}}/slides/03-turtle/turtle.py.ipynb)
- [Solutions]({{site.url}}{{site.baseurl}}/slides/03-turtle/solutions.py)
- {% notebook_badges slides/05-td_while/td_while.py.md %}
[Notebook `while`]({{site.url}}{{site.baseurl}}/slides/05-td_while/td_while.py.ipynb)
- {% notebook_badges slides/05-td_while/solutions.py.md %}
[Solutions]({{site.url}}{{site.baseurl}}/slides/05-td_while/solutions.py.ipynb)

### 2024-02-13 : Exercices récapitulatifs

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ipywidgets
jinja2 >= 3.0.0, < 3.2.0
jupyterlab
jupyterlab-rise
jupytext
nbconvert
nbtutor
Expand Down
23 changes: 18 additions & 5 deletions slides/07-fonctions/fonctions.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jupyter:
extension: .md
format_name: markdown
format_version: '1.3'
jupytext_version: 1.14.5
jupytext_version: 1.16.1
kernelspec:
display_name: Python 3 (ipykernel)
language: python
Expand Down Expand Up @@ -58,10 +58,10 @@ Thonny (où ils s'affichent dans la zone d'édition) et les exécuter avec le bo
<!-- #region slideshow={"slide_type": "subslide"} -->
Les commandes de base en `turtle` :

- `forward(d)` avance de d pixels
- `backward(d)` recule de d pixels
- `left(a)` pivote vers la gauche de a degrés
- `right(a)` pivote vers la droite de a degrés
- `forward(d)` avance de `d` pixels
- `backward(d)` recule de `d` pixels
- `left(a)` pivote vers la gauche de `a` degrés
- `right(a)` pivote vers la droite de `a` degrés
- `up()` relève le crayon pour avancer sans dessiner
- `down()` abaisse le crayon pour dessiner
- `reset()` remet le dessin à zéro
Expand Down Expand Up @@ -595,3 +595,16 @@ ma_fonction(15)
print()
ma_fonction(a="machin")
```

```python
def machin():
print(a)

a = 15

machin()

a = 20

machin()
```
30 changes: 30 additions & 0 deletions slides/07-fonctions/koch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import turtle

turtle.speed("fast")


def segment_koch(l, n):
"""Trace un des cotés du flocon à l'ordre `n`, de longueur `l` en partant de la
position courante et dans la direction courante."""
if n == 0:
turtle.forward(l)
else:
segment_koch(l / 3.0, n - 1)
turtle.left(60)
segment_koch(l / 3.0, n - 1)
turtle.right(120)
segment_koch(l / 3.0, n - 1)
turtle.left(60)
segment_koch(l / 3.0, n - 1)


def flocon_koch(l, n):
"""Trace le flocon à l'ordre `n` et de côté `l` en partant de la position courant
et dans la direction courante."""
for _ in range(3):
segment_koch(l, n)
turtle.right(120)


for n in range(6):
flocon_koch(3**5, n)
13 changes: 13 additions & 0 deletions slides/07-fonctions/l_system.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from turtle import *

def draw(seq, length):
for action in seq:
match action.lower():
case "f":
forward(length)
case "+":
left(90)
case "-":
right(90)


31 changes: 31 additions & 0 deletions slides/07-fonctions/square_filling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import turtle
turtle.speed('fast')

def peano(l, n):
if n == 0:
turtle.forward(l)
else:
peano(l/3., n-1)
turtle.left(90)
peano(l/3., n-1)
turtle.right(90)
peano(l/3., n-1)
turtle.right(90)
peano(l/3., n-1)
turtle.right(90)
peano(l/3., n-1)
turtle.left(90)
peano(l/3., n-1)
turtle.left(90)
peano(l/3., n-1)
turtle.left(90)
peano(l/3., n-1)
turtle.right(90)
peano(l/3., n-1)


for n in range(6):
peano(3**5, n)
turtle.penup()
turtle.back(3**5)
turtle.pendown()
5 changes: 5 additions & 0 deletions slides/07-fonctions/turtle_star.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from turtle import *

while True:
forward(200)
left(170)

0 comments on commit 5b6964c

Please sign in to comment.