Computer Exercise 0: Practice solutions
Algorithms, Programming, and Data Representation · Module 92313 · Exercise 0
Practice · not course-graded
Exercise 0 is a practice workflow check. Use it to verify your submission setup; it is not part of the course grade. Try each task before opening the worked steps.
Task 1: Return the exact greeting
Connected topic: Computers, programs, and data representation (Chapter 2)
Task 01 · hello()
Try first: write the function first, then compare its returned string character for character.
Attempted it? Open the worked steps
Task 01 · hello() · worked solution
The contract is a zero-argument function returning one exact string. There is no input to transform.
Return the required literal; do not
printit, because printing producesNoneas the function result.Call the function and compare the value, including capitalization, comma, and exclamation mark.
The whole function:
def hello(): return "Hello, World!"
Task 2: Add two numbers
Connected topic: Computers, programs, and data representation (Chapter 2)
Task 02 · add_two_numbers(a, b)
Try first: identify the return type implied by the examples and consider negative and decimal inputs.
Attempted it? Open the worked steps
Task 02 · add_two_numbers(a, b) · worked solution
The required operation is ordinary addition. Keep the parameters generic so Python preserves its numeric behavior for integers and floats.
Return
a + b; avoid converting toint, which would discard a fractional part.Check that
add_two_numbers(2, 3)returns 5, then check a negative value and a float.The whole function:
def add_two_numbers(a, b): return a + b
Task 3: Square a number
Connected topic: Computers, programs, and data representation (Chapter 2)
Task 03 · square(number)
Try first: express “square” as multiplication and check a negative input.
Attempted it? Open the worked steps
Task 03 · square(number) · worked solution
A square is the number multiplied by itself; it is not the square root and it is nonnegative for real inputs.
Return
number * number.Check
square(4)= 16 andsquare(-3)= 9.The whole function:
def square(number): return number * number
Task 4: Test whether a number is even
Connected topic: Computers, programs, and data representation (Chapter 2)
Task 04 · is_even(number)
Try first: use the remainder after division by two.
Attempted it? Open the worked steps
Task 04 · is_even(number) · worked solution
An integer is even exactly when its remainder modulo 2 is zero. Python’s modulo rule also handles negative integers consistently.
Return the Boolean comparison
number % 2 == 0. Do not return the strings"orTrue"".False"Check 4 gives
True, 5 givesFalse, and -2 givesTrue.The whole function:
def is_even(number): return number % 2 == 0
Task 5: Build a personalized greeting
Connected topic: Computers, programs, and data representation (Chapter 2)
Task 05 · greet(name)
Try first: use string formatting and preserve the supplied name exactly.
Attempted it? Open the worked steps
Task 05 · greet(name) · worked solution
The output has a fixed prefix, the name, and a final exclamation mark. No punctuation is added to the name itself.
Use an f-string to construct and return the full text.
Check
greet("Ada")returns exactly"Hello, Ada!"and does notprintto the terminal.The whole function:
def greet(name): return f"Hello, {name}!"
Personal worked-solution guide based on the APDR Computer Exercise 0 task sheet, rewritten in my own words. It is not an official FAU publication. Exercise 0 is practice; Exercises 1–2 are scored tasks. Use the samples and dataset from your own assigned repository where values are personalized. Made by Thanate Amornjiraporn (Focus).