Review: functions, errors, models and safe AI use
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 example | Fixed rule or learned? |
|---|---|
| a canteen price rule written by a person | fixed rule |
| a model that finds the pattern in last year’s sales | learned from data |
| a spam filter trained on labelled messages | learned from data |
| if mark >= 50 show Pass | fixed rule |
1def double_price(price): 2 return price * 2 3 4print(double_price(15))
30
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.")
How many books? Please type digits only. How many books? six Please type digits only. How many books? 6 You have 6 books
1w = 3 2b = 20 3x = 5 4print(w * x + b)
35
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.
| Message to an AI tool | Send? |
|---|---|
| an idea for a story about a robot | yes |
| a maths question | yes |
| your school name and class | no |
| a password | no |