Lesson 8: Functions for shapes
تحتاج هذه الصفحة إلى متصفح حديث (يدعم SharedArrayBuffer). يرجى تحديث Chrome أو Edge أو Firefox أو Safari إلى أحدث إصدار.
English
Name a shape
- A function keeps a drawing recipe under a name.
- A parameter changes the drawing:
square(50)andsquare(100)use the same code.
Words for this lesson
| Word | Meaning |
|---|---|
| function | a named block of code: def square(size): |
| parameter | a value the function gets, like size |
| call | run the function: square(80) |
English
Squares of many sizes
import turtle
def square(size):
for i in range(4):
turtle.forward(size)
turtle.left(90)
square(40)
square(80)
square(120)
الصعوبة 3/5 · 200 عملة + مكافأة صغيرة عند الإنجاز الأول اليوم
Write square(size) and call it three times to draw squares of size 50, 100 and 150.
اضغط تشغيل لرؤية المخرجات هنا.
الصعوبة 3/5 · 200 عملة + مكافأة صغيرة عند الإنجاز الأول اليوم
Write polygon(sides, size) that draws any shape with equal sides. Draw a triangle of size 100 and a hexagon of size 60.
اضغط تشغيل لرؤية المخرجات هنا.