☰ خطة العام · تكنولوجيا المعلومات والاتصالات (بالإنجليزية)

Functions

الأسبوع 8 · الدرس ٤ «الدوال ذات المعاملات في لغة Python»: الدالة والمعاملات ومساحة الدائرة وإرجاع القيمة · 3 دروس
Answers are for parents and teachers.
1
In the lines below, name the parameters and the arguments.
Python
1def triangle_area(base, height):
2    return 0.5 * base * height
3
4print(triangle_area(6, 4))
2
Predict the two lines shown by subtract(10, 4) and subtract(4, 10).
Python
1def subtract(a, b):
2    print(a - b)
3
4subtract(10, 4)
5subtract(4, 10)
3
What do the two lines show?
Python
1def celsius_to_f(c):
2    return c * 9 / 5 + 32
3
4print(celsius_to_f(25))
5print(celsius_to_f(100))
4
A price after a 10 percent discount is price * 0.9. Write a function discounted(price) that returns it. What does discounted(200) give?
5
What do the two lines show, and why does each return end the function?
Python
1def bigger(a, b):
2    if a > b:
3        return a
4    else:
5        return b
6
7print(bigger(8, 3))
8print(bigger(2, 9))