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

Term review and class-garden project

الأسبوع 15 · مراجعة الوحدتين ١ و٢ ومشروع الفصل (من إعداد Darslab) · 3 دروس
2

Review: functions, errors, models and safe AI use

ICT Prep 3 Term 1, Units 1–2: Review
GoalReview functions, errors, models and safe use of AI with new mixed tasks.
New words
return · hands a value back from a functionexcept ValueError · the block that handles a wrong typed valuew and b · the weight (change per step) and the bias (starting value) of a linecheck the source · the better habit than trusting a clue
Explanation

Now the second half of the term. Functions: a parameter is in the definition, an argument is in the call, and return hands a value back. Errors: try and except ValueError keep a program calm, and a loop with break asks again. Models: a traditional program follows rules written by a person, a model finds its rule from data, and a line y = w * x + b has the starting value b and the change per step w. Safe use of AI: write as if the message were public, read the terms with a grown-up, check answers in other sources and give credit. Deepfakes: a clue is a reason to check, and the better habit is to check the source. The table asks whether some invented examples are fixed rules or learned from data.

Invented exampleFixed rule or learned?
a canteen price rule written by a personfixed rule
a model that finds the pattern in last year’s saleslearned from data
a spam filter trained on labelled messageslearned from data
if mark >= 50 show Passfixed rule
Worked examples
Python
1def double_price(price):
2    return price * 2
3
4print(double_price(15))
Output
30
Task: predict the output of a function with return. double_price returns twice the price it receives, and print shows the returned value. With 15 the screen shows 30.
Python
1while True:
2    try:
3        books = int(input("How many books? "))
4        print("You have", books, "books")
5        break
6    except ValueError:
7        print("Please type digits only.")
Output
How many books? 
Please type digits only.
How many books? six
Please type digits only.
How many books? 6
You have 6 books
Task: put the lines of a retry program in order. The correct order is: while True, try, read the number, show it, break, except ValueError, show the hint. Typing nothing or a word repeats the question.
Python
1w = 3
2b = 20
3x = 5
4print(w * x + b)
Output
35
Task: read the line y = 3x + 20. The weight is w = 3, the bias is b = 20, and for x = 5 the value is 3 × 5 + 20 = 35.
Class activity

Write three new tasks about Weeks 10 to 14: one on w and b, one on safe messages to an AI tool and one on a suspect video. Exchange them with a classmate and check each other’s answers with the lesson.

Practice
1
Sort the messages: which are safe to send to an AI tool?
Message to an AI toolSend?
an idea for a story about a robotyes
a maths questionyes
your school name and classno
a passwordno
2
An invented clip shows a mayor saying something strange, with lips slightly out of step. What is the clue and what is the better check?
3
What error does add_numbers(3) cause when the function has two parameters, and how do you fix the call?
4
Fix the line if num % 2 = 0: