Dictionary
Programming task — enter your code and have it checked. In the first four parts you define the values yourself in the code - this is about creating, reading, replacing and adding to a dictionary. In part 5 and 6 are the values above
input() read in and fixed entries fed in automatically; there the output is compared character by character, so give only what is required. input() was in the module Variables introduced.
Part 1 — Person
Create your own dictionary and build a sentence from it.
Exercise
- Create a dictionary
personwith the keys"name"and"alter"on. Choose the values yourself: a name (string) and an age (integer). - Build a sentence of the form from this
<name> ist <alter> Jahre alt.and output exactly this value — for"name": "Anna"and"alter": 20thereforeAnna ist 20 Jahre alt.
To do this, access the two values in the dictionary using the keys. Just output this one sentence.
Part 1 — Your Code
Loading Python…Tests
Part 2 — Car Brand
Only read a value using its key.
Exercise
- Create a dictionary
autowith the keys"marke"and"farbe"on. Choose the values yourself (both strings). - Lis just the value of
"marke"about his key and give it out.
The output should contain exactly the brand name — not the color and not the entire dictionary.
Part 2 — Your Code
Loading Python…Tests
Part 3 — Changing the book
Overwrite an existing value.
Exercise
- Create a dictionary
buchwith the keys"titel"and"seiten"on. Give in"seiten"a first, old Page number (whole number). You choose the values yourself. - Assign the key
"seiten"then one new Page number and overwrite the old value. - Pass only the new page value.
For "seiten": 120 and then overwritten 150 the output is 150 — not the old number.
Part 3 — Your Code
Loading Python…Tests
Part 4 — Expand the city
Add a new key.
Exercise
- Create a dictionary
stadtwith the keys"name"and"land"(both strings, chosen by yourself). - Then add one to the dictionary new Key
"einwohner"with an integer as a value. - Build a set of the form from all three values
<name> liegt in <land> und hat <einwohner> Einwohner.and output exactly that.
For "name": "Berlin", "land": "Deutschland" and supplemented "einwohner": 3800000 the output is
Berlin liegt in Deutschland und hat 3800000 Einwohner.
Part 4 — Your Code
Loading Python…Tests
Part 5 — Check food
A dictionary value with if test.
Exercise
- Read with two
input()-Call first Court of Justice withinput()one, then one Price as a decimal numberfloat(input()). - Save both in a dictionary
essenwith the keys"gericht"and"preis". - Use a case distinction to check whether the price actually greater than 10 is:
- if yes, output:
<gericht> ist teuer. - otherwise output:
<gericht> ist guenstig.
- if yes, output:
For Pizza and 12 the output is Pizza ist teuer.; at Salat and 10
(exactly 10, so not bigger) Salat ist guenstig.
Part 5 — Your Code
Loading Python…Tests
Part 6 — Grade Point Average
Calculate with values from the dictionary.
Exercise
- Read three at a time
input()-Call one Name withinput(), then this Math note and the Info note each as a decimal numberfloat(input())there. - Store everything in a dictionary
schuelerwith the keys"name","note_mathe"and"note_info". - Calculate the average of the two grades as the sum of the two values divided by 2. Pay attention to the bracketing of the numerator and denominator and report
/(not//) to create a decimal number. - Pass only this average value.
In math = 2 and info = 3 the output is 2.5; at 2 and 2 arises 2.0.
Trailing zeros are allowed: 2.5 and 2.50 are graded equally. Do not round the average to fewer places here.
Part 6 — Your Code
Loading Python…Tests
Report as PDF
Document and download your results.
Module overview
| Part | Status |
|---|---|
| Part 1: Person | Open |
| Part 2: Car Brand | Open |
| Part 3: Change book | Open |
| Part 4: Expand the city | Open |
| Part 5: Check food | Open |
| Part 6: Grade Point Average | 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.