Printable worksheet ยท 2 of 4
State what a function promises - Paper 2
Read the information, then answer the questions. An adult may read the instructions aloud. Show your working where asked.
Read before answering
Numeric function contract: f(n) returns 3*n + (1) without changing other data. Python implementation A: def f(n): return 3*n + (1). Implementation B: def f(n): print(3*n + (1)). The caller evaluates result = f(-4) + 1. In Python a function reaching its end without return produces None. Use only these invented numeric inputs.
Worksheet preview
- Under implementation A, find f(-4) and the caller's result for the rule 3*n + (1).
- Does implementation B satisfy the same returning contract? Explain the caller's outcome.
- Give three input-output tests that include zero and both signs.
This exercise is included in the free preview. Register free to complete it and download the preview PDFs. No payment is required.
Already registered? Sign in