What you'll build
Ten short Python functions, already written for you. For each one, answer four questions in plain words — its name, what it needs, its job, and whether it returns an answer. No code to write or run; this is pure reading, to make functions click before you write your own.
Requirements
The must-do parts. If any are missing, we'll ask you to take another pass.
- For each of the ten functions under The functions below, answer these four questions: (1) What is the name of the function? (2) What information does it need — its inputs? (3) What job does it do, in one plain sentence? (4) Does it return an answer — yes or no — and if yes, what?
- Number your answers 1 to 10 so they line up with the functions.
- Watch question 4 closely. Some functions
returna value the program can use; others onlyprintsomething and hand nothing back. Telling those two apart is the whole point of this exercise. - Use your own words. Don't copy the code line back — say what it does.
- For any function that only prints, write one extra line saying what it *would* hand back if you changed it to use
return. - Find the function that walks a list with a loop, and say in one line how its answer changes if the list is empty.
The functions
Read each one, then answer the four questions for it. You are not running any of this code — just reading it.
def say_hello():
print("Hello and welcome to the shop.")def greet(name):
print("Welcome,", name)def double(number):
return number * 2def add_prices(price1, price2):
total = price1 + price2
return totaldef make_receipt_line(item, price):
return item + ": GHS " + str(price)def verdict(score):
if score >= 50:
return "Pass"
else:
return "Fail"def check_age(age):
if age >= 18:
print("You are an adult.")
else:
print("You are a minor.")def apply_discount(price, percent):
discount = price * percent / 100
return price - discountdef total_fees(fees):
total = 0
for fee in fees:
total = total + fee
return totaldef count_passes(scores):
passes = 0
for score in scores:
if score >= 50:
passes = passes + 1
return passesHow we'll grade it
Four checks, four points. Three or above is passing — we'll ask you to revise anything we can't tick.
| Check | What we look for | Pt |
|---|---|---|
| Names and inputs | Each function's name and the information it needs (its parameters) are identified correctly. | 1 |
| Jobs described | Each function's job is explained in plain words, not just the code repeated back. | 1 |
| Return or not | Each answer correctly says whether the function returns a value (and what) — including the ones that only print. | 1 |
| All ten, clearly | All ten are covered, numbered, and easy to follow. | 1 |