Functions
Programming task — enter your code and have it checked. At the
Reading-exercises (Parts 1, 2, 4, 5), the test feeds fixed inputs and compares your output character by character — so give only what is required.
input(prompt) with prompt is allowed, the prompt is hidden. At the
Definition-exercises (Part 3, 6) you define just the function — none input(), none print(); the test calls your function itself with fixed values and checks the return.
Part 1 — Function hallo(name)
Define a function, call it and use its return value.
TipExercise
- Write a function
hallo(name)that exactly the textHallo, <name>!return — the function itself should notprint()call. - Below the function definition, read a Name with
input()one, call the function with it and save the return in a variable. - Give this return with you
print()out.
The following is read: 1 line (name). Exactly one line is output - upon input Mia therefore Hallo, Mia!.
Part 1 — Your Code
Loading Python…Tests
Part 2 — Function addiere(a, b)
Sum as return value.
TipExercise
- Write a function
addiere(a, b), which is the sum of the parameters return. - Below the function definition, read two integers one - each with
int(input()), firsta, thenb— call the function and save the result insumme. - Pass only
summeout.
The following is read: 2 lines (a, then b). Example: 4 and 5 → Output 9.
Part 2 — Your Code
Loading Python…Tests
Part 3 — Function ist_positiv(zahl)
Just define — the check calls the function itself.
TipExercise
- Paper only the function
ist_positiv(zahl), theTruereturn, ifzahl > 0is, and otherwiseFalse. - You have to here read nothing and produce no output — none
input(), noneprint().
The check calls your function with fixed values: ist_positiv(5) must: True result, ist_positiv(-3) and ist_positiv(0) each False (the zero counts not as positive).
Part 3 — Your Code
Loading Python…Tests
Part 4 — Function quadrat(zahl)
A bill as a function.
TipExercise
- Write a function
quadrat(zahl), which returns the square of the number. - Below the function definition, read an integer (
int(input())), call the function and print its return.
The following is read: 1 Line (number). When entering 6 is the output 36, at -4 it is 16 (pay attention to the square, not the double).
Part 4 — Your Code
Loading Python…Tests
Part 5 — Function max_von_zwei(a, b)
Conditional return.
TipExercise
- Write a function
max_von_zwei(a, b)that returns the larger of the two numbers. If the numbers are equal, return their common value. - Below the function definition, read two integers (using
int(input()), firsta, thenb), call the function and print its return.
The following is read: 2 lines (a, then b). Example: 8 and 3 → Output 8; at 2 and 9 → 9. At 5 and 5 is the output 5.
Part 5 — Your Code
Loading Python…Tests
Part 6 — Function rechner(a, b)
Two returns as tuples — just define.
TipExercise
- Paper only the function
rechner(a, b), the two values returns: first the sum of the two parameters, then their product. In Python, you return multiple values by separating them with commasreturnwrite — the order decides the tuple. - You have to here read nothing and produce no output — none
input(), noneprint().
The check calls your function with fixed values and checks the returned tuple: rechner(2, 7) must: (9, 14) result, rechner(5, 6) must: (11, 30) result. Pay attention to the order: first sum, then product.
Part 6 — Your Code
Loading Python…Tests
Report as PDF
Document and download your results.
Module overview
| Part | Status |
|---|---|
| Part 1: hello | Open |
| Part 2: add | Open |
| Part 3: is_positive | Open |
| Part 4: square | Open |
| Part 5: max_of_two | Open |
| Part 6: calculator | Open |
Not all parts are completed yet - you can still create the report, which will then mark which parts are open.
Download PDF
Enter your name and download the report as a PDF.