Tricky exercises
Programming task — enter your code and have it checked. Most parts read their values with them input() a: the check feeds in fixed inputs and compares your output line by line — so give only what is required (no additional texts). At part 7 you define the values yourself
(none input()); There it is checked whether the function and the lists are structured correctly.
input() you know from the “Variables” module.
Part 1 — Separate even and odd
Split the numbers read into two lists.
Exercise
- Read this first Number
nas an integer (int(input())), after thatnadditional integers — one perinput(). - Collect the even numbers in one list and the odd ones in a second list (even means: through 2 divisible without remainder, so
z % 2 == 0) — in the order in which they were entered. - Give in Row 1 the list of even numbers, in
Row 2 the list of odd ones — e.g. B.
[4, 2, 10]and below[7, 9, 13]. - Example: input
6then4 7 2 9 10 13→[4, 2, 10]and below[7, 9, 13].
Part 1 — Your Code
Loading Python…Tests
Part 2 — Find the largest number
Maximum manual — without max().
Exercise
- Read this first Number
nas an integer (int(input())), after thatnadditional integers — one perinput(). - Determine which largest Number with a marker: set it to the first number and replace it as soon as a larger number comes up.
- Don't use
max(). - Pass only the largest number from — at
5then3 17 5 12 8therefore17.
Part 2 — Your Code
Loading Python…Tests
Part 3 — Count grades
Collect frequencies in a dictionary.
Exercise
- Read this first Number
nas an integer (int(input())), after thatnGrades as whole numbers — one perinput(). - Create an empty dictionary. If the note is already a key, increase its value by 1, otherwise put it with the value
1on. - Output the finished dictionary — e.g. B.
{1: 2, 2: 3, 3: 1, 4: 1}. - Example:
7then1 2 2 3 1 4 2→{1: 2, 2: 3, 3: 1, 4: 1}.
Part 3 — Your Code
Loading Python…Tests
Part 4 — Sorting without sort()
Bubble sort with comparison and exchange.
Exercise
- Read this first Number
nas an integer (int(input())), after thatnintegers — one perinput()— and collect them in a list. - Sort the list from small to large: compare adjacent elements in nested loops and swap them if the one on the left is larger than the one on the right.
- Don't use
sort()orsorted(). - Output the sorted list — at
5then8 3 6 1 9therefore[1, 3, 6, 8, 9].
Tip for swapping: Either cache with an auxiliary variable or, more briefly, with the Python tuple swap a, b = b, a.
Part 4 — Your Code
Loading Python…Tests
Part 5 — Check password list
Decide per input and output one line.
Exercise
- Read this first Number
nas an integer (int(input())), after thatnPasswords as text — one perinput(). - Be specific for each password one line of:
lang genug, if it has at least 4 characters (len(passwort) >= 4), otherwisezu kurz. - Pay attention to the text and the limit (exactly 4 characters is “long enough”).
- Example:
4thenab,test,hallo,xy→zu kurz/lang genug/lang genug/zu kurz.
Part 5 — Your Code
Loading Python…Tests
Part 6 — Calculating Averages
Read and calculate multiple data sets.
Exercise
- Read this first Number
nthe student as a whole number (int(input())). - Then read per student successively three values with one each
input(): the Name as text (input()), Note 1 and Note 2 each as a decimal number (float(input())). - Calculate the average as (Note 1+ grade 2) divided by 2
and give exactly per student one line in the form
Name: Durchschnittfrom — e.g. B.Mia: 3.0(name, colon, space, then the average). - Example:
2, thenMia 2 4andTom 2 3→Mia: 3.0/Tom: 2.5.
Part 6 — Your Code
Loading Python…Tests
Part 7 — Squares of a List
Define a function and apply it to each list element - here without input().
Exercise
This exercise will not read in: you set the numbers yourself. The core is that Define the function and that Images (Mapping) via a list.
- Write a function named
quadrat, the a number receives and its square (the number times itself) return. - Leg yourself a list with the name
zahlenwith at least three integers (e.g. B.[2, 4, 6, 8]). - Calls
quadratin a loop for each number and collect the results in a new list namedquadrate. - Give the list
quadratefrom — with the numbers[2, 4, 6, 8]therefore[4, 16, 36, 64].
Part 7 — Your Code
Loading Python…Tests
Part 8 — Doubling to the limit
Iterative approximation with while.
Exercise
- Read that Date as an integer (
int(input())). - Double the value in one
whileloop while it smaller than100is (that is, until it is at least100reached), and count the steps. - Give in Row 1 the final value, in Row 2 the number of steps - i.e. two lines with a number each.
- Example: starting value
7→112and below4.
Part 8 — Your Code
Loading Python…Tests
Report as PDF
Document and download your results.
Module overview
| Part | Status |
|---|---|
| Part 1: Split | Open |
| Part 2: Maximum | Open |
| Part 3: Counting | Open |
| Part 4: Sorting | Open |
| Part 5: Passwords | Open |
| Part 6: Averages | Open |
| Part 7: Squares | Open |
| Part 8: Approximation | 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.