From 624c0f1a1a59ce969bc3d7f8670014f8437ac7e5 Mon Sep 17 00:00:00 2001 From: TrollRoll2 <101802614+TrollRoll2@users.noreply.github.com> Date: Tue, 16 Jul 2024 14:12:59 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20rage/ohj?= =?UTF-8?q?elmointi-24-sv@82815971da88a4cd644d8ecd0ef441f94541b77d=20?= =?UTF-8?q?=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 404.html | 2 +- 404/index.html | 2 +- arvostelu-ja-kokeet/index.html | 2 +- credits/index.html | 2 +- index.html | 2 +- kaikki-tehtavat/index.html | 2 +- osa-1/1-introduktion/index.html | 2 +- osa-1/2-info-fran-anvandaren/index.html | 2 +- osa-1/3-mer-om-variabler/index.html | 4 ++-- osa-1/4-rakneoperationer/index.html | 2 +- osa-1/5-villkorssatser/index.html | 2 +- osa-1/index.html | 2 +- osa-10/1-klasshierarkier/index.html | 2 +- osa-10/2-atkamstmodifierare/index.html | 2 +- .../index.html | 2 +- osa-10/4-storre-applikation/index.html | 2 +- osa-10/index.html | 2 +- osa-11/1-list-comprehension/index.html | 12 ++++++------ osa-11/2-mer-om-comprehensions/index.html | 2 +- osa-11/3-rekursion/index.html | 12 ++++++------ osa-11/4-lisaa-esimerkkeja/index.html | 12 ++++++------ osa-11/index.html | 2 +- osa-12/1-funktioner-som-argument/index.html | 2 +- osa-12/2-generatorer/index.html | 2 +- osa-12/3-funktionell-programmering/index.html | 2 +- osa-12/4-reguljara-uttryck/index.html | 2 +- osa-12/index.html | 2 +- osa-13/1-pygame/index.html | 2 +- osa-13/2-animation/index.html | 2 +- osa-13/3-handelser/index.html | 2 +- osa-13/4-fler-pygame-tekniker/index.html | 2 +- osa-13/index.html | 2 +- osa-14/1-spelprojekt/index.html | 2 +- osa-14/2-robot-och-ladar/index.html | 2 +- osa-14/3-fardigstallande-av-spelet/index.html | 2 +- osa-14/4-ditt-eget-sepl/index.html | 6 +++--- osa-14/index.html | 2 +- osa-2/1-terminologi/index.html | 2 +- osa-2/2-else-elif/index.html | 2 +- osa-2/3-kombinera-villkor/index.html | 2 +- osa-2/4-loopar/index.html | 2 +- osa-2/index.html | 2 +- osa-3/1-loopar-med-villkor/index.html | 2 +- osa-3/2-behandla-strangar/index.html | 2 +- osa-3/3-mer-om-loopar/index.html | 2 +- osa-3/4-definiera-funktioner/index.html | 2 +- osa-3/index.html | 2 +- osa-4/1-vscode/index.html | 2 +- osa-4/2-mer-om-funktioner/index.html | 2 +- osa-4/3-listor/index.html | 2 +- osa-4/4-iteration/index.html | 2 +- osa-4/5-utskrift/index.html | 2 +- osa-4/6-strangar-listor/index.html | 2 +- osa-4/index.html | 2 +- osa-5/1-mer-om-listor/index.html | 2 +- osa-5/2-referenser/index.html | 2 +- osa-5/3-lexikon/index.html | 2 +- osa-5/4-tuple/index.html | 2 +- osa-5/index.html | 2 +- osa-6/1-lasa-filer/index.html | 2 +- osa-6/2-skriva-filer/index.html | 2 +- osa-6/3-fel/index.html | 2 +- osa-6/4-lokala-globala-variabler/index.html | 2 +- osa-6/index.html | 2 +- osa-7/1-moduler/index.html | 2 +- osa-7/2-slumpmassighet/index.html | 2 +- osa-7/3-tid-datum/index.html | 2 +- osa-7/4-behandla-data/index.html | 2 +- osa-7/5-egna-moduler/index.html | 2 +- osa-7/6-funktionaliteter-python/index.html | 2 +- osa-7/index.html | 2 +- osa-8/1-objekt-och-metoder/index.html | 12 ++++++------ osa-8/2-klasser-och-objekt/index.html | 2 +- osa-8/3-egna-klasser/index.html | 2 +- osa-8/4-metoder-i-egna-klasser/index.html | 14 +++++++------- osa-8/5-fler-exempel/index.html | 2 +- osa-8/index.html | 2 +- osa-9/1-objekt-och-referenser/index.html | 12 ++++++------ osa-9/2-objekt-som-attribut/index.html | 2 +- osa-9/3-inkapsling/index.html | 2 +- osa-9/4-metodernas-rackvidd/index.html | 2 +- osa-9/5-klassattribut/index.html | 2 +- osa-9/6-fler-exempel-med-klasser/index.html | 2 +- osa-9/index.html | 2 +- .../osa-11/1-list-comprehension/page-data.json | 2 +- page-data/osa-11/3-rekursion/page-data.json | 2 +- .../osa-11/4-lisaa-esimerkkeja/page-data.json | 2 +- .../osa-8/1-objekt-och-metoder/page-data.json | 2 +- .../4-metoder-i-egna-klasser/page-data.json | 2 +- .../osa-9/1-objekt-och-referenser/page-data.json | 2 +- report-issue/index.html | 2 +- sanasto/index.html | 2 +- sign-in/index.html | 2 +- sign-up/index.html | 2 +- .../12766/9_1_1.webp | Bin 2982 -> 0 bytes .../80977/9_1_1.png | Bin 1983 -> 0 bytes .../81c8e/9_1_1.png | Bin 2460 -> 0 bytes .../a0b58/9_1_1.webp | Bin 2016 -> 0 bytes .../10600/11_4_2.png | Bin 0 -> 4631 bytes .../81c8e/11_4_2.png | Bin 0 -> 6816 bytes .../a0b58/11_4_2.webp | Bin 0 -> 5236 bytes .../c2de8/11_4_2.webp | Bin 0 -> 8850 bytes .../08a84/11_3_1.png | Bin 0 -> 4186 bytes .../108f8/11_3_1.png | Bin 0 -> 3926 bytes .../2e4ba/11_3_1.webp | Bin 0 -> 6388 bytes .../81c8e/11_3_1.png | Bin 0 -> 2281 bytes .../a0b58/11_3_1.webp | Bin 0 -> 1668 bytes .../bc10c/11_3_1.webp | Bin 0 -> 3668 bytes .../81c8e/11_1_2.png | Bin 3887 -> 0 bytes .../a0b58/11_1_2.webp | Bin 3800 -> 0 bytes .../c4c4c/11_1_2.webp | Bin 5132 -> 0 bytes .../fb933/11_1_2.png | Bin 3845 -> 0 bytes .../4c0ad/8_1_1.png | Bin 1930 -> 0 bytes .../5af35/8_1_1.webp | Bin 4414 -> 0 bytes .../81c8e/8_1_1.png | Bin 2756 -> 0 bytes .../a0b58/8_1_1.webp | Bin 2478 -> 0 bytes .../10600/11_4_2.png | Bin 4201 -> 0 bytes .../81c8e/11_4_2.png | Bin 4581 -> 0 bytes .../a0b58/11_4_2.webp | Bin 4858 -> 0 bytes .../c2de8/11_4_2.webp | Bin 7848 -> 0 bytes .../12766/9_1_1.webp | Bin 0 -> 2956 bytes .../80977/9_1_1.png | Bin 0 -> 2226 bytes .../81c8e/9_1_1.png | Bin 0 -> 3626 bytes .../a0b58/9_1_1.webp | Bin 0 -> 1998 bytes .../4c0ad/8_1_1.png | Bin 0 -> 2232 bytes .../5af35/8_1_1.webp | Bin 0 -> 4888 bytes .../81c8e/8_1_1.png | Bin 0 -> 4670 bytes .../a0b58/8_1_1.webp | Bin 0 -> 2478 bytes .../81c8e/11_1_2.png | Bin 0 -> 5765 bytes .../a0b58/11_1_2.webp | Bin 0 -> 3690 bytes .../c4c4c/11_1_2.webp | Bin 0 -> 5214 bytes .../fb933/11_1_2.png | Bin 0 -> 4306 bytes .../08a84/11_3_1.png | Bin 3490 -> 0 bytes .../108f8/11_3_1.png | Bin 3888 -> 0 bytes .../2e4ba/11_3_1.webp | Bin 6528 -> 0 bytes .../81c8e/11_3_1.png | Bin 2169 -> 0 bytes .../a0b58/11_3_1.webp | Bin 1718 -> 0 bytes .../bc10c/11_3_1.webp | Bin 3786 -> 0 bytes tuki/index.html | 2 +- usein-kysytyt-kysymykset/index.html | 2 +- verkkotentti-ohja/index.html | 2 +- verkkotentti-ohpe/index.html | 2 +- verkkotentti/index.html | 2 +- virheilmoitukset/index.html | 2 +- 144 files changed, 134 insertions(+), 134 deletions(-) delete mode 100644 static/13e71ea262de820629eb873bb73f2d94/12766/9_1_1.webp delete mode 100644 static/13e71ea262de820629eb873bb73f2d94/80977/9_1_1.png delete mode 100644 static/13e71ea262de820629eb873bb73f2d94/81c8e/9_1_1.png delete mode 100644 static/13e71ea262de820629eb873bb73f2d94/a0b58/9_1_1.webp create mode 100644 static/32e25a73b5e04b72265ba7ccd2d765b1/10600/11_4_2.png create mode 100644 static/32e25a73b5e04b72265ba7ccd2d765b1/81c8e/11_4_2.png create mode 100644 static/32e25a73b5e04b72265ba7ccd2d765b1/a0b58/11_4_2.webp create mode 100644 static/32e25a73b5e04b72265ba7ccd2d765b1/c2de8/11_4_2.webp create mode 100644 static/33f03fd48c215b216b48b8d09c1f757a/08a84/11_3_1.png create mode 100644 static/33f03fd48c215b216b48b8d09c1f757a/108f8/11_3_1.png create mode 100644 static/33f03fd48c215b216b48b8d09c1f757a/2e4ba/11_3_1.webp create mode 100644 static/33f03fd48c215b216b48b8d09c1f757a/81c8e/11_3_1.png create mode 100644 static/33f03fd48c215b216b48b8d09c1f757a/a0b58/11_3_1.webp create mode 100644 static/33f03fd48c215b216b48b8d09c1f757a/bc10c/11_3_1.webp delete mode 100644 static/3f079cde22be6cf33b7be317492aa108/81c8e/11_1_2.png delete mode 100644 static/3f079cde22be6cf33b7be317492aa108/a0b58/11_1_2.webp delete mode 100644 static/3f079cde22be6cf33b7be317492aa108/c4c4c/11_1_2.webp delete mode 100644 static/3f079cde22be6cf33b7be317492aa108/fb933/11_1_2.png delete mode 100644 static/74b678969e8df323e37bea6c8b4fae79/4c0ad/8_1_1.png delete mode 100644 static/74b678969e8df323e37bea6c8b4fae79/5af35/8_1_1.webp delete mode 100644 static/74b678969e8df323e37bea6c8b4fae79/81c8e/8_1_1.png delete mode 100644 static/74b678969e8df323e37bea6c8b4fae79/a0b58/8_1_1.webp delete mode 100644 static/876ad26e1b0c7b303582f9e0f2cb0148/10600/11_4_2.png delete mode 100644 static/876ad26e1b0c7b303582f9e0f2cb0148/81c8e/11_4_2.png delete mode 100644 static/876ad26e1b0c7b303582f9e0f2cb0148/a0b58/11_4_2.webp delete mode 100644 static/876ad26e1b0c7b303582f9e0f2cb0148/c2de8/11_4_2.webp create mode 100644 static/a3722ba9326d57861bd87ed8593aab50/12766/9_1_1.webp create mode 100644 static/a3722ba9326d57861bd87ed8593aab50/80977/9_1_1.png create mode 100644 static/a3722ba9326d57861bd87ed8593aab50/81c8e/9_1_1.png create mode 100644 static/a3722ba9326d57861bd87ed8593aab50/a0b58/9_1_1.webp create mode 100644 static/a9810fa9a13874067832dc3cc67de74e/4c0ad/8_1_1.png create mode 100644 static/a9810fa9a13874067832dc3cc67de74e/5af35/8_1_1.webp create mode 100644 static/a9810fa9a13874067832dc3cc67de74e/81c8e/8_1_1.png create mode 100644 static/a9810fa9a13874067832dc3cc67de74e/a0b58/8_1_1.webp create mode 100644 static/bb2be65b36f7fdf4ea48dfde815e9fbf/81c8e/11_1_2.png create mode 100644 static/bb2be65b36f7fdf4ea48dfde815e9fbf/a0b58/11_1_2.webp create mode 100644 static/bb2be65b36f7fdf4ea48dfde815e9fbf/c4c4c/11_1_2.webp create mode 100644 static/bb2be65b36f7fdf4ea48dfde815e9fbf/fb933/11_1_2.png delete mode 100644 static/ca600c1fe96166b67e6fe37b5f5dcc89/08a84/11_3_1.png delete mode 100644 static/ca600c1fe96166b67e6fe37b5f5dcc89/108f8/11_3_1.png delete mode 100644 static/ca600c1fe96166b67e6fe37b5f5dcc89/2e4ba/11_3_1.webp delete mode 100644 static/ca600c1fe96166b67e6fe37b5f5dcc89/81c8e/11_3_1.png delete mode 100644 static/ca600c1fe96166b67e6fe37b5f5dcc89/a0b58/11_3_1.webp delete mode 100644 static/ca600c1fe96166b67e6fe37b5f5dcc89/bc10c/11_3_1.webp diff --git a/404.html b/404.html index e8b3d93a2..82f5ebf55 100644 --- a/404.html +++ b/404.html @@ -134,4 +134,4 @@ } } }) -
\ No newline at end of file +
\ No newline at end of file diff --git a/404/index.html b/404/index.html index 918919edd..1bfae8ad3 100644 --- a/404/index.html +++ b/404/index.html @@ -134,4 +134,4 @@ } } }) -
\ No newline at end of file +
\ No newline at end of file diff --git a/arvostelu-ja-kokeet/index.html b/arvostelu-ja-kokeet/index.html index 03bfea6f6..3009df6dc 100644 --- a/arvostelu-ja-kokeet/index.html +++ b/arvostelu-ja-kokeet/index.html @@ -190,4 +190,4 @@ hylätty -

Arvostelu perustuu sekä tehtyihin tehtäviin (50 % kokonaispisteistä) että kokeeseen (50 % kokonaispisteistä). Tämä tarkoittaa, että arvosteluasteikon kokonaispisteet saadaan laskemalla tämän sivun pistevisualisaation (sininen pallo oikeassa alakulmassa) kurssipisteet ja saamasi koepisteet yhteen.

Kurssin läpipääsyyn vaaditaan vähintään 25% jokaisen osan ohjelmointitehtävien pisteistä.

Koeleikkuri

Kokeesta tulee saada vähintään puolet pisteistä kurssin läpäisemiseksi.

\ No newline at end of file +

Arvostelu perustuu sekä tehtyihin tehtäviin (50 % kokonaispisteistä) että kokeeseen (50 % kokonaispisteistä). Tämä tarkoittaa, että arvosteluasteikon kokonaispisteet saadaan laskemalla tämän sivun pistevisualisaation (sininen pallo oikeassa alakulmassa) kurssipisteet ja saamasi koepisteet yhteen.

Kurssin läpipääsyyn vaaditaan vähintään 25% jokaisen osan ohjelmointitehtävien pisteistä.

Koeleikkuri

Kokeesta tulee saada vähintään puolet pisteistä kurssin läpäisemiseksi.

\ No newline at end of file diff --git a/credits/index.html b/credits/index.html index 24c2f5d39..8a8c8d477 100644 --- a/credits/index.html +++ b/credits/index.html @@ -134,4 +134,4 @@ } } }) -

Kiitokset ja materiaalista

Kurssin on tehnyt Helsingin yliopiston Agile Education Research -tutkimusryhmä.

Kurssimateriaali

Kurssimateriaalin ja tehtävien tekijät ovat Erkki Kaila, Antti Laaksonen ja Matti Luukkainen. Muutama kurssin tehtävistä on Arto Hellaksen (né Vihavainen) käsialaa.

Kurssin materiaali on lisensoitu Creative Commons BY-NC-SA 4.0 -lisenssillä, joten voit käyttää ja levittää sitä vapaasti, kunhan alkuperäisten tekijöiden nimiä ei poisteta. Jos teet muutoksia materiaaliin ja haluat levittää muunneltua versiota, se täytyy lisensoida samalla lisenssillä. Materiaalien käyttö kaupalliseen tarkoitukseen on ilman erillistä lupaa kielletty.

Kurssilla käytössä oleva teknologia

Kurssisivuston ovat tehneet Henrik Nygren ja Antti Leinonen. Helsingin yliopiston Agile Education Research -tutkimusryhmä on luonut kurssilla käytetyn ohjelmointitehtävien palautusympäristön (Test My Code) ja sen liitännäiset ohjelmointiympäristöihin, kurssimateriaalissa olevan kyselyjärjestelmän ja muut toiminnot.

\ No newline at end of file +

Kiitokset ja materiaalista

Kurssin on tehnyt Helsingin yliopiston Agile Education Research -tutkimusryhmä.

Kurssimateriaali

Kurssimateriaalin ja tehtävien tekijät ovat Erkki Kaila, Antti Laaksonen ja Matti Luukkainen. Muutama kurssin tehtävistä on Arto Hellaksen (né Vihavainen) käsialaa.

Kurssin materiaali on lisensoitu Creative Commons BY-NC-SA 4.0 -lisenssillä, joten voit käyttää ja levittää sitä vapaasti, kunhan alkuperäisten tekijöiden nimiä ei poisteta. Jos teet muutoksia materiaaliin ja haluat levittää muunneltua versiota, se täytyy lisensoida samalla lisenssillä. Materiaalien käyttö kaupalliseen tarkoitukseen on ilman erillistä lupaa kielletty.

Kurssilla käytössä oleva teknologia

Kurssisivuston ovat tehneet Henrik Nygren ja Antti Leinonen. Helsingin yliopiston Agile Education Research -tutkimusryhmä on luonut kurssilla käytetyn ohjelmointitehtävien palautusympäristön (Test My Code) ja sen liitännäiset ohjelmointiympäristöihin, kurssimateriaalissa olevan kyselyjärjestelmän ja muut toiminnot.

\ No newline at end of file diff --git a/index.html b/index.html index c04caba03..698719915 100644 --- a/index.html +++ b/index.html @@ -229,4 +229,4 @@

Luentotallenteet
OsaLuentotallenne
Osa 1Luentotallenne, 04.09.2023
Osa 2Luentotallenne, 11.09.2023
Osa 3Luentotallenne, 18.09.2023
Osa 4Luentotallenne, 25.09.2023
Osa 5Luentotallenne, 02.10.2023
Osa 6Luentotallenne, 09.10.2023
Osa 7Luentotallenne, 16.10.2023
Osa 8Luentotallenne, 30.10.2023
Osa 9Luentotallenne, 03.11.2023
Osa 10Luentotallenne, 13.11.2023
Osa 11Luentotallenne, 20.11.2023
Osa 12Luentotallenne, 27.11.2023
Osa 13Luentotallenne, 05.12.2023
Osa 14Ei luentoa, projektityö
\ No newline at end of file +
OsaLuentotallenne
Osa 1Luentotallenne, 04.09.2023
Osa 2Luentotallenne, 11.09.2023
Osa 3Luentotallenne, 18.09.2023
Osa 4Luentotallenne, 25.09.2023
Osa 5Luentotallenne, 02.10.2023
Osa 6Luentotallenne, 09.10.2023
Osa 7Luentotallenne, 16.10.2023
Osa 8Luentotallenne, 30.10.2023
Osa 9Luentotallenne, 03.11.2023
Osa 10Luentotallenne, 13.11.2023
Osa 11Luentotallenne, 20.11.2023
Osa 12Luentotallenne, 27.11.2023
Osa 13Luentotallenne, 05.12.2023
Osa 14Ei luentoa, projektityö
\ No newline at end of file diff --git a/kaikki-tehtavat/index.html b/kaikki-tehtavat/index.html index 3e64ed914..3c0b1e7d7 100644 --- a/kaikki-tehtavat/index.html +++ b/kaikki-tehtavat/index.html @@ -134,4 +134,4 @@ } } }) -
\ No newline at end of file +
\ No newline at end of file diff --git a/osa-1/1-introduktion/index.html b/osa-1/1-introduktion/index.html index dbfda2fae..c353591b1 100644 --- a/osa-1/1-introduktion/index.html +++ b/osa-1/1-introduktion/index.html @@ -228,4 +228,4 @@ # ett år består av 365 dagar och varje dag av 24 timmar print(365*24)

När programmet körs, kommer kommentaren inte att synas för användaren:

Esimerkkitulostus

Antal timmar i ett år: 8760

Korta kommentarer kan också skrivas i slutet på en rad, på följande sätt:

print("Antal timmar i ett år:")
-print(365*24) # 365 dagar, 24 timmar per dag

Kertauskysely tämän osan asioihin liittyen:

Loading...
:
Loading...

Log in to view the quiz

Seuraava osa:

\ No newline at end of file +print(365*24) # 365 dagar, 24 timmar per dag

Kertauskysely tämän osan asioihin liittyen:

Loading...
:
Loading...

Log in to view the quiz

Seuraava osa:

\ No newline at end of file diff --git a/osa-1/2-info-fran-anvandaren/index.html b/osa-1/2-info-fran-anvandaren/index.html index 774431438..853e32385 100644 --- a/osa-1/2-info-fran-anvandaren/index.html +++ b/osa-1/2-info-fran-anvandaren/index.html @@ -246,4 +246,4 @@ print("Gatuadressen är nu " + gata)

Så här kan det se ut när programmet körs:

Esimerkkitulostus

Vilken är din gatuadress? Slitagestigen 2 Ange en ny gatuadress: Värjan 1 -Gatuadressen är nu Värjan 1

Kertauskysely tämän osan asioihin liittyen:

Loading...
:
Loading...

Log in to view the quiz

Seuraava osa:

\ No newline at end of file +Gatuadressen är nu Värjan 1

Kertauskysely tämän osan asioihin liittyen:

Loading...
:
Loading...

Log in to view the quiz

Seuraava osa:

\ No newline at end of file diff --git a/osa-1/3-mer-om-variabler/index.html b/osa-1/3-mer-om-variabler/index.html index 9d533d4aa..5fa809043 100644 --- a/osa-1/3-mer-om-variabler/index.html +++ b/osa-1/3-mer-om-variabler/index.html @@ -210,7 +210,7 @@
  • kan du använda variabler i olika situationer
  • vet du vilken typ av data som kan lagras i variabler
  • känner du till skillnaderna mellan strängar, heltal och flyttal.
  • -

    Vänligen fyll i den här enkäten före du börjar med den här delen. Du får ett poäng efter att du har fyllt i enkäten.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Variabler har olika användningsområden inom programmering. Du kan använda variabler för att lagra vilken som helst typ av information som kan behövas senare medan ett program körs.

    I Python skapas variabler på följande sätt:

    variabelns_namn = ...

    ... ovan syftar till värdet som sparas i variabeln.

    Till exempel när du använde instruktionen input för att läsa in en sträng från användaren, sparade du strängen i en variabel och använde variabeln senare i ditt program.

    namn = input("Ange ditt namn: ")
    +

    Vänligen fyll i den här enkäten före du börjar med den här delen. Du får ett poäng efter att du har fyllt i enkäten.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Variabler har olika användningsområden inom programmering. Du kan använda variabler för att lagra vilken som helst typ av information som kan behövas senare medan ett program körs.

    I Python skapas variabler på följande sätt:

    variabelns_namn = ...

    ... ovan syftar till värdet som sparas i variabeln.

    Till exempel när du använde instruktionen input för att läsa in en sträng från användaren, sparade du strängen i en variabel och använde variabeln senare i ditt program.

    namn = input("Ange ditt namn: ")
     print("Hejsan " + namn)
    Esimerkkitulostus

    Ange ditt namn: Konstantin Hejsan Konstantin

    Värdet som lagras i variabeln kan också definieras med hjälp av andra variabler:

    fornamn = "Gabrielle"
     efternamn = "Gullholm"
    @@ -266,4 +266,4 @@
     luku3 = 3.62
     
     medeltal = (siffra1 + siffra2 + luku3) / 3
    -print(f"Medelvärde: {medeltal}")
    Esimerkkitulostus

    Medelvärde: 1.6233333333333333

    Kertauskysely tämän osan asioihin liittyen:

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:

    \ No newline at end of file +print(f"Medelvärde: {medeltal}")
    Esimerkkitulostus

    Medelvärde: 1.6233333333333333

    Kertauskysely tämän osan asioihin liittyen:

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:

    \ No newline at end of file diff --git a/osa-1/4-rakneoperationer/index.html b/osa-1/4-rakneoperationer/index.html index f29ca2260..d07967f3a 100644 --- a/osa-1/4-rakneoperationer/index.html +++ b/osa-1/4-rakneoperationer/index.html @@ -349,4 +349,4 @@ print("Hej " + nimi + "!") alder = int(input("Vad är din ålder? ")) -# programmet fortsätter...

    Kertauskysely tämän osan asioihin liittyen:

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:

    \ No newline at end of file +# programmet fortsätter...

    Kertauskysely tämän osan asioihin liittyen:

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:

    \ No newline at end of file diff --git a/osa-1/5-villkorssatser/index.html b/osa-1/5-villkorssatser/index.html index f4050c780..f6fbcc967 100644 --- a/osa-1/5-villkorssatser/index.html +++ b/osa-1/5-villkorssatser/index.html @@ -316,4 +316,4 @@ print("a är mindre än 5")
    Esimerkkitulostus

    True a är mindre än 5

    Pythons nyckelord True och False kan också användas direkt som sådana. I det följande exemplet körs print-instruktionen alltid, eftersom värdet på villkoret är True:

    villkor = True
     if villkor:
    -    print("Vi når hit alltid")
    Esimerkkitulostus

    Vi når hit alltid

    Man kan tycka att det inte i ovanstående exempel verkar vara en så nyttig funktion. Senare under kursens lopp ska vi se på situationer där vi kan ha mera nytta av Boolean-variabler.

    Kertauskysely tämän osan asioihin liittyen:

    Loading...
    :
    Loading...

    Log in to view the quiz

    Vänligen svara på en kort enkät om materialet i den här veckans modul. Du får ett poäng när du fyllt i enkäten.

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file + print("Vi når hit alltid")
    Esimerkkitulostus

    Vi når hit alltid

    Man kan tycka att det inte i ovanstående exempel verkar vara en så nyttig funktion. Senare under kursens lopp ska vi se på situationer där vi kan ha mera nytta av Boolean-variabler.

    Kertauskysely tämän osan asioihin liittyen:

    Loading...
    :
    Loading...

    Log in to view the quiz

    Vänligen svara på en kort enkät om materialet i den här veckans modul. Du får ett poäng när du fyllt i enkäten.

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file diff --git a/osa-1/index.html b/osa-1/index.html index 7f1c77128..1d8ce0c7b 100644 --- a/osa-1/index.html +++ b/osa-1/index.html @@ -150,4 +150,4 @@ } })
    \ No newline at end of file +
    Loading...
    \ No newline at end of file diff --git a/osa-10/1-klasshierarkier/index.html b/osa-10/1-klasshierarkier/index.html index b9dafa618..1458b84f8 100644 --- a/osa-10/1-klasshierarkier/index.html +++ b/osa-10/1-klasshierarkier/index.html @@ -393,4 +393,4 @@ print(bonus) print(bonus2)
    Esimerkkitulostus

    0.7225 -0.7586250000000001

    Loading
    Loading
    Loading
    Loading
    Seuraava osa:

    \ No newline at end of file +0.7586250000000001

    Loading
    Loading
    Loading
    Loading
    Seuraava osa:

    \ No newline at end of file diff --git a/osa-10/2-atkamstmodifierare/index.html b/osa-10/2-atkamstmodifierare/index.html index 2cdde028b..13fe9cb9c 100644 --- a/osa-10/2-atkamstmodifierare/index.html +++ b/osa-10/2-atkamstmodifierare/index.html @@ -319,4 +319,4 @@ if __name__ == "__main__": fs = Fotbollsspelare("peter pythonson", "putte", "anfallare") print(fs) -
    Esimerkkitulostus

    Fotbollsspelare - namn:Peter Pythonson, smeknamn: Putte, position: anfallare

    Loading
    Loading
    Seuraava osa:

    \ No newline at end of file +
    Esimerkkitulostus

    Fotbollsspelare - namn:Peter Pythonson, smeknamn: Putte, position: anfallare

    Loading
    Loading
    Seuraava osa:

    \ No newline at end of file diff --git a/osa-10/3-objektorienterade-programmeringstekniker/index.html b/osa-10/3-objektorienterade-programmeringstekniker/index.html index 89c40f49a..4fbb03211 100644 --- a/osa-10/3-objektorienterade-programmeringstekniker/index.html +++ b/osa-10/3-objektorienterade-programmeringstekniker/index.html @@ -445,4 +445,4 @@ print(bok.namn)
    Esimerkkitulostus

    Livet av en Python Den gamle och Java -C-värdheter på nätet

    Loading
    Seuraava osa:

    \ No newline at end of file +C-värdheter på nätet

    Loading
    Seuraava osa:

    \ No newline at end of file diff --git a/osa-10/4-storre-applikation/index.html b/osa-10/4-storre-applikation/index.html index f34e71bb7..b2c8bb378 100644 --- a/osa-10/4-storre-applikation/index.html +++ b/osa-10/4-storre-applikation/index.html @@ -500,4 +500,4 @@ forvaringstjanst = MolnHanterare("amazon-cloud", "anvandarnamn", "losenord") applikation = TelefonkatalogApplikation(forvaringstjanst) -applikation.exekvera()

    Som du har sett tidigare har den här typen av tekniker ett pris, eftersom det blir mer kod att skriva, så en programmerare måste överväga om det är en acceptabel avvägning.

    Den teknik som beskrivs ovan kallas beroendeinjektion. Som namnet antyder är tanken att alla beroenden som krävs av ett objekt ska tillhandahållas utanför objektet. Det är ett mycket användbart verktyg i en programmerares verktygslåda, eftersom det gör det lättare att implementera nya funktioner i program och underlättar automatisk testning. Detta tema kommer att utforskas ytterligare på de tidigare nämnda kurserna Software Development och Software Engineering.

    Svara vänligen på en snabb enkät om denna del av kursen.

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file +applikation.exekvera()

    Som du har sett tidigare har den här typen av tekniker ett pris, eftersom det blir mer kod att skriva, så en programmerare måste överväga om det är en acceptabel avvägning.

    Den teknik som beskrivs ovan kallas beroendeinjektion. Som namnet antyder är tanken att alla beroenden som krävs av ett objekt ska tillhandahållas utanför objektet. Det är ett mycket användbart verktyg i en programmerares verktygslåda, eftersom det gör det lättare att implementera nya funktioner i program och underlättar automatisk testning. Detta tema kommer att utforskas ytterligare på de tidigare nämnda kurserna Software Development och Software Engineering.

    Svara vänligen på en snabb enkät om denna del av kursen.

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file diff --git a/osa-10/index.html b/osa-10/index.html index 664d46ec2..82a38316d 100644 --- a/osa-10/index.html +++ b/osa-10/index.html @@ -150,4 +150,4 @@ } })
    \ No newline at end of file +
    Loading...
    \ No newline at end of file diff --git a/osa-11/1-list-comprehension/index.html b/osa-11/1-list-comprehension/index.html index cddee7abd..5e43d09f0 100644 --- a/osa-11/1-list-comprehension/index.html +++ b/osa-11/1-list-comprehension/index.html @@ -192,12 +192,12 @@ for tal in talen: strangar.append(str(tal))

    List comprehension

    Det finns också ett mer "pythoniskt" sätt att generera listor från befintliga listor. Dessa kallas list comprehensions.

    Tanken är att på en enda rad få plats med både beskrivningen av vad som ska göras med varje objekt i listan och tilldelningen av resultatet till en ny lista.

    I exemplet ovan var operationen som utfördes på varje objekt i listan mycket enkel: varje heltal omvandlades till en sträng. Låt oss se hur detta skulle se ut implementerat med en list comprehension:

    talen = [1, 2, 3, 6, 5, 4, 7]
     strangar = [str(tal) for tal in talen]

    Den andra raden ovan innehåller många av samma element som den mer traditionella iterativa metoden, men syntaxen är annorlunda. Ett sätt att generalisera en list comprehension skulle kunna vara

    [<uttryck> for <föremål> in <serie>]

    Hakparenteserna runt list comprehensionsatsen signalerar till Python att resultatet ska vara en ny lista. En efter en bearbetas varje objekt i den ursprungliga listan och resultatet lagras i den nya listan, precis som i det iterativa tillvägagångssättet ovan. Som resultat har vi en ny lista med exakt lika många objekt som i originalet, och alla objekt har behandlats på ett identiskt sätt.

    (OBS: originalen till bilderna i denna del saknas tillfälligt, vilket är anledningen till att det finns en del finskt vokabulär i illustrationerna i denna del. Vi arbetar på att åtgärda detta).

    - - + + - - - 11 1 2 + + + 11 1 2

    List comprehensions kan också hantera mycket mer komplicerade operationer. Vi kan utföra beräkningar, till exempel multiplicera de ursprungliga objekten med tio:

    talen = list(range(1,10))
    @@ -277,4 +277,4 @@
         testlista = ["hej", 3, True, "hejsan", -123.344, "hejsansvejsan", 2, False]
         langder = strang_langder(testlista)
         print(langder)
    -
    Esimerkkitulostus

    [3, -1, -1, 6, -1, 13, -1, -1]

    Loading
    Seuraava osa:
    2. Mer om comprehensions

    \ No newline at end of file +
    Esimerkkitulostus

    [3, -1, -1, 6, -1, 13, -1, -1]

    Loading
    Seuraava osa:
    2. Mer om comprehensions

    \ No newline at end of file diff --git a/osa-11/2-mer-om-comprehensions/index.html b/osa-11/2-mer-om-comprehensions/index.html index 4b254dc31..c67c50826 100644 --- a/osa-11/2-mer-om-comprehensions/index.html +++ b/osa-11/2-mer-om-comprehensions/index.html @@ -363,4 +363,4 @@ lista = [-2, 3, 2, 1, 4, -10, 5, 1, 6] fakultett = {tal : fakultet(tal) for tal in lista if tal > 0} print(fakulteter) -
    Esimerkkitulostus

    {3: 6, 2: 2, 1: 1, 4: 24, 5: 120, 6: 720}

    Loading
    Loading
    Seuraava osa:
    3. Rekursion

    \ No newline at end of file +
    Esimerkkitulostus

    {3: 6, 2: 2, 1: 1, 4: 24, 5: 120, 6: 720}

    Loading
    Loading
    Seuraava osa:
    3. Rekursion

    \ No newline at end of file diff --git a/osa-11/3-rekursion/index.html b/osa-11/3-rekursion/index.html index 73caf8934..e1c4d6ce0 100644 --- a/osa-11/3-rekursion/index.html +++ b/osa-11/3-rekursion/index.html @@ -277,12 +277,12 @@
  • mindre än det vi letar efter: vi kan göra om sökningen i den större halvan av listan
  • större än den vi letar efter: vi kan göra om sökningen i den mindre halvan av listan.
  • Om listan är tom kan vi fastställa att objektet inte hittades och returnera en indikation på det.

    I följande bild kan vi se hur en binär sökning fortskrider när den letar efter talet 24:

    - - + + - - - 11 3 1 + + + 11 3 1

    Här är en rekursiv algoritm för en binär sökning:

    def binarsokning(lista: list, foremal: int, vanster : int, hoger : int):
    @@ -315,4 +315,4 @@
         print(binarsokning(lista, 15, 0, len(lista)-1))
    Esimerkkitulostus

    True True False -False

    Funktionen binar_sokning tar fyra argument: mållistan, det objekt som söks samt vänster och höger kant på sökområdet. När funktionen anropas första gången täcker sökområdet hela mållistan. Den vänstra kanten ligger på index 0 och den högra kanten ligger på index len(lista)-1. Funktionen beräknar det centrala indexet och kontrollerar den positionen på listan. Antingen har objektet hittats eller så fortsätter sökningen till den mindre eller större halvan av mållistan.

    Låt oss jämföra detta med en enkel linjär sökning. Vid en linjär sökning är sökområdet från början och framåt, tills antingen objektet hittas eller sökområdet tar slut. Antalet steg som behövs för att täcka hela sökområdet växer linjärt i samma takt som sökområdets storlek. Varje söksteg täcker endast en sökkandidat från början av sökområdet. Låt oss anta att det sökta objektet inte hittas. Om sökområdet är en miljon objekt långt måste vi ta en miljon söksteg för att försäkra oss om att objektet inte finns i sökområdet.

    Vid en binär sökning växer däremot antalet steg som behövs logaritmiskt. Låt oss återigen anta att det sökta objektet inte hittas. Sökområdet halveras för varje steg, eftersom vi vet att objektet antingen är mindre eller större än den aktuella sökkandidaten i mitten. 2 gånger 20 (2^20) är redan långt över 1 miljon, så det tar som mest 20 steg att täcka hela sökområdet med en binär sökning. När vi har att göra med sorterade sökområden, vilket ofta är fallet när vi har att göra med datorer och material som ska bearbetas automatiskt, är en binär sökning alltså mycket effektivare än en linjär sökning.

    Seuraava osa:
    4. Fler exempel på rekursion

    \ No newline at end of file +False

    Funktionen binar_sokning tar fyra argument: mållistan, det objekt som söks samt vänster och höger kant på sökområdet. När funktionen anropas första gången täcker sökområdet hela mållistan. Den vänstra kanten ligger på index 0 och den högra kanten ligger på index len(lista)-1. Funktionen beräknar det centrala indexet och kontrollerar den positionen på listan. Antingen har objektet hittats eller så fortsätter sökningen till den mindre eller större halvan av mållistan.

    Låt oss jämföra detta med en enkel linjär sökning. Vid en linjär sökning är sökområdet från början och framåt, tills antingen objektet hittas eller sökområdet tar slut. Antalet steg som behövs för att täcka hela sökområdet växer linjärt i samma takt som sökområdets storlek. Varje söksteg täcker endast en sökkandidat från början av sökområdet. Låt oss anta att det sökta objektet inte hittas. Om sökområdet är en miljon objekt långt måste vi ta en miljon söksteg för att försäkra oss om att objektet inte finns i sökområdet.

    Vid en binär sökning växer däremot antalet steg som behövs logaritmiskt. Låt oss återigen anta att det sökta objektet inte hittas. Sökområdet halveras för varje steg, eftersom vi vet att objektet antingen är mindre eller större än den aktuella sökkandidaten i mitten. 2 gånger 20 (2^20) är redan långt över 1 miljon, så det tar som mest 20 steg att täcka hela sökområdet med en binär sökning. När vi har att göra med sorterade sökområden, vilket ofta är fallet när vi har att göra med datorer och material som ska bearbetas automatiskt, är en binär sökning alltså mycket effektivare än en linjär sökning.

    Seuraava osa:
    4. Fler exempel på rekursion

    \ No newline at end of file diff --git a/osa-11/4-lisaa-esimerkkeja/index.html b/osa-11/4-lisaa-esimerkkeja/index.html index 2e76ebd39..0fdcf00e5 100644 --- a/osa-11/4-lisaa-esimerkkeja/index.html +++ b/osa-11/4-lisaa-esimerkkeja/index.html @@ -213,12 +213,12 @@
  • Anropa sig själv på barnnoden till vänster
  • Anropa sig själv på barnnoden till höger
  • - - + + - - - 11 4 2 + + + 11 4 2

    Som du kan se på bilden ovan är både de vänstra och högra "underträden" fullfjädrade binära träd i sig, och den enda nod som lämnas utanför de rekursiva anropen är den överordnade noden, som bearbetas i steg 1 innan funktionen anropas rekursivt. På så sätt kan vi vara säkra på att varje nod har besökts exakt en gång när funktionen är klar.

    En iterativ version av en binär trädtraversering skulle vara mycket mer komplicerad, eftersom vi på något sätt skulle behöva hålla reda på alla noder som vi redan har besökt. Samma principer gäller för alla beräkningsbara trädstrukturer, inte bara binära.

    Ett binärt träd är också lätt att modellera i Python-kod. Vi behöver bara skriva en klassdefinition för en enda nod. Den har ett värdeattribut och attribut för de vänstra och högra underordnade noderna:

    
    @@ -291,4 +291,4 @@
             return sok_nod(rot.hoger_barn, varde)
     
         return sok_nod(rot.vanster_barn, varde)
    -
    Loading

    Besök till tiden innan rekursion

    Låt oss avsluta denna del av materialet med en lite större övning som koncentrerar sig på objektorienterade programmeringsprinciper. Vi rekommenderar inte att du använder rekursion i denna serie av uppgifter, men tekniker för list comprehension kommer att vara användbara.

    Loading
    Loading

    Svara slutligen på en snabb enkät:

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file +
    Loading

    Besök till tiden innan rekursion

    Låt oss avsluta denna del av materialet med en lite större övning som koncentrerar sig på objektorienterade programmeringsprinciper. Vi rekommenderar inte att du använder rekursion i denna serie av uppgifter, men tekniker för list comprehension kommer att vara användbara.

    Loading
    Loading

    Svara slutligen på en snabb enkät:

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file diff --git a/osa-11/index.html b/osa-11/index.html index bf55b77e8..ef25861e6 100644 --- a/osa-11/index.html +++ b/osa-11/index.html @@ -150,4 +150,4 @@ } })
    \ No newline at end of file +
    Loading...
    \ No newline at end of file diff --git a/osa-12/1-funktioner-som-argument/index.html b/osa-12/1-funktioner-som-argument/index.html index 238a948cb..dbced7dfc 100644 --- a/osa-12/1-funktioner-som-argument/index.html +++ b/osa-12/1-funktioner-som-argument/index.html @@ -379,4 +379,4 @@ kopiera_rader("första.txt", "andra.txt", lambda rad: "Python" in rad) # Kopierar alla rader som inte slutar med en punkt - kopiera_rader("första.txt", "andra.txt", lambda rad: rad[-1] != ".")

    Funktionsdefinitionen innehåller ett standardvärde för nyckelordsparametern kriterie: lambda x: True. Denna anonyma funktion returnerar alltid True oavsett indata. Standardbeteendet är alltså att kopiera alla rader. Som vanligt gäller att om ett värde anges för en parameter med ett standardvärde, ersätter det nya värdet standardvärdet.

    Loading
    Seuraava osa:
    2. Generatorer

    \ No newline at end of file + kopiera_rader("första.txt", "andra.txt", lambda rad: rad[-1] != ".")

    Funktionsdefinitionen innehåller ett standardvärde för nyckelordsparametern kriterie: lambda x: True. Denna anonyma funktion returnerar alltid True oavsett indata. Standardbeteendet är alltså att kopiera alla rader. Som vanligt gäller att om ett värde anges för en parameter med ett standardvärde, ersätter det nya värdet standardvärdet.

    Loading
    Seuraava osa:
    2. Generatorer

    \ No newline at end of file diff --git a/osa-12/2-generatorer/index.html b/osa-12/2-generatorer/index.html index e1247d697..d7899035b 100644 --- a/osa-12/2-generatorer/index.html +++ b/osa-12/2-generatorer/index.html @@ -251,4 +251,4 @@ ghi hij ijk -jkl

    Loading
    Seuraava osa:
    3. Funktionell programmering

    \ No newline at end of file +jkl

    Loading
    Seuraava osa:
    3. Funktionell programmering

    \ No newline at end of file diff --git a/osa-12/3-funktionell-programmering/index.html b/osa-12/3-funktionell-programmering/index.html index ff5b55177..2c1de5da1 100644 --- a/osa-12/3-funktionell-programmering/index.html +++ b/osa-12/3-funktionell-programmering/index.html @@ -414,4 +414,4 @@ talens_summa = reduce(lambda summa, foremal: summa + foremal, lista) -print(talens_summa)

    Ifall ett ursprungligt värde lämnas bort tar reduce det första föremålet i listan som sitt ursprungsvärde och börjar reducera från det andra föremålet framåt.

    OBS: Om föremålen i serien är av en annan typ än det avsedda reducerade resultatet, är det tredje argumentet obligatoriskt. Exemplet med bankkontona skulle inte fungera utan det ursprungliga värdet. Det vill säga att prova detta

    saldon_totalt = reduce(saldo_summa_hjalpare, konton)

    Skulle producera ett fel:

    TypeError: unsupported operand type(s) for +: 'Bankkonto' and 'int'

    I ovanstående fall, när reduce försöker utföra funktionen saldo_summa_hjalpare för första gången, är de argument som används de två första föremålen i listan, som båda är av typen Bankkonto. Specifikt är det värde som tilldelats parametern saldo_summa det första föremålet i listan. Funktionen saldo_summa_hjalpare försöker lägga till ett heltalsvärde till den, men att lägga till ett heltal direkt till ett Bankkonto-objekt är inte en åtgärd som stöds.

    Loading
    Seuraava osa:
    4. Reguljära uttryck

    \ No newline at end of file +print(talens_summa)

    Ifall ett ursprungligt värde lämnas bort tar reduce det första föremålet i listan som sitt ursprungsvärde och börjar reducera från det andra föremålet framåt.

    OBS: Om föremålen i serien är av en annan typ än det avsedda reducerade resultatet, är det tredje argumentet obligatoriskt. Exemplet med bankkontona skulle inte fungera utan det ursprungliga värdet. Det vill säga att prova detta

    saldon_totalt = reduce(saldo_summa_hjalpare, konton)

    Skulle producera ett fel:

    TypeError: unsupported operand type(s) for +: 'Bankkonto' and 'int'

    I ovanstående fall, när reduce försöker utföra funktionen saldo_summa_hjalpare för första gången, är de argument som används de två första föremålen i listan, som båda är av typen Bankkonto. Specifikt är det värde som tilldelats parametern saldo_summa det första föremålet i listan. Funktionen saldo_summa_hjalpare försöker lägga till ett heltalsvärde till den, men att lägga till ett heltal direkt till ett Bankkonto-objekt är inte en åtgärd som stöds.

    Loading
    Seuraava osa:
    4. Reguljära uttryck

    \ No newline at end of file diff --git a/osa-12/4-reguljara-uttryck/index.html b/osa-12/4-reguljara-uttryck/index.html index 069905e91..304012eb3 100644 --- a/osa-12/4-reguljara-uttryck/index.html +++ b/osa-12/4-reguljara-uttryck/index.html @@ -288,4 +288,4 @@ Ange sträng: jarmo the hut Hittades inte. Ange sträng: jabba the smut -Hittades inte.

    Loading

    Den stora finalen

    Som avslutning på denna del av materialet ska vi arbeta lite mer med objekt och klasser genom att bygga ett lite mer omfattande program. Denna övning innefattar inte nödvändigtvis reguljära uttryck, men avsnitten om Funktioner som argument och list comprehension kommer sannolikt att vara användbara.

    Du kan också ha nytta av de exempel som finns i modul 10.

    Loading

    Svara till sist på en snabb enkät:

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file +Hittades inte.

    Loading

    Den stora finalen

    Som avslutning på denna del av materialet ska vi arbeta lite mer med objekt och klasser genom att bygga ett lite mer omfattande program. Denna övning innefattar inte nödvändigtvis reguljära uttryck, men avsnitten om Funktioner som argument och list comprehension kommer sannolikt att vara användbara.

    Du kan också ha nytta av de exempel som finns i modul 10.

    Loading

    Svara till sist på en snabb enkät:

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file diff --git a/osa-12/index.html b/osa-12/index.html index 8ca98567c..6f6d38de8 100644 --- a/osa-12/index.html +++ b/osa-12/index.html @@ -150,4 +150,4 @@ } })
    \ No newline at end of file +
    Loading...
    \ No newline at end of file diff --git a/osa-13/1-pygame/index.html b/osa-13/1-pygame/index.html index df07abc49..b529aecde 100644 --- a/osa-13/1-pygame/index.html +++ b/osa-13/1-pygame/index.html @@ -258,4 +258,4 @@ fonster.blit(robot, (300, 0)) fonster.blit(robot, (100, 200))

    Resultatet borde vara att fönstret ser ut så här:

    Här sätter vi lokationen av bilden så, att den ligger i mitten av fönstret:

    bredd = robot.get_width()
     hojd = robot.get_height()
    -fonster.blit(robot, (320-bredd/2, 240-hojd/2))

    Fönstret borde nu se ut så här:

    Metoden get_width ger bildens bredd och metoden get_height ger dess höjd, båda i pixlar. Fönstrets mittpunkt ligger på halva bredden och höjden, alltså på (320, 240), vilket vi kan använda för att beräkna en lämplig plats för bildens övre vänstra hörn, så att det ligger exakt i mitten.

    Loading
    Loading
    Loading
    Loading
    Seuraava osa:
    2. Animation

    \ No newline at end of file +fonster.blit(robot, (320-bredd/2, 240-hojd/2))

    Fönstret borde nu se ut så här:

    Metoden get_width ger bildens bredd och metoden get_height ger dess höjd, båda i pixlar. Fönstrets mittpunkt ligger på halva bredden och höjden, alltså på (320, 240), vilket vi kan använda för att beräkna en lämplig plats för bildens övre vänstra hörn, så att det ligger exakt i mitten.

    Loading
    Loading
    Loading
    Loading
    Seuraava osa:
    2. Animation

    \ No newline at end of file diff --git a/osa-13/2-animation/index.html b/osa-13/2-animation/index.html index 9a132d398..f21a2d16f 100644 --- a/osa-13/2-animation/index.html +++ b/osa-13/2-animation/index.html @@ -258,4 +258,4 @@ vinkel += 0.01 klocka.tick(60)

    Exekvering av koden ovan borde se ut så här:

    Rotation i en relativt exakt cirkel uppnås med hjälp av några grundläggande trigonometriska funktioner. Variabeln vinkel innehåller vinkeln för robotens position i förhållande till fönstrets mittpunkt och den horisontella linjen som går genom fönstret. Sinus- och cosinusfunktionerna från Pythons matematikbibliotek används här för att beräkna koordinaterna för robotens position:

            x = 320+math.cos(vinkel)*100-robot.get_width()/2
    -        y = 240+math.sin(vinkel)*100-robot.get_height()/2

    Roboten roterar runt en cirkel med radien 100 runt fönstrets mittpunkt. Hypotenusan i detta scenario är cirkelns radie. Cosinusfunktionen anger längden på den angränsande sidan i en rätvinklig triangel i förhållande till hypotenusan, vilket innebär att den ger oss platsens x-koordinat. Sinusfunktionen ger längden på den motsatta sidan, dvs. y-koordinaten. Platsen justeras sedan för bildens storlek, så att cirkelns mittpunkt ligger i fönstrets mittpunkt.

    För varje iteration ökar storleken på vinkel med 0,01. Eftersom vi använder radianer är en hel cirkel 2π, vilket motsvarar ca 6,28. Det tar cirka 628 iterationer för roboten att gå en hel cirkel, och med 60 iterationer per sekund tar detta drygt 10 sekunder.

    Loading
    Loading
    Loading
    Loading
    Loading
    Loading
    Seuraava osa:
    3. Händelser

    \ No newline at end of file + y = 240+math.sin(vinkel)*100-robot.get_height()/2

    Roboten roterar runt en cirkel med radien 100 runt fönstrets mittpunkt. Hypotenusan i detta scenario är cirkelns radie. Cosinusfunktionen anger längden på den angränsande sidan i en rätvinklig triangel i förhållande till hypotenusan, vilket innebär att den ger oss platsens x-koordinat. Sinusfunktionen ger längden på den motsatta sidan, dvs. y-koordinaten. Platsen justeras sedan för bildens storlek, så att cirkelns mittpunkt ligger i fönstrets mittpunkt.

    För varje iteration ökar storleken på vinkel med 0,01. Eftersom vi använder radianer är en hel cirkel 2π, vilket motsvarar ca 6,28. Det tar cirka 628 iterationer för roboten att gå en hel cirkel, och med 60 iterationer per sekund tar detta drygt 10 sekunder.

    Loading
    Loading
    Loading
    Loading
    Loading
    Loading
    Seuraava osa:
    3. Händelser

    \ No newline at end of file diff --git a/osa-13/3-handelser/index.html b/osa-13/3-handelser/index.html index 6e88d735f..e413dae50 100644 --- a/osa-13/3-handelser/index.html +++ b/osa-13/3-handelser/index.html @@ -347,4 +347,4 @@ fonster.blit(robot, (robot_x, robot_y)) pygame.display.flip() - klocka.tick(60)

    Exekveringen av programmet borde se ut så här:

    Loading
    Loading
    Seuraava osa:
    4. Fler pygame-tekniker

    \ No newline at end of file + klocka.tick(60)

    Exekveringen av programmet borde se ut så här:

    Loading
    Loading
    Seuraava osa:
    4. Fler pygame-tekniker

    \ No newline at end of file diff --git a/osa-13/4-fler-pygame-tekniker/index.html b/osa-13/4-fler-pygame-tekniker/index.html index 6f78ea956..b8fb1efde 100644 --- a/osa-13/4-fler-pygame-tekniker/index.html +++ b/osa-13/4-fler-pygame-tekniker/index.html @@ -222,4 +222,4 @@ while True: for handelse in pygame.event.get(): if handelse.type == pygame.QUIT: - exit()

    Körning av koden ovan borde se ut enligt följande:

    Här skapar metoden pygame.font.SysFont ett typsnittsobjekt, som använder systemtypsnittet Arial i storlek 24. Metoden render skapar sedan en bild av den angivna texten i den angivna färgen. Denna bild ritas på fönstret med metoden blit, precis som tidigare.

    OBS: olika system kommer att ha olika teckensnitt tillgängliga. Om det system som det här programmet körs på inte har teckensnittet Arial, trots att Arial är ett mycket vanligt teckensnitt som finns på de flesta system, används istället systemets standardteckensnitt. Om du behöver ha ett specifikt teckensnitt tillgängligt för ditt spel kan du inkludera teckensnittsfilen i spelkatalogen och ange dess plats för metoden pygame.font.Font.

    Övningar

    Här är några mer avancerade övningar för att öva på det du har lärt dig i denna del av kursmaterialet.

    Loading
    Loading

    Svara vänligen på en snabb enkät om denna del av kursen:

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file + exit()

    Körning av koden ovan borde se ut enligt följande:

    Här skapar metoden pygame.font.SysFont ett typsnittsobjekt, som använder systemtypsnittet Arial i storlek 24. Metoden render skapar sedan en bild av den angivna texten i den angivna färgen. Denna bild ritas på fönstret med metoden blit, precis som tidigare.

    OBS: olika system kommer att ha olika teckensnitt tillgängliga. Om det system som det här programmet körs på inte har teckensnittet Arial, trots att Arial är ett mycket vanligt teckensnitt som finns på de flesta system, används istället systemets standardteckensnitt. Om du behöver ha ett specifikt teckensnitt tillgängligt för ditt spel kan du inkludera teckensnittsfilen i spelkatalogen och ange dess plats för metoden pygame.font.Font.

    Övningar

    Här är några mer avancerade övningar för att öva på det du har lärt dig i denna del av kursmaterialet.

    Loading
    Loading

    Svara vänligen på en snabb enkät om denna del av kursen:

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file diff --git a/osa-13/index.html b/osa-13/index.html index c86ac501a..31fc42732 100644 --- a/osa-13/index.html +++ b/osa-13/index.html @@ -150,4 +150,4 @@ } })
    \ No newline at end of file +
    Loading...
    \ No newline at end of file diff --git a/osa-14/1-spelprojekt/index.html b/osa-14/1-spelprojekt/index.html index 204743880..e411e2cc8 100644 --- a/osa-14/1-spelprojekt/index.html +++ b/osa-14/1-spelprojekt/index.html @@ -408,4 +408,4 @@

    Huvudloopen.display.flip()

    I det här skedet är den enda händelse som faktiskt hanteras av spelet att stänga spelfönstret, t.ex. med exit-knappen. Spelet avslutas sedan genom att anropa Pythons exit-funktion.

    Varje gång metoden rita_fonster anropas korsas hela spelrutnätet igenom och den bild som motsvarar varje ruta i rutnätet ritas på rätt plats.

    -

    OBS: koordinaterna x och y används på två olika sätt i spelet. När man hanterar index i en tvådimensionell lista är det logiskt att ange y-koordinaten först, eftersom y hänvisar till numret på raden medan x är numret på kolumnen. Å andra sidan, när man använder pygame-metoder, skickas x vanligtvis först, vilket det ganska ofta gör när man arbetar med grafik och även i matematiska sammanhang.

    Seuraava osa:

    \ No newline at end of file +

    OBS: koordinaterna x och y används på två olika sätt i spelet. När man hanterar index i en tvådimensionell lista är det logiskt att ange y-koordinaten först, eftersom y hänvisar till numret på raden medan x är numret på kolumnen. Å andra sidan, när man använder pygame-metoder, skickas x vanligtvis först, vilket det ganska ofta gör när man arbetar med grafik och även i matematiska sammanhang.

    Seuraava osa:

    \ No newline at end of file diff --git a/osa-14/2-robot-och-ladar/index.html b/osa-14/2-robot-och-ladar/index.html index 4ac65ffe2..5db3745cd 100644 --- a/osa-14/2-robot-och-ladar/index.html +++ b/osa-14/2-robot-och-ladar/index.html @@ -255,4 +255,4 @@

    Omfaktorisering?3. Färdigställande av spelet

    \ No newline at end of file +

    Omfaktorisering och kodkvalitet är ett ämne för en del efterföljande kurser, t.ex. Software Development Methods och Software Engineering.

    Seuraava osa:

    \ No newline at end of file diff --git a/osa-14/3-fardigstallande-av-spelet/index.html b/osa-14/3-fardigstallande-av-spelet/index.html index 6077c58d0..110a1b548 100644 --- a/osa-14/3-fardigstallande-av-spelet/index.html +++ b/osa-14/3-fardigstallande-av-spelet/index.html @@ -248,4 +248,4 @@

    Ditt spel på GitHub?GitHub är en populär plats för många typer av programmeringsprojekt. Det kan användas för att lagra källkoden och annat material för alla dina egna programmeringsprojekt också, och ditt program kommer då att underhållas genom git-versionskontroll, och det kan enkelt delas med andra. Du kommer att bli mycket bekant med git och GitHub om du fortsätter med andra programmeringskurser på mooc.fi.

    Hur många drag krävs?

    Rutnätet i det här spelet är ganska litet, men spelet är inte så lätt. Den första utmaningen är att helt enkelt klara spelet, men nästa steg är att försöka göra det med så få drag som möjligt. Hur kort är den kortaste vägen till en lösning?

    -

    Att leta efter den kortaste möjliga lösningen är inte alls en lätt uppgift, men det finns beräkningslösningar för detta också. Detta är ett av ämnena i kursen Datastrukturer och algoritmer.

    Seuraava osa:

    \ No newline at end of file +

    Att leta efter den kortaste möjliga lösningen är inte alls en lätt uppgift, men det finns beräkningslösningar för detta också. Detta är ett av ämnena i kursen Datastrukturer och algoritmer.

    Seuraava osa:

    \ No newline at end of file diff --git a/osa-14/4-ditt-eget-sepl/index.html b/osa-14/4-ditt-eget-sepl/index.html index 445abe9b7..1fd6006b5 100644 --- a/osa-14/4-ditt-eget-sepl/index.html +++ b/osa-14/4-ditt-eget-sepl/index.html @@ -255,9 +255,9 @@

    Kollegial granskningHur väl är det programmerat? Är koden läsbar och används klasser och funktioner på rätt sätt?

    En bra recension brukar peka ut både bra funktioner och några förslag till förbättringar.

    -
    Loading...
    :
    Loading...

    Log in to view the quiz

    +
    Loading...
    :
    Loading...

    Log in to view the quiz

    Frågeformulär för att avsluta

    Först ber vi dig svara på en snabb enkät om den här delen av kursen.

    -
    Loading...
    :
    Loading...

    Log in to view the quiz

    +
    Loading...
    :
    Loading...

    Log in to view the quiz

    Vänligen svara också på kursens feedbackformulär. Enkätens svar hjälper oss att förbättra kursen.

    -
    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file +
    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file diff --git a/osa-14/index.html b/osa-14/index.html index bb33c9b73..8f04c3c13 100644 --- a/osa-14/index.html +++ b/osa-14/index.html @@ -150,4 +150,4 @@ } })
    \ No newline at end of file +
    Loading...
    \ No newline at end of file diff --git a/osa-2/1-terminologi/index.html b/osa-2/1-terminologi/index.html index 45c55033d..39857d954 100644 --- a/osa-2/1-terminologi/index.html +++ b/osa-2/1-terminologi/index.html @@ -330,4 +330,4 @@ Lön 276.0 euro

    Det verkar som att värdet lagrat i lon är korrekt i början: timlon = 20.0 och timmar = 12, 20,0 * 6 = 120,0. Instruktionen som ska multiplicera det här med två fungerar dock inte. Det måste alltså vara ett problem med den instruktionen:

    lon * 2

    Instruktionen multiplicerar nog värdet, men resultatet lagras ingenstans. Vi ändrar på det:

    lon *= 2

    När vi nu kör programmet, märker vi att resultatet är korrekt:

    Esimerkkitulostus

    villkor: True lön i början: 276.0 lön efter fördubbling: 552.0 -Lön 552.0 euro

    När programmet fungerar som det ska, är det viktigt att ta bort print-satser och annan kod som använts för att debugga.

    Det här var ett ganska enkelt exempel och i fall som det här kan man eventuellt hitta buggar genom att läsa igenom koden med omtanke. Att använda print-satser för att debugga är ändå ofta ett snabbt sätt att få en ledtråd för var problemet kan ligga. print-satser kan också användas för att fastställa vilka delar av koden som fungerar korrekt. Då kan man fokusera på andra ställen där buggar med större sannolikhet gömmer sig.

    print-satser är bara ett sätt att debugga program. Vi återkommer till det här ämnet senare under kursen. Nu ska du bli van vid att debugga, med hjälp av print-instruktioner, för att hitta problematiska delar i din kod. Proffs klarar sig inte utan print-satser i debuggningssyfte – det är alltså en viktig resurs redan som nybörjare.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:

    \ No newline at end of file +Lön 552.0 euro

    När programmet fungerar som det ska, är det viktigt att ta bort print-satser och annan kod som använts för att debugga.

    Det här var ett ganska enkelt exempel och i fall som det här kan man eventuellt hitta buggar genom att läsa igenom koden med omtanke. Att använda print-satser för att debugga är ändå ofta ett snabbt sätt att få en ledtråd för var problemet kan ligga. print-satser kan också användas för att fastställa vilka delar av koden som fungerar korrekt. Då kan man fokusera på andra ställen där buggar med större sannolikhet gömmer sig.

    print-satser är bara ett sätt att debugga program. Vi återkommer till det här ämnet senare under kursen. Nu ska du bli van vid att debugga, med hjälp av print-instruktioner, för att hitta problematiska delar i din kod. Proffs klarar sig inte utan print-satser i debuggningssyfte – det är alltså en viktig resurs redan som nybörjare.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:

    \ No newline at end of file diff --git a/osa-2/2-else-elif/index.html b/osa-2/2-else-elif/index.html index df3bf1e8d..abc5dc60f 100644 --- a/osa-2/2-else-elif/index.html +++ b/osa-2/2-else-elif/index.html @@ -282,4 +282,4 @@ Det är juldag Tack och hej.

    Märk att det föregående exemplet saknar else-gren. Om användaren ger ett datum som inte uppfyller villkoret på någon av if- eller elif-grenarna, kommer ingen av grenarna att köras.

    Esimerkkitulostus

    Julkalender Vilken dag är det? 1/1 -Tack och hej.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:

    \ No newline at end of file +Tack och hej.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:

    \ No newline at end of file diff --git a/osa-2/3-kombinera-villkor/index.html b/osa-2/3-kombinera-villkor/index.html index 4551f845f..bb37c6253 100644 --- a/osa-2/3-kombinera-villkor/index.html +++ b/osa-2/3-kombinera-villkor/index.html @@ -305,4 +305,4 @@ elif nummer > 0 and nummer % 2 != 0: print("Talet är ojämnt") else: - print("Talet är negativt")

    Man kan inte på rak arm säga vilkendera lösning är bättre. Situationen bestämmer ofta hur det lönar sig att bygga upp if-satsen på ett logiskt sätt. I det här exemplet tycker flera personer att versionen med kapsling är mera intuitiv.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:

    \ No newline at end of file + print("Talet är negativt")

    Man kan inte på rak arm säga vilkendera lösning är bättre. Situationen bestämmer ofta hur det lönar sig att bygga upp if-satsen på ett logiskt sätt. I det här exemplet tycker flera personer att versionen med kapsling är mera intuitiv.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:

    \ No newline at end of file diff --git a/osa-2/4-loopar/index.html b/osa-2/4-loopar/index.html index 4ad8ab72a..05919c656 100644 --- a/osa-2/4-loopar/index.html +++ b/osa-2/4-loopar/index.html @@ -356,4 +356,4 @@ forsok += 1 koder += kod + ", " # ...

    Hjälpvariabeln kan tilldelas värdet "" – det vill säga en tom sträng:

    koder = ""

    För varje iteration blir strängen längre i och med att koden användaren angett läggs till i slutet av strängen tillsammans med ett komma och ett mellanslag.

        kod = input("Ange pin-kod: ")
    -    koder += kod + ", "

    Om användaren anger koderna 1111 2222 1234 kommer värdet på koder till slut att vara:

    Esimerkkitulostus

    1111, 2222, 1234,

    Loading...
    :
    Loading...

    Log in to view the quiz

    Vänligen svara på en kort enkät som behandlar den här veckans material.

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file + koder += kod + ", "

    Om användaren anger koderna 1111 2222 1234 kommer värdet på koder till slut att vara:

    Esimerkkitulostus

    1111, 2222, 1234,

    Loading...
    :
    Loading...

    Log in to view the quiz

    Vänligen svara på en kort enkät som behandlar den här veckans material.

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file diff --git a/osa-2/index.html b/osa-2/index.html index 2e0d2c02b..da97045bd 100644 --- a/osa-2/index.html +++ b/osa-2/index.html @@ -150,4 +150,4 @@ } })
    \ No newline at end of file +
    Loading...
    \ No newline at end of file diff --git a/osa-3/1-loopar-med-villkor/index.html b/osa-3/1-loopar-med-villkor/index.html index 0be0a0c08..53dd895b3 100644 --- a/osa-3/1-loopar-med-villkor/index.html +++ b/osa-3/1-loopar-med-villkor/index.html @@ -314,4 +314,4 @@ text += f"vitsordet {vitsord} " text += f"i kursen {kurs}" -print(text)
    Esimerkkitulostus

    Du fick vitsordet 4 i kursen Introkurs i programmering

    I det förra exemplet räknade du summan av varandra påföljande siffror genom att alltid öka på värdet i loopen.

    Samma fungerar också för strängar – du kan lägga till nya delar i en sträng inom en loop. Den här tekniken kan vara till nytta i följande uppgift.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:

    \ No newline at end of file +print(text)
    Esimerkkitulostus

    Du fick vitsordet 4 i kursen Introkurs i programmering

    I det förra exemplet räknade du summan av varandra påföljande siffror genom att alltid öka på värdet i loopen.

    Samma fungerar också för strängar – du kan lägga till nya delar i en sträng inom en loop. Den här tekniken kan vara till nytta i följande uppgift.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:

    \ No newline at end of file diff --git a/osa-3/2-behandla-strangar/index.html b/osa-3/2-behandla-strangar/index.html index d24be5d3d..e8d6e9393 100644 --- a/osa-3/2-behandla-strangar/index.html +++ b/osa-3/2-behandla-strangar/index.html @@ -356,4 +356,4 @@ Hittades inte Vad söker du efter? ampa Hittades på platsen 5 -...

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:

    \ No newline at end of file +...

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:

    \ No newline at end of file diff --git a/osa-3/3-mer-om-loopar/index.html b/osa-3/3-mer-om-loopar/index.html index d4b09ada7..620d75c1f 100644 --- a/osa-3/3-mer-om-loopar/index.html +++ b/osa-3/3-mer-om-loopar/index.html @@ -336,4 +336,4 @@ 0 1 2 3 0 1 2 0 1 -0

    I programmet använder den yttre loopen hjälpvariabeln siffra som minskar med ett tills det når till noll. Hjälpvariabeln i tilldelas värdet 0 före man fortsätter till den inre loopen – varje gång den yttre loopen upprepas.

    Den inre loopen använder sig av hjälpvariabeln i som ökar med talet 1 för varje iteration av den inre loopen. Den inre loopen fortsätter tills i är lika med siffra, och skriver ut varje värde hos i med mellanslag emellan. När loopen avslutas skapar print-instruktionen i den yttre loopen en ny rad.

    I och med att värdet på siffra minskar för varje iteration av den yttre loopen, kommer antalet iterationer hos den inre loopen att minska. Vid varje upprepning blir sifferraden kortare, vilket bildar "pyramiden".

    Kapslade loopar kan vara svårtolkade på en första titt, men det är viktigt att förstå hur de fungerar. Du kan använda dig av Python Tutors visualiseringsverktyg för att bättre förstå hur ovanstående exempel fungerar. Kopiera koden ovan till kodfönstret och följ hur utskriften formar sig och hur hjälpvariablernas värden ändras medan programmet körs.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:

    \ No newline at end of file +0

    I programmet använder den yttre loopen hjälpvariabeln siffra som minskar med ett tills det når till noll. Hjälpvariabeln i tilldelas värdet 0 före man fortsätter till den inre loopen – varje gång den yttre loopen upprepas.

    Den inre loopen använder sig av hjälpvariabeln i som ökar med talet 1 för varje iteration av den inre loopen. Den inre loopen fortsätter tills i är lika med siffra, och skriver ut varje värde hos i med mellanslag emellan. När loopen avslutas skapar print-instruktionen i den yttre loopen en ny rad.

    I och med att värdet på siffra minskar för varje iteration av den yttre loopen, kommer antalet iterationer hos den inre loopen att minska. Vid varje upprepning blir sifferraden kortare, vilket bildar "pyramiden".

    Kapslade loopar kan vara svårtolkade på en första titt, men det är viktigt att förstå hur de fungerar. Du kan använda dig av Python Tutors visualiseringsverktyg för att bättre förstå hur ovanstående exempel fungerar. Kopiera koden ovan till kodfönstret och följ hur utskriften formar sig och hur hjälpvariablernas värden ändras medan programmet körs.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:

    \ No newline at end of file diff --git a/osa-3/4-definiera-funktioner/index.html b/osa-3/4-definiera-funktioner/index.html index cfb03f894..853a63409 100644 --- a/osa-3/4-definiera-funktioner/index.html +++ b/osa-3/4-definiera-funktioner/index.html @@ -274,4 +274,4 @@ halsa("Alice") halsa("Beatrice")
    Esimerkkitulostus

    Hej Beatrice -Hej Beatrice

    Oavsett vilka argument vi anropar funktionen med skrivs värdet "Beatrice" från den globala variabeln ut.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Vänligen svara på en kort enkät gällande den här veckans material.

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file +Hej Beatrice

    Oavsett vilka argument vi anropar funktionen med skrivs värdet "Beatrice" från den globala variabeln ut.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Vänligen svara på en kort enkät gällande den här veckans material.

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file diff --git a/osa-3/index.html b/osa-3/index.html index 65a11ab0c..c4ac4299d 100644 --- a/osa-3/index.html +++ b/osa-3/index.html @@ -150,4 +150,4 @@ } })
    \ No newline at end of file +
    Loading...
    \ No newline at end of file diff --git a/osa-4/1-vscode/index.html b/osa-4/1-vscode/index.html index 945234d21..189b28aec 100644 --- a/osa-4/1-vscode/index.html +++ b/osa-4/1-vscode/index.html @@ -313,4 +313,4 @@ 4 1 9 -

    Du kan ha flera breakpoints i din kod. När körandet av koden har stannat upp kan du starta det genom att klicka på den blå triangeln. Körandet fortsätter tills nästa breakpoint nås.

    Den inbyggda visuella debuggaren är ett bra alternativ till debuggning med print-satser. Det är upp till dig själv vilken metod du använder dig av i fortsättningen. Alla programmerare har sina egna preferenser, men det är alltid en bra idé att testa på olika alternativ förrän man bestämmer sig för att göra på ett visst sätt.

    Seuraava osa:

    \ No newline at end of file +

    Du kan ha flera breakpoints i din kod. När körandet av koden har stannat upp kan du starta det genom att klicka på den blå triangeln. Körandet fortsätter tills nästa breakpoint nås.

    Den inbyggda visuella debuggaren är ett bra alternativ till debuggning med print-satser. Det är upp till dig själv vilken metod du använder dig av i fortsättningen. Alla programmerare har sina egna preferenser, men det är alltid en bra idé att testa på olika alternativ förrän man bestämmer sig för att göra på ett visst sätt.

    Seuraava osa:

    \ No newline at end of file diff --git a/osa-4/2-mer-om-funktioner/index.html b/osa-4/2-mer-om-funktioner/index.html index 1992c4484..10537835c 100644 --- a/osa-4/2-mer-om-funktioner/index.html +++ b/osa-4/2-mer-om-funktioner/index.html @@ -343,4 +343,4 @@ print(meddelande) ganger -= 1

    Det här berättar för alla användare av funktionen att argumentet som lagras i meddelande ska vara en sträng medan argumentet som lagras i ganger ska vara ett heltal.

    Också typen av returvärdet kan specificeras när funktionen definieras:

    def fraga_namn() -> str:
         namn = input("Vad är ditt namn? ")
    -    return namn

    Det här berättar för användaren att funktionen borde returnera en sträng.

    Obs! Typledtrådar är bokstavligen ledtrådar. Det är inte en garanti och kan inte säkerställa att felaktiga datatyper inte ges till eller returneras av en funktion. Om det här sker kommer funktionen ändå att köras, men den fungerar inte nödvändigtvis korrekt.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:

    \ No newline at end of file + return namn

    Det här berättar för användaren att funktionen borde returnera en sträng.

    Obs! Typledtrådar är bokstavligen ledtrådar. Det är inte en garanti och kan inte säkerställa att felaktiga datatyper inte ges till eller returneras av en funktion. Om det här sker kommer funktionen ändå att köras, men den fungerar inte nödvändigtvis korrekt.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:

    \ No newline at end of file diff --git a/osa-4/3-listor/index.html b/osa-4/3-listor/index.html index d20a57bac..37fa9c3f6 100644 --- a/osa-4/3-listor/index.html +++ b/osa-4/3-listor/index.html @@ -388,4 +388,4 @@ vikter = las_in_siffror() print("Pituudet:") -langder = las_in_siffror()
    Loading
    Loading
    Loading

    Mer om att behandla listor

    Det finns flera sätt till att använda listor i Python. Om du vill läsa mera är Pythons dokumentation ett bra ställe att börja med.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    4. Iteration

    \ No newline at end of file +langder = las_in_siffror()
    Loading
    Loading
    Loading

    Mer om att behandla listor

    Det finns flera sätt till att använda listor i Python. Om du vill läsa mera är Pythons dokumentation ett bra ställe att börja med.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    4. Iteration

    \ No newline at end of file diff --git a/osa-4/4-iteration/index.html b/osa-4/4-iteration/index.html index d4cf6b110..378924e39 100644 --- a/osa-4/4-iteration/index.html +++ b/osa-4/4-iteration/index.html @@ -274,4 +274,4 @@ if element bättre än bast: bast = element -# vi vet nu det bästa värdet

    Detaljerna kring den slutliga koden beror på typen av elementen i listan och kriteriet för väljandet av det bästa (eller sämsta) elementet. Ibland kan du behöva fler än en hjälpvariabel.

    Låt oss öva på den här metoden.

    Loading
    Loading
    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    5. Formatera utskrift

    \ No newline at end of file +# vi vet nu det bästa värdet

    Detaljerna kring den slutliga koden beror på typen av elementen i listan och kriteriet för väljandet av det bästa (eller sämsta) elementet. Ibland kan du behöva fler än en hjälpvariabel.

    Låt oss öva på den här metoden.

    Loading
    Loading
    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    5. Formatera utskrift

    \ No newline at end of file diff --git a/osa-4/5-utskrift/index.html b/osa-4/5-utskrift/index.html index d77488b47..9be08d67c 100644 --- a/osa-4/5-utskrift/index.html +++ b/osa-4/5-utskrift/index.html @@ -227,4 +227,4 @@ alder = 59 stad = "Villmanstrand" halsning = f"Hej {namn}, du är {alder} år" -print(halsning + f", du bor i {stad}")
    Esimerkkitulostus

    Hej Leffe, du är 59 år, du bor i Villmanstrand

    Du kan tänka att f-strängen är en slags funktion som skapar en normal sträng baserat på "argumenten" mellan klammerparenteserna.

    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    6. Mera strängar och listor

    \ No newline at end of file +print(halsning + f", du bor i {stad}")
    Esimerkkitulostus

    Hej Leffe, du är 59 år, du bor i Villmanstrand

    Du kan tänka att f-strängen är en slags funktion som skapar en normal sträng baserat på "argumenten" mellan klammerparenteserna.

    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    6. Mera strängar och listor

    \ No newline at end of file diff --git a/osa-4/6-strangar-listor/index.html b/osa-4/6-strangar-listor/index.html index 0c3d7acef..fcc56151f 100644 --- a/osa-4/6-strangar-listor/index.html +++ b/osa-4/6-strangar-listor/index.html @@ -338,4 +338,4 @@ print(analysens_resultat) # start av programmet -main()
    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Vänligen svara på en kort enkät om den här veckans material.

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file +main()
    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Vänligen svara på en kort enkät om den här veckans material.

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file diff --git a/osa-4/index.html b/osa-4/index.html index 703ae42cb..966b38080 100644 --- a/osa-4/index.html +++ b/osa-4/index.html @@ -150,4 +150,4 @@ } })
    \ No newline at end of file +
    Loading...
    \ No newline at end of file diff --git a/osa-5/1-mer-om-listor/index.html b/osa-5/1-mer-om-listor/index.html index 2ee4b1cff..b757282cf 100644 --- a/osa-5/1-mer-om-listor/index.html +++ b/osa-5/1-mer-om-listor/index.html @@ -441,4 +441,4 @@ 7 _ 5 _ 6 _ 4 _ _ _ _ 7 8 _ 3 9 _ _ _ _ 1 _ _ _ _ _ 3 - 3 _ _ _ _ _ _ _ 2

    Flera andra spel kan också representeras på liknande sätt: till exempel schack, minröj, sänka skepp och Mastermind. I sudoku fungerar siffor väl för att representera spelets läge, medan för andra spel kan andra metoder vara bättre.

    Loading
    Loading
    Loading
    Loading
    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    2. Referenser

    \ No newline at end of file + 3 _ _ _ _ _ _ _ 2

    Flera andra spel kan också representeras på liknande sätt: till exempel schack, minröj, sänka skepp och Mastermind. I sudoku fungerar siffor väl för att representera spelets läge, medan för andra spel kan andra metoder vara bättre.

    Loading
    Loading
    Loading
    Loading
    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    2. Referenser

    \ No newline at end of file diff --git a/osa-5/2-referenser/index.html b/osa-5/2-referenser/index.html index 2f16eab75..62e8865ce 100644 --- a/osa-5/2-referenser/index.html +++ b/osa-5/2-referenser/index.html @@ -408,4 +408,4 @@ siffror = [1, 4, 2, 5, 3, 6, 4, 7] print(nast_minst(siffror)) print(siffror)
    Esimerkkitulostus

    2 -[1, 4, 2, 5, 3, 6, 4, 7]

    Funktionen sorted returnerar en ny ordnad kopia av listan, så vi behöver inte mera "sabotera" den ursprungliga listan när vi söker efter det näst minsta värdet.

    Det är en bra vana att undvika sidoeffekter i funktioner. Sidoeffekter kan göra det svårare att säkerställa att programmet fungerar som det ska i alla situationer.

    Funktioner som saknar sidoeffekter kallas rena funktioner. Då man arbetar med funktionell programmering är rena funktioner speciellt viktiga. Vi dyker djupare i det här under fortsättningskursen i programmering.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    3. Lexikon

    \ No newline at end of file +[1, 4, 2, 5, 3, 6, 4, 7]

    Funktionen sorted returnerar en ny ordnad kopia av listan, så vi behöver inte mera "sabotera" den ursprungliga listan när vi söker efter det näst minsta värdet.

    Det är en bra vana att undvika sidoeffekter i funktioner. Sidoeffekter kan göra det svårare att säkerställa att programmet fungerar som det ska i alla situationer.

    Funktioner som saknar sidoeffekter kallas rena funktioner. Då man arbetar med funktionell programmering är rena funktioner speciellt viktiga. Vi dyker djupare i det här under fortsättningskursen i programmering.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    3. Lexikon

    \ No newline at end of file diff --git a/osa-5/3-lexikon/index.html b/osa-5/3-lexikon/index.html index 3966ba8df..44aba19a7 100644 --- a/osa-5/3-lexikon/index.html +++ b/osa-5/3-lexikon/index.html @@ -348,4 +348,4 @@ print("Medellängden är", total_langd / len(personer))
    Esimerkkitulostus

    Peppa Python Philip Python Pedro Python -Medellängden är 173.0

    Loading
    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    4. Tuple

    \ No newline at end of file +Medellängden är 173.0

    Loading
    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    4. Tuple

    \ No newline at end of file diff --git a/osa-5/4-tuple/index.html b/osa-5/4-tuple/index.html index fc8225af6..5638825cc 100644 --- a/osa-5/4-tuple/index.html +++ b/osa-5/4-tuple/index.html @@ -235,4 +235,4 @@ print("nyckel:", nyckel) print("värde:", varde)

    Tupler finns i bakgrunden här också. Metoden lexikon.items() returnerar varje nyckel-värdepar som en tuple, där det första elementet innehåller nyckeln och det andra värdet.

    Ett annat användningsområde för tupler är att byta värden sinsemellan två variabler:

    tal1, tal2 = tal2, tal1

    Tilldelningssatsen ovan svänger på värdena lagrade i variablerna tal1 och tal2. Resultatet är detsamma som vi skulle uppnå med hjälp av en hjälpvariabel:

    hjalp = tal1
     tal1 = tal2
    -tal2 = hjalp
    Loading
    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Vänligen svara på en kort enkät gällande materialet för den här veckan.

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file +tal2 = hjalp
    Loading
    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Vänligen svara på en kort enkät gällande materialet för den här veckan.

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file diff --git a/osa-5/index.html b/osa-5/index.html index 6311cfa3f..0457ce8a0 100644 --- a/osa-5/index.html +++ b/osa-5/index.html @@ -150,4 +150,4 @@ } })
    \ No newline at end of file +
    Loading...
    \ No newline at end of file diff --git a/osa-6/1-lasa-filer/index.html b/osa-6/1-lasa-filer/index.html index 118dedbba..ce5856864 100644 --- a/osa-6/1-lasa-filer/index.html +++ b/osa-6/1-lasa-filer/index.html @@ -444,4 +444,4 @@ '080488-123X': 3300, '290274-044S': 4350, '010479-007Z': 2500 -}

    For-loopen i slutet av programmet kombinerar namnen på arbetstagarna med deras löner.

    Programmet kan också ta i beaktande situationer där pic saknas för en arbetstagare.

    Kom ihåg att ordningen som elementen är lagrade i lexikon inte har någon skillnad, eftersom nycklarna behandlas med hjälp av hashvärden.

    Loading
    Loading
    Loading
    Loading
    Loading
    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    2. Skriva filer

    \ No newline at end of file +}

    For-loopen i slutet av programmet kombinerar namnen på arbetstagarna med deras löner.

    Programmet kan också ta i beaktande situationer där pic saknas för en arbetstagare.

    Kom ihåg att ordningen som elementen är lagrade i lexikon inte har någon skillnad, eftersom nycklarna behandlas med hjälp av hashvärden.

    Loading
    Loading
    Loading
    Loading
    Loading
    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    2. Skriva filer

    \ No newline at end of file diff --git a/osa-6/2-skriva-filer/index.html b/osa-6/2-skriva-filer/index.html index a6f78831e..94bc76d59 100644 --- a/osa-6/2-skriva-filer/index.html +++ b/osa-6/2-skriva-filer/index.html @@ -298,4 +298,4 @@ veckopoang = las_veckopoang("veckopoang.csv") -print(hamta_vitsord("Paula", veckopoang))
    Esimerkkidata

    3

    Om vi märker att någon funktionalitet i programmet kräver åtgärdande, kommer ändringar inte att orsaka följder överallt i koden. Om vi till exempel vill ändra på vitsordsgränserna, behöver vi bara ändra på funktionen som räknar ut vitsordet – alla andra funktioner som använder den här funktionen skulle fortfarande fungera, med de nya gränserna. Om koden för den här funktionaliteten skulle vara splittrad, finns det en risk att vi glömmer att uppdatera koden på något ställe. Det här skulle antagligen orsaka problem.

    Loading
    Loading
    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    3. Förbered dig på fel

    \ No newline at end of file +print(hamta_vitsord("Paula", veckopoang))
    Esimerkkidata

    3

    Om vi märker att någon funktionalitet i programmet kräver åtgärdande, kommer ändringar inte att orsaka följder överallt i koden. Om vi till exempel vill ändra på vitsordsgränserna, behöver vi bara ändra på funktionen som räknar ut vitsordet – alla andra funktioner som använder den här funktionen skulle fortfarande fungera, med de nya gränserna. Om koden för den här funktionaliteten skulle vara splittrad, finns det en risk att vi glömmer att uppdatera koden på något ställe. Det här skulle antagligen orsaka problem.

    Loading
    Loading
    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    3. Förbered dig på fel

    \ No newline at end of file diff --git a/osa-6/3-fel/index.html b/osa-6/3-fel/index.html index 2500a90af..5011fcb70 100644 --- a/osa-6/3-fel/index.html +++ b/osa-6/3-fel/index.html @@ -312,4 +312,4 @@ print(fakultet(-1)) File "testi.py", line 3, in fakultet raise ValueError("Negativt värde: " + str(n)) -ValueError: Negativt värde: -1
    Loading
    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    4. Lokala och globala variabler

    \ No newline at end of file +ValueError: Negativt värde: -1
    Loading
    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    4. Lokala och globala variabler

    \ No newline at end of file diff --git a/osa-6/4-lokala-globala-variabler/index.html b/osa-6/4-lokala-globala-variabler/index.html index 332480500..0523b1796 100644 --- a/osa-6/4-lokala-globala-variabler/index.html +++ b/osa-6/4-lokala-globala-variabler/index.html @@ -330,4 +330,4 @@ print(analys) # start av programmet -main()
    Loading...
    :
    Loading...

    Log in to view the quiz

    Vänligen svara på en kort enkät gällande materialet för den här veckan.

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file +main()
    Loading...
    :
    Loading...

    Log in to view the quiz

    Vänligen svara på en kort enkät gällande materialet för den här veckan.

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file diff --git a/osa-6/index.html b/osa-6/index.html index 947820175..1595724ae 100644 --- a/osa-6/index.html +++ b/osa-6/index.html @@ -150,4 +150,4 @@ } })
    \ No newline at end of file +
    Loading...
    \ No newline at end of file diff --git a/osa-7/1-moduler/index.html b/osa-7/1-moduler/index.html index cdef8153e..322eaa94e 100644 --- a/osa-7/1-moduler/index.html +++ b/osa-7/1-moduler/index.html @@ -251,4 +251,4 @@
  • https://docs.python.org/3/library/math.html
  • Vi kan också kolla på innehållet i en modul med funktionen dir:

    import math
     
    -print(dir(math))

    Den här funktionen returnerar en lista av namn definierade av modulen. Det kan vara namn på klasser, fixerade värden eller funktioner:

    Esimerkkitulostus

    ['__doc__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'hypot', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']

    Loading
    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    2. Slumpmässighet

    \ No newline at end of file +print(dir(math))

    Den här funktionen returnerar en lista av namn definierade av modulen. Det kan vara namn på klasser, fixerade värden eller funktioner:

    Esimerkkitulostus

    ['__doc__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'hypot', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']

    Loading
    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    2. Slumpmässighet

    \ No newline at end of file diff --git a/osa-7/2-slumpmassighet/index.html b/osa-7/2-slumpmassighet/index.html index fbcc87a63..34f9b00e0 100644 --- a/osa-7/2-slumpmassighet/index.html +++ b/osa-7/2-slumpmassighet/index.html @@ -252,4 +252,4 @@ seed(1337) # det här genererar alltid samma tal -print(randint(1, 100))

    Om vi har funktioner som baserar sig på slumpmässighet och har valt ett seed-värde, kommer funktionen att ge samma resultat varje gång den körs. Resultatet kan skilja sig mellan olika Python-versioner, men i grunden kommer slumpmässigheten att försvinna då vi definierar seed-värdet. Funktionaliteten kan dock vara nyttig då vi exempelvis testar på vårt program.

    Loading
    Loading
    Loading
    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    3. Tid och datum

    \ No newline at end of file +print(randint(1, 100))

    Om vi har funktioner som baserar sig på slumpmässighet och har valt ett seed-värde, kommer funktionen att ge samma resultat varje gång den körs. Resultatet kan skilja sig mellan olika Python-versioner, men i grunden kommer slumpmässigheten att försvinna då vi definierar seed-värdet. Funktionaliteten kan dock vara nyttig då vi exempelvis testar på vårt program.

    Loading
    Loading
    Loading
    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    3. Tid och datum

    \ No newline at end of file diff --git a/osa-7/3-tid-datum/index.html b/osa-7/3-tid-datum/index.html index 0788cfcc0..920b4de34 100644 --- a/osa-7/3-tid-datum/index.html +++ b/osa-7/3-tid-datum/index.html @@ -301,4 +301,4 @@ print("Du föddes på förra årtusendet") else: print("Du föddes på det här årtusendet")
    Esimerkkitulostus

    Ange din födelsetid i formatet dd.mm.åååå: 5.11.1986 -Du föddes på förra årtusendet

    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    4. Behandla data

    \ No newline at end of file +Du föddes på förra årtusendet

    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    4. Behandla data

    \ No newline at end of file diff --git a/osa-7/4-behandla-data/index.html b/osa-7/4-behandla-data/index.html index 0f279b610..237ddc719 100644 --- a/osa-7/4-behandla-data/index.html +++ b/osa-7/4-behandla-data/index.html @@ -247,4 +247,4 @@
  • https://docs.python.org/3/library/
  • Förutom standardbiblioteket är internet fullproppat med andra Python-moduler för olika ändamål. Några vanliga moduler listas på den här sidan:

    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    5. Skapa dina egna moduler

    \ No newline at end of file +
    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    5. Skapa dina egna moduler

    \ No newline at end of file diff --git a/osa-7/5-egna-moduler/index.html b/osa-7/5-egna-moduler/index.html index 6fe54e3fc..eadd2f554 100644 --- a/osa-7/5-egna-moduler/index.html +++ b/osa-7/5-egna-moduler/index.html @@ -292,4 +292,4 @@ print(ord.sista_ordet(strang)) print(ord.antal_ord(strang))
    Esimerkkitulostus

    Polisstationen full -3

    I uppgifterna under den här kursen har du flera gånger ombetts att ha dina test under ett if __name__ == "__main__" -block. Nu vet du varför.

    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Vänligen svara på en kort enkät om materialet för den här veckan.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    6. Flera funktionaliteter i Python

    \ No newline at end of file +3

    I uppgifterna under den här kursen har du flera gånger ombetts att ha dina test under ett if __name__ == "__main__" -block. Nu vet du varför.

    Loading
    Loading...
    :
    Loading...

    Log in to view the quiz

    Vänligen svara på en kort enkät om materialet för den här veckan.

    Loading...
    :
    Loading...

    Log in to view the quiz

    Seuraava osa:
    6. Flera funktionaliteter i Python

    \ No newline at end of file diff --git a/osa-7/6-funktionaliteter-python/index.html b/osa-7/6-funktionaliteter-python/index.html index 808088bc6..457200656 100644 --- a/osa-7/6-funktionaliteter-python/index.html +++ b/osa-7/6-funktionaliteter-python/index.html @@ -232,4 +232,4 @@ print("Deras summa är", sum(lista)) test(1, 2, 3, 4, 5)
    Esimerkkitulostus

    Du gav 5 argument -Deras summa är 15

    Loading

    Vänligen svara på kursfeedbacksenkäten här nedan. Enkätens resultat hjälper oss att utveckla och förbättra den här kursen.

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file +Deras summa är 15

    Loading

    Vänligen svara på kursfeedbacksenkäten här nedan. Enkätens resultat hjälper oss att utveckla och förbättra den här kursen.

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file diff --git a/osa-7/index.html b/osa-7/index.html index a9defd3c2..696d9284f 100644 --- a/osa-7/index.html +++ b/osa-7/index.html @@ -150,4 +150,4 @@ } })
    \ No newline at end of file +
    Loading...
    \ No newline at end of file diff --git a/osa-8/1-objekt-och-metoder/index.html b/osa-8/1-objekt-och-metoder/index.html index 1e72290f1..246a35f51 100644 --- a/osa-8/1-objekt-och-metoder/index.html +++ b/osa-8/1-objekt-och-metoder/index.html @@ -216,12 +216,12 @@ Sju Python Ett nytt namn Sju Python

    - - + + - - - 8 1 1 + + + 8 1 1

    Objekt och metoder

    Datan som lagras i ett objekt kan kommas åt genom olika metoder. En metod är en funktion som opererar på ett specifikt objekt som den är kopplad till. Sättet att åtskilja mellan metoder och andra funktioner ligger i hur de är kallade: först skriver man namnet på objektet som avses, sedan en punkt och till sist metodens namn, åtföljt av argument ifall sådana finns. Till exempel returnerar metoden values alla värden som är lagrade i ett objekt av typen ordlista eller dict:

    # detta skapar ett objekt av typen ordlista med namnet bok
    @@ -260,4 +260,4 @@
     lista.pop(0)
     
     print(lista)
    Esimerkkitulostus

    [1, 2, 3, 5, 1] -[2, 3, 5, 1]

    Loading
    Loading
    Seuraava osa:
    2. Klasser och objekt

    \ No newline at end of file +[2, 3, 5, 1]

    Loading
    Loading
    Seuraava osa:
    2. Klasser och objekt

    \ No newline at end of file diff --git a/osa-8/2-klasser-och-objekt/index.html b/osa-8/2-klasser-och-objekt/index.html index 9c6f0a9e7..afeb2b53e 100644 --- a/osa-8/2-klasser-och-objekt/index.html +++ b/osa-8/2-klasser-och-objekt/index.html @@ -256,4 +256,4 @@ Månad: 12

    Veckodagen som datumet infaller på är tillgänglig via metoden isoweekday:

    veckodag = dag.isoweekday()

    Detta är en metodkallelse, alltså finns det parenteser efter namnet på metoden. Om du lämnar bort parenteserna uppstår det inte något fel, men resultatet blir konstigt:

    veckodag =  dag.isoweekday
     print("Veckodag:", veckodag)
    Esimerkkitulostus

    Veckodag: <built-in method isoweekday of datetime.date object at 0x10ed66450>

    Månaden av ett date-objekt är en variabel, alltså kan det tillgivna värdet kommas åt med en referens.

    manad = dag.month

    Lägg märke till att det inte finns parenteser här. Att sätta in parenteser skulle orsaka ett fel:

    manad = dag.month()
    Esimerkkitulostus
    Traceback (most recent call last): File "", line 1, in -TypeError: 'int' object is not callable
    Loading
    Loading
    Seuraava osa:
    3. Egna klasser

    \ No newline at end of file +TypeError: 'int' object is not callable
    Loading
    Loading
    Seuraava osa:
    3. Egna klasser

    \ No newline at end of file diff --git a/osa-8/3-egna-klasser/index.html b/osa-8/3-egna-klasser/index.html index 8a4c2d7b3..9e378820c 100644 --- a/osa-8/3-egna-klasser/index.html +++ b/osa-8/3-egna-klasser/index.html @@ -304,4 +304,4 @@ tillagg_pengar_pa_kontot(peters_konto, 500) print(peters_konto.saldo)
    Esimerkkitulostus

    0 -500

    Loading
    Loading
    Loading
    Seuraava osa:
    4. Metoder i egna klasser

    \ No newline at end of file +500

    Loading
    Loading
    Loading
    Seuraava osa:
    4. Metoder i egna klasser

    \ No newline at end of file diff --git a/osa-8/4-metoder-i-egna-klasser/index.html b/osa-8/4-metoder-i-egna-klasser/index.html index e36cd8485..92da18ad6 100644 --- a/osa-8/4-metoder-i-egna-klasser/index.html +++ b/osa-8/4-metoder-i-egna-klasser/index.html @@ -307,15 +307,15 @@ if __name__ == "__main__": resultat1 = PersonligtRekord("Peter", 1, 11, 2020, 235) - print(tulos1.poang) - print(tulos1.spelare) - print(tulos1.datum) + print(resultat1.poang) + print(resultat1.spelare) + print(resultat1.datum) # Datumet är inte giltigt resultat2 = PersonligtRekord("Pernilla", 4, 13, 2019, 4555) - print(tulos2.poang) - print(tulos2.spelare) - print(tulos2.datum) # Skriver ut standardvärdet 1900-01-01
    Esimerkkitulostus

    235 + print(resultat2.poang) + print(resultat2.spelare) + print(resultat2.datum) # Skriver ut standardvärdet 1900-01-01

    Esimerkkitulostus

    235 Peter 2020-11-01 4555 @@ -341,4 +341,4 @@ self.saldo += superbonus def __str__(self): - return f"Bonuskort(namn={self.namn}, saldo={self.saldo})"

    Loading
    Loading
    Seuraava osa:

    \ No newline at end of file + return f"Bonuskort(namn={self.namn}, saldo={self.saldo})"
    Loading
    Loading
    Seuraava osa:
    5. Fler exempel

    \ No newline at end of file diff --git a/osa-8/5-fler-exempel/index.html b/osa-8/5-fler-exempel/index.html index ccd48a29a..3b3f6d636 100644 --- a/osa-8/5-fler-exempel/index.html +++ b/osa-8/5-fler-exempel/index.html @@ -282,4 +282,4 @@ dejt studier 1 -0

    Loading

    Vänligen svara på en snabb enkät om veckans material:

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file +0

    Loading

    Vänligen svara på en snabb enkät om veckans material:

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file diff --git a/osa-8/index.html b/osa-8/index.html index 1865dac2e..adbe316ba 100644 --- a/osa-8/index.html +++ b/osa-8/index.html @@ -150,4 +150,4 @@ } })
    \ No newline at end of file +
    Loading...
    \ No newline at end of file diff --git a/osa-9/1-objekt-och-referenser/index.html b/osa-9/1-objekt-och-referenser/index.html index b249cd9a0..c7281a228 100644 --- a/osa-9/1-objekt-och-referenser/index.html +++ b/osa-9/1-objekt-och-referenser/index.html @@ -233,12 +233,12 @@ affarslista.append(mjolk) affarslista.append(mjolk) affarslista.append(Produkt("Gurka", "st")) - - + + - - - 9 1 1 + + + 9 1 1

    Om det finns mer än en referens till samma objekt spelar det ingen roll vilken av referenserna som används:

    class Hund:
    @@ -540,4 +540,4 @@
     
         # Detta fungerar inte, Person måste vara innanför citationstecken
         def aldre_an(self, annat: Person):
    -        return self.fodelsear < annat.fodelsear:
    Loading
    Seuraava osa:
    2. Objekt som attribut

    \ No newline at end of file + return self.fodelsear < annat.fodelsear:
    Loading
    Seuraava osa:
    2. Objekt som attribut

    \ No newline at end of file diff --git a/osa-9/2-objekt-som-attribut/index.html b/osa-9/2-objekt-som-attribut/index.html index edfa46309..04d4289ea 100644 --- a/osa-9/2-objekt-som-attribut/index.html +++ b/osa-9/2-objekt-som-attribut/index.html @@ -308,4 +308,4 @@ if spelare is not None: print(f"Johans målmängd {p.mal}") else: - print(f"Johan spelar inte i Gumtäkts boll :(")
    Esimerkkitulostus

    Johan spelar inte i Gumtäkts boll :(

    Loading
    Seuraava osa:
    3. Inkapsling

    \ No newline at end of file + print(f"Johan spelar inte i Gumtäkts boll :(")
    Esimerkkitulostus

    Johan spelar inte i Gumtäkts boll :(

    Loading
    Seuraava osa:
    3. Inkapsling

    \ No newline at end of file diff --git a/osa-9/3-inkapsling/index.html b/osa-9/3-inkapsling/index.html index ffca52044..b63e88f39 100644 --- a/osa-9/3-inkapsling/index.html +++ b/osa-9/3-inkapsling/index.html @@ -344,4 +344,4 @@
  • Idag åt jag gröt
  • Idag lärde jag mig objekt-orienterad programmering
  • Idag lade jag mig tidigt
  • -
    Loading
    Seuraava osa:
    4. Metodernas räckvidd

    \ No newline at end of file +
    Loading
    Seuraava osa:
    4. Metodernas räckvidd

    \ No newline at end of file diff --git a/osa-9/4-metodernas-rackvidd/index.html b/osa-9/4-metodernas-rackvidd/index.html index feecbbe20..31eae173a 100644 --- a/osa-9/4-metodernas-rackvidd/index.html +++ b/osa-9/4-metodernas-rackvidd/index.html @@ -244,4 +244,4 @@ print(hand1) hand2 = kortlek.dela(5) print(hand2)

    Eftersom händerna är slumpmässigt genererade, är följande endast ett exempel av det som kunde utskrivas:

    Esimerkkitulostus

    [('spader', 7), ('spader', 11), ('hjarter', 7), ('ruter', 3), ('spader', 4)] -[('klover', 8), ('spader', 12), ('ruter', 13), ('klover', 11), ('spader', 10)]

    Privata metoder är i allmänhet mindre vanliga än privata attribut. En tumregel är att en metod ska döljas när klienten inte har något behov av att direkt komma åt den. Detta är särskilt fallet när det är möjligt att klienten kan påverka objektets integritet negativt genom att anropa metoden.

    Loading
    Seuraava osa:
    5. Klassattribut

    \ No newline at end of file +[('klover', 8), ('spader', 12), ('ruter', 13), ('klover', 11), ('spader', 10)]

    Privata metoder är i allmänhet mindre vanliga än privata attribut. En tumregel är att en metod ska döljas när klienten inte har något behov av att direkt komma åt den. Detta är särskilt fallet när det är möjligt att klienten kan påverka objektets integritet negativt genom att anropa metoden.

    Loading
    Seuraava osa:
    5. Klassattribut

    \ No newline at end of file diff --git a/osa-9/5-klassattribut/index.html b/osa-9/5-klassattribut/index.html index 7e065955f..5e0def70a 100644 --- a/osa-9/5-klassattribut/index.html +++ b/osa-9/5-klassattribut/index.html @@ -354,4 +354,4 @@ return True
    reg = Registration("Bertil Bilist", "Volvo", "1992", "abc-123")
     
     if Registration.registernummer_giltigt("xyz-789"):
    -    print("Detta är ett giltigt nummer!")
    Esimerkkitulostus

    Detta är ett giltigt nummer!

    Giltigheten för en registernummer kan kontrolleras även utan att skapa en enda instans av klassen, t.ex. med Registration.nummer_plat_giltig("xyz-789"). Samma metod anropas i klassens konstruktor. OBS: även inom konstruktören är denna metod åtkomlig via klassens namn, inte self!

    Loading
    Seuraava osa:
    6. Fler exempel med klasser

    \ No newline at end of file + print("Detta är ett giltigt nummer!")
    Esimerkkitulostus

    Detta är ett giltigt nummer!

    Giltigheten för en registernummer kan kontrolleras även utan att skapa en enda instans av klassen, t.ex. med Registration.nummer_plat_giltig("xyz-789"). Samma metod anropas i klassens konstruktor. OBS: även inom konstruktören är denna metod åtkomlig via klassens namn, inte self!

    Loading
    Seuraava osa:
    6. Fler exempel med klasser

    \ No newline at end of file diff --git a/osa-9/6-fler-exempel-med-klasser/index.html b/osa-9/6-fler-exempel-med-klasser/index.html index de63b4301..bb8162f85 100644 --- a/osa-9/6-fler-exempel-med-klasser/index.html +++ b/osa-9/6-fler-exempel-med-klasser/index.html @@ -384,4 +384,4 @@ print(studerande1.gjorda_kurser) print(studerande2.gjorda_kurser)
    Esimerkkitulostus

    ['ItP', 'Tira'] -[]

    Den stora finalen

    Fastän följande övning avslutar den här delen av materialet, så har de tekniker som krävs för att lösa den redan behandlats i avsnittet som heter Objekt som attribut. Du behöver inte använda @property-dekoratorn eller standardvärden för parametrar i den här övningen. Den här övningen är mycket lik övningarna en presentask och den kortaste personen i rummet.

    Loading

    Svara avslutningsvis på följande frågeformulär:

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file +[]

    Den stora finalen

    Fastän följande övning avslutar den här delen av materialet, så har de tekniker som krävs för att lösa den redan behandlats i avsnittet som heter Objekt som attribut. Du behöver inte använda @property-dekoratorn eller standardvärden för parametrar i den här övningen. Den här övningen är mycket lik övningarna en presentask och den kortaste personen i rummet.

    Loading

    Svara avslutningsvis på följande frågeformulär:

    Loading...
    :
    Loading...

    Log in to view the quiz

    \ No newline at end of file diff --git a/osa-9/index.html b/osa-9/index.html index cf4ed4196..7256f3f84 100644 --- a/osa-9/index.html +++ b/osa-9/index.html @@ -150,4 +150,4 @@ } })
    \ No newline at end of file +
    Loading...
    \ No newline at end of file diff --git a/page-data/osa-11/1-list-comprehension/page-data.json b/page-data/osa-11/1-list-comprehension/page-data.json index 5d261f452..c7718d564 100644 --- a/page-data/osa-11/1-list-comprehension/page-data.json +++ b/page-data/osa-11/1-list-comprehension/page-data.json @@ -1,5 +1,5 @@ { "componentChunkName": "component---src-templates-course-content-template-js", "path": "/osa-11/1-list-comprehension", - "result": {"data":{"page":{"htmlAst":{"type":"element","tagName":"div","properties":{},"children":[{"type":"element","tagName":"text-box","properties":{"variant":"learningObjectives","name":"Inlärningsmål"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Efter den här delen"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Vet du vad list comprehension är"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Kommer du att kunna använda list comprehensions för att skapa nya listor"}]},{"type":"text","value":"\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"En av de situationer där programmering är som mest kraftfull är vid bearbetning av sekvenser av objekt och händelser. Datorer är bra på att upprepa saker. I de tidigare delarna av det här materialet har vi till exempel itererat strängar, listor och ordlistor på olika sätt."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss anta att vi har en lista med heltal och att vi skulle behöva samma lista med objekt i strängformat. Ett traditionellt sätt att utföra uppgiften skulle kunna se ut så här:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"talen "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"6"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\nstrangar "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" talen"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n strangar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"list-comprehension","style":"position:relative;"},"children":[{"type":"text","value":"List comprehension"},{"type":"element","tagName":"a","properties":{"href":"#list-comprehension","ariaLabel":"list comprehension permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Det finns också ett mer \"pythoniskt\" sätt att generera listor från befintliga listor. Dessa kallas list comprehensions."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Tanken är att på en enda rad få plats med både beskrivningen av vad som ska göras med varje objekt i listan och tilldelningen av resultatet till en ny lista."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I exemplet ovan var operationen som utfördes på varje objekt i listan mycket enkel: varje heltal omvandlades till en sträng. Låt oss se hur detta skulle se ut implementerat med en list comprehension:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"talen "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"6"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\nstrangar "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" talen"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Den andra raden ovan innehåller många av samma element som den mer traditionella iterativa metoden, men syntaxen är annorlunda. Ett sätt att generalisera en list comprehension skulle kunna vara"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"[ for in ]"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Hakparenteserna runt list comprehensionsatsen signalerar till Python att resultatet ska vara en ny lista. En efter en bearbetas varje objekt i den ursprungliga listan och resultatet lagras i den nya listan, precis som i det iterativa tillvägagångssättet ovan. Som resultat har vi en ny lista med exakt lika många objekt som i originalet, och alla objekt har behandlats på ett identiskt sätt."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"(OBS: originalen till bilderna i denna del saknas tillfälligt, vilket är anledningen till att det finns en del finskt vokabulär i illustrationerna i denna del. Vi arbetar på att åtgärda detta)."}]},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-wrapper"],"style":"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 301px; margin-bottom: 1rem;"},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"a","properties":{"className":["gatsby-resp-image-link"],"href":"/ohjelmointi-24-sv/static/3f079cde22be6cf33b7be317492aa108/fb933/11_1_2.png","style":"display: block","target":"_blank","rel":["noopener"]},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-background-image"],"style":"padding-bottom: 131.7391304347826%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAaCAYAAAC3g3x9AAAACXBIWXMAAAsTAAALEwEAmpwYAAACRUlEQVRIx42V16oCQQyG5/0fyStBRUQUbCCiggWx995y+AJZouyuJxAmk/JvJpnJBkmhx+Mh1WpVCoWCtFot+Q+F7XYrSbzb7eRyucj5fJbT6SRpvsZhNptpJtfrVZBZ2S8WCzkejyqv12vl5/OpOmxxMchhs9lE6XqZ7HCCyA62MmCLi0EOq9UqUiyXS3m/3yqT0e12U5msYAgdNghfYozACvP5XFMdjUZ6FHg8HuuKMzI+MDI6k82fWDDQB/sSGez3e/0SK42ACMBO/ew02LwvsXayYAJER+kUxAqI1ZIggExnPsQYgRX8Brrf7+pIrQ6HgwbAAGIjI2w0gL2P1Qy9wtbX66VgMLWyOgICIHp84mIjwG/mWLySSqUimUxGyuWyNJtN1WGLi4kAPagV2u5dHPmm+LgPQJ82R6P4dDiXy0mpVJJ8Pi/ZbDZqkjXPgyUC4kzBAbULTlPsqOx/AvrUAQMIEDrc7Xal1+upTEOw2bOMPbLvlO80GQ0GA6nVasrI6HyHU7tsZPeNZwaADQdkdNjsDn7Hf7wUvmz3jGDGEmyAtseGD76W7cdLofg4UGiuBAH2lnn42GFkuzbmQwyx2DVDXkC/39cacU2m06leXmQmCKOf1cvY8DGZWDB02vh5ljQP7Rn+mofIqRPbjsHRrAR+2sRO7OFwqA58FRklexu4yJPJRJl62UBFjy8xxLJHDrQ/iX0H/U1Iiwlp/1iuRaPRkHa7LfV6XYrFYvTkEv/LcWPIGkMjOp2OHhFG/p4y3/wHBFfbIcHIViUAAAAASUVORK5CYII='); background-size: cover; display: block;"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"picture","properties":{},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/3f079cde22be6cf33b7be317492aa108/a0b58/11_1_2.webp 230w","/ohjelmointi-24-sv/static/3f079cde22be6cf33b7be317492aa108/c4c4c/11_1_2.webp 301w"],"sizes":"(max-width: 301px) 100vw, 301px","type":"image/webp"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/3f079cde22be6cf33b7be317492aa108/81c8e/11_1_2.png 230w","/ohjelmointi-24-sv/static/3f079cde22be6cf33b7be317492aa108/fb933/11_1_2.png 301w"],"sizes":"(max-width: 301px) 100vw, 301px","type":"image/png"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"img","properties":{"className":["gatsby-resp-image-image"],"src":"/ohjelmointi-24-sv/static/3f079cde22be6cf33b7be317492aa108/fb933/11_1_2.png","alt":"11 1 2","title":"11 1 2","loading":"lazy","decoding":"async","style":"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"},"children":[]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"List comprehensions kan också hantera mycket mer komplicerade operationer. Vi kan utföra beräkningar, till exempel multiplicera de ursprungliga objekten med tio:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"talen "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"list"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"range"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"talen"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\ntalen_multiplicerade "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"tal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" talen"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"talen_multiplicerade"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[1, 2, 3, 4, 5, 6, 7, 8, 9]\n[10, 20, 30, 40, 50, 60, 70, 80, 90]"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Faktum är att uttrycket i list comprehension-satsen kan vara vilket Python-uttryck som helst. Du kan till och med anropa funktioner som du själv har definierat:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"fakultet"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","triple-quoted-string","string"]},"children":[{"type":"text","value":"\"\"\" Funktionen räknar fakulteten n! för positiva heltal \"\"\""}]},{"type":"text","value":"\n k "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"while"}]},{"type":"text","value":" n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n k "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*="}]},{"type":"text","value":" n\n n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" k\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n lista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n fakulteter "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"fakultet"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"fakulteter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[120, 2, 24, 6, 1]"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Med den mer välbekanta "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":"-loopen skulle samma process kunna uttryckas så här:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"fakultet"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","triple-quoted-string","string"]},"children":[{"type":"text","value":"\"\"\" Funktionen räknar fakulteten n! för positiva heltal \"\"\""}]},{"type":"text","value":"\n k "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"while"}]},{"type":"text","value":" n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n k "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*="}]},{"type":"text","value":" n\n n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" k\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n lista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n fakulteter "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n fakulteter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"fakultet"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"fakulteter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"List Comprehensions gör att vi kan uttrycka samma funktionalitet på ett mer konsekvent sätt, vanligtvis utan att förlora något av läsbarheten."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Vi kan också returnera en list comprehension-sats direkt från en funktion. Om vi behövde en funktion för att producera fakultettal för listor med tal, skulle vi kunna göra det på ett mycket kortfattat sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"fakulteter"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"talen"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"list"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"fakultet"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" talen"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Kvadratrötter","tmcname":"osa11-01_kvadratrotter"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skriv en funktion med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"kvadratrot(nummer: list)"}]},{"type":"text","value":" som tar en lista med heltal som sitt argument. Funktionen ska returnera en ny lista som innehåller kvadratrötterna av de ursprungliga heltalen."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Modulen "},{"type":"element","tagName":"a","properties":{"href":"https://docs.python.org/3/library/math.html","target":"_blank","rel":["noopener","noreferrer"]},"children":[{"type":"text","value":"math"}]},{"type":"text","value":" från Pythons standardbibliotek innehåller en lämplig funktion för att räkna ut kvadratrötter."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen bör använda en list comprehension. Funktionen får vara högst två rader lång, inklusive rubrikraden som börjar med nyckelordet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska fungera enligt följande:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"rader "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" kvadratrot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" rad "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" rader"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"1.0\n1.4142135623730951\n1.7320508075688772\n2.0"}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Stjärnrader","tmcname":"osa11-02_stjarnrader"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa funktionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"stjarnrader(nummer: list)"}]},{"type":"text","value":" som tar en lista med heltal som sitt argument. Funktionen ska returnera en ny lista som innehåller rader med stjärnor. Längden på varje rad ska motsvara heltalet på samma index i den ursprungliga listan. Funktionen bör använda en list comprehension för att uppnå detta."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen får vara högst två rader lång, inklusive rubrikraden som börjar med nyckelordet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska fungera på följande sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"rader "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" stjarnrader"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" rad "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" rader"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nrader "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" stjarnrader"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" rad "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" rader"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"pre","properties":{},"children":[{"type":"text","value":"*\n**\n***\n****\n\n****\n***\n**\n*\n**********\n"}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Bäst provresultat","tmcname":"osa11-03_bast_provresultat"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I uppgiftsbotten finns färdigt en klassdefinition för "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Provresultat"}]},{"type":"text","value":", som har följane offentliga attribut:"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"namn"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"vitsord1"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"vitsord2"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"vitsord3"}]},{"type":"text","value":"\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en funktion med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"bast_resultat(resultat: list)"}]},{"type":"text","value":" som tar en lista med Provresultat-objekt som sitt argument."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska returnera en ny lista som endast innehåller det bästa resultatet från varje Provresultat-objekt. Funktionen bör använda en list comprehension för att uppnå detta."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska fungera på följande sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"resultat1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Provresultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nresultat2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Provresultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Pernilla\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nresultat3 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Provresultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Paulus\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nprestationer "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"resultat1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" resultat2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" resultat3"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"bast_resultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"prestationer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[5, 4, 3]"}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Längder","tmcname":"osa11-04_langder"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en funktion med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"langder(listor: list)"}]},{"type":"text","value":" som tar en lista innehållande listor med heltal som argument. Funktionen ska returnera en ny lista som innehåller längderna på listorna i argumentlistan."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen bör använda en list comprehension för att uppnå detta."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska fungera på följande sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"listat "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"324"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"31"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"langder"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"listat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[5, 4, 0]"}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"att-filtrera-foremal","style":"position:relative;"},"children":[{"type":"text","value":"Att filtrera föremål"},{"type":"element","tagName":"a","properties":{"href":"#att-filtrera-foremal","ariaLabel":"att filtrera foremal permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I exemplen ovan var alla våra listor lika långa före och efter en list comprehension-operation. I varje fall användes alla föremål i den ursprungliga listan som grund för den nya listan. Men ibland behöver vi bara några av de ursprungliga föremålen. Hur kan detta åstadkommas?"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"En list comprehension-sats kan också innehålla ett villkor, så att vi kan kontrollera objekten mot villkoret och bara välja ut dem som matchar. Den allmänna syntaxen är enligt följande:"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"[ for in if ]"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Satsen ovan är i övrigt identisk med den allmänna form som introducerades i början av detta avsnitt, men nu finns det en if-sats i slutet. Endast de objekt från den ursprungliga listan för vilka det booleska uttrycket är sant används som grund för den nya listan."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I exemplet nedan väljer vi alla jämna objekt från den ursprungliga listan som bas för den nya listan. I själva verket bearbetas inte dessa objekt ytterligare på något sätt, utan de tilldelas den nya listan som de är:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"lista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"6"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"12"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\njamna "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"foremal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" foremal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" lista "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" foremal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"%"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"jamna"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[2, 4, 6, 4, 10, 12]"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Uttrycket i list comprehension-satsen ovan är bara ett enkelt "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"foremal"}]},{"type":"text","value":", vilket innebär att inga operationer ska utföras på föremålen i listan. Uttrycket kan vara vilket Python-uttryck som helst, precis som i de tidigare exemplen. Följande list comprehension-sats tar till exempel alla jämna föremål i en lista, multiplicerar varje föremål med tio och lagrar resultatet i en ny lista:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"lista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"6"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"12"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\njamna "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"foremal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" foremal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" lista "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" foremal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"%"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"jamna"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[20, 40, 60, 40, 100, 120]"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"När du stöter på mer och mer komplicerade list comprehensions kan det vara bra att försöka läsa villkoret först. Föremålen bearbetas ändå bara om de klarar testet, så det är ofta vettigt att först ta reda på vilka objekt som klarar filtreringssteget. Ibland skulle uttrycket i en list comprehension-sats inte ens vara möjligt för alla föremål i den ursprungliga listan."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Till exempel är fakultettal bara definierat för icke-negativa heltal. Om vi inte kan vara säkra på att en lista bara innehåller värden på noll eller högre, måste innehållet filtreras innan det skickas vidare till den fakultetfunktion som vi skapade tidigare:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"fakultet"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","triple-quoted-string","string"]},"children":[{"type":"text","value":"\"\"\" Funktionen räknar fakulteten n! för positiva heltal \"\"\""}]},{"type":"text","value":"\n k "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"while"}]},{"type":"text","value":" n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n k "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*="}]},{"type":"text","value":" n\n n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" k\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n lista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n fakulteter "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"fakultet"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" lista "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"fakulteter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[6, 24, 120, 1]"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Som vi såg i vårt allra första exempel på list comprehension, där heltal omvandlades till strängar, behöver föremålen i den nya listan inte vara av samma typ som föremålen i den ursprungliga listan. Om vi fortsätter från fakultetexemplet ovan kan vi skapa en tupel från varje originella föremål och dess bearbetade motsvarighet och lagra dessa i en lista, vilket kombinerar allt vi har lärt oss hittills i en enda list comprehension-sats:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"fakultet"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","triple-quoted-string","string"]},"children":[{"type":"text","value":"\"\"\" Funktionen räknar fakulteten n! för positiva heltal \"\"\""}]},{"type":"text","value":"\n k "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"while"}]},{"type":"text","value":" n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n k "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*="}]},{"type":"text","value":" n\n n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" k\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n lista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"6"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n fakulteter "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" fakultet"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" lista "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"and"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"%"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"fakulteter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[(2, 2), (4, 24), (6, 720)]"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Om vi plockar isär exemplet ovan har vi det booleska uttrycket "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"n > 0 and n % 2 == 0"}]},{"type":"text","value":". Detta innebär att endast föremål som är både positiva och delbara med två accepteras för vidare bearbetning från den ursprungliga listan."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Dessa positiva, jämna tal bearbetas sedan i tur och ordning till formatet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"(n, fakultet(n))"}]},{"type":"text","value":". Detta är en tupel, där det första objektet är själva talet och det andra objektet är resultatet som returneras av fakultetfunktionen."}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Ta bort mindre","tmcname":"osa11-05_ta_bort_mindre"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en funktion med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"ta_bort_mindre(tal: list, grans: int)"}]},{"type":"text","value":" som tar en lista med heltal och ett gränsvärde (också i heltalsformat) som sina argument."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen bör använda en list comprehension för att producera en ny lista utan de värden som är mindre än gränsvärdet."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska fungera på följande sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"talen "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"65"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"32"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"6"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"9"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"11"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ta_bort_mindre"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"talen"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ta_bort_mindre"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"8"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"100"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[65, 32, 11]\n[7, 8]"}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Börjar med vokal","tmcname":"osa11-06_borjar_med_vokal"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en funktion med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"borjar_med_vokal(ord: list)"}]},{"type":"text","value":" som tar en lista med strängar som sitt argument."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska använda en list comprehension teknik för att skapa och returnera en ny lista som endast innehåller de ord från den ursprungliga listan som börjar med en vokal (a, e, i, o, u, y, å, ä, ö). Både små och stora bokstäver bör accepteras."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska fungera på följande sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"ord_lista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"automobil\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"moped\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Enhörning\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"katt\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Hund\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"ÄPPEL\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"appelsin\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" vok "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" borjar_med_vokal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ord_lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"vok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"automobil\nEnhörning\nÄPPEL\nappelsin"}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"alternativ-exekvering-med-list-comprehension","style":"position:relative;"},"children":[{"type":"text","value":"Alternativ exekvering med list comprehension"},{"type":"element","tagName":"a","properties":{"href":"#alternativ-exekvering-med-list-comprehension","ariaLabel":"alternativ exekvering med list comprehension permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ofta när vi har en villkorlig sats inkluderar vi också en else-gren. Eftersom vi kan använda villkor i list comprehensions är else-grenen också tillgänglig med list comprehension. Den allmänna syntaxen för villkoret som används med list comprehension ser ut så här:"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":" if else "}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Vi stötte på dessa enradiga villkor, eller ternära operatorer, redan i "},{"type":"element","tagName":"a","properties":{"href":"https://programming-24.mooc.fi/part-7/6-more-features","target":"_blank","rel":["noopener","noreferrer"]},"children":[{"type":"text","value":"modul 7"}]},{"type":"text","value":". Uttrycket ovan utvärderas till antingen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"uttryck 1"}]},{"type":"text","value":" eller "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"uttryck 2"}]},{"type":"text","value":", beroende på om villkoret är sant eller falskt."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Som en uppfräschning av ämnet kan vi säga att om vi behöver skriva ut det större av två tal och vi bara vill använda en enda utskriftssats, kan vi få plats med allt på en enda rad:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"tal1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"input"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Ange tal 1:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\ntal2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"input"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Ange tal 2:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal1 "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" tal1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">"}]},{"type":"text","value":" tal2 "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"text","value":" tal2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Genom att kombinera den ternära operatorssyntaxen med en list comprehension-sats får man följande allmänna struktur:"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"[ if else for in ]"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Det här kan se lite förvirrande ut, eftersom den villkorliga strukturen nu kommer före den faktiska list comprehensionen. Det är bara så här syntaxen har definierats, åtminstone för tillfället. Om det också finns en "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"else"}]},{"type":"text","value":"-gren kommer villkoret först. Om det bara finns ett "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":", kommer det sist. Du kan prova att byta ut dem och se vad som händer."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Att inkludera en else-operator innebär att vi återigen kommer att bearbeta varje objekt från den ursprungliga listan. Beroende på om villkoret är sant eller falskt utförs antingen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"uttryck 1"}]},{"type":"text","value":" eller "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"uttryck 2"}]},{"type":"text","value":" på varje objekt i listan."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I följande exempel kontrolleras om föremåleni en lista är noll eller högre. Alla sådana föremål accepteras som de är, men alla negativa föremål negeras, så att tecknet ändras från negativt till positivt. Resultatet är en lista som innehåller de absoluta värdena för föremålen i den ursprungliga listan."}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"\ntalen "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"45"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"110"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"9"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"11"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\nabsolut_varde "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"text","value":"tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" talen"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"absolut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[1, 3, 45, 110, 2, 9, 11]"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Vi upprepar vad som händer ovan: om villkoret "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"nummer >= 0"}]},{"type":"text","value":" är sant, genomgår föremålet uttrycket "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"nummer"}]},{"type":"text","value":", och resultatet är själva föremålet. Om villkoret är falskt genomgår föremålet uttrycket "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"–nummer"}]},{"type":"text","value":", så att det får ett positivt värde."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I följande exempel har vi funktionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"strang_langder"}]},{"type":"text","value":" som tar en lista som sitt argument och returnerar en annan lista med längderna på alla strängar i den ursprungliga listan. Den här funktionen är dock okej med listföremål av alla typer. Om föremålet är en sträng beräknar den dess längd. Om objektet är något annat infogar den -1 i listan som den returnerar."}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"strang_langder"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"list"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","triple-quoted-string","string"]},"children":[{"type":"text","value":"\"\"\" Funktionen returnerar längden på strängarna i en ny lista \"\"\""}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"foremal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"type"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"foremal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" foremal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n testlista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"hej\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"True"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"hejsan\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"123.344"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"hejsansvejsan\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"False"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n langder "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" strang_langder"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"testlista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"langder"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[3, -1, -1, 6, -1, 13, -1, -1]"}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Lotterinummer","tmcname":"osa11-07_lotterinummer"},"children":[{"type":"element","tagName":"h2","properties":{"id":"lotterinummer-matchade","style":"position:relative;"},"children":[{"type":"text","value":"LotteriNummer matchade"},{"type":"element","tagName":"a","properties":{"href":"#lotterinummer-matchade","ariaLabel":"lotterinummer matchade permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en klass med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"LotteriNummer"}]},{"type":"text","value":" som tar veckonumret (ett heltalsvärde) och en lista med sju heltal som sina konstruktorsargument. Listan ska innehålla de korrekta lotterinumren för den givna veckan."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa också en metod med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"antalet_traffar(nummer: list)"}]},{"type":"text","value":" som tar en lista med heltal som sitt argument. Metoden returnerar antalet korrekta inlägg i parameterlistan."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Metoden bör använda en list comprehension för att uppnå detta. Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska fungera på följande sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"ratta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" LotteriNummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"6"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\negen_rad "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"11"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"13"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"19"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"24"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ratta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"antalet_traffar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"egen_rad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"3"}]}]},{"type":"element","tagName":"h2","properties":{"id":"lotterinummer-matchade-pa-plats","style":"position:relative;"},"children":[{"type":"text","value":"LotteriNummer matchade på plats"},{"type":"element","tagName":"a","properties":{"href":"#lotterinummer-matchade-pa-plats","ariaLabel":"lotterinummer matchade pa plats permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en metod med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"traffar_pa_plats(nummer)"}]},{"type":"text","value":" som tar en lista med sju heltal som sitt argument och returnerar en ny lista med sju heltal. Den nya listan innehåller endast de inlägg från den ursprungliga listan som matchar veckans korrekta nummer. Dessa måste ligga kvar på samma index som de gjorde i den ursprungliga listan. Resten av indexen bör fyllas med värdena "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"-1"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen bör använda en list comprehension för att uppnå detta. Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska fungera på följande sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"ratta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" LotteriNummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"8"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"20"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"30"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"33"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\negen_rad "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"11"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"20"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"30"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ratta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"traffar_pa_plats"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"egen_rad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[1, -1, -1, 10, -1, 20, 30]"}]}]}]}]},"html":"

    Efter den här delen

      \n
    • Vet du vad list comprehension är
    • \n
    • Kommer du att kunna använda list comprehensions för att skapa nya listor
    • \n

    En av de situationer där programmering är som mest kraftfull är vid bearbetning av sekvenser av objekt och händelser. Datorer är bra på att upprepa saker. I de tidigare delarna av det här materialet har vi till exempel itererat strängar, listor och ordlistor på olika sätt.

    Låt oss anta att vi har en lista med heltal och att vi skulle behöva samma lista med objekt i strängformat. Ett traditionellt sätt att utföra uppgiften skulle kunna se ut så här:

    talen = [1, 2, 3, 6, 5, 4, 7]\n\nstrangar = []\nfor tal in talen:\n    strangar.append(str(tal))

    List comprehension

    Det finns också ett mer \"pythoniskt\" sätt att generera listor från befintliga listor. Dessa kallas list comprehensions.

    Tanken är att på en enda rad få plats med både beskrivningen av vad som ska göras med varje objekt i listan och tilldelningen av resultatet till en ny lista.

    I exemplet ovan var operationen som utfördes på varje objekt i listan mycket enkel: varje heltal omvandlades till en sträng. Låt oss se hur detta skulle se ut implementerat med en list comprehension:

    talen = [1, 2, 3, 6, 5, 4, 7]\nstrangar = [str(tal) for tal in talen]

    Den andra raden ovan innehåller många av samma element som den mer traditionella iterativa metoden, men syntaxen är annorlunda. Ett sätt att generalisera en list comprehension skulle kunna vara

    [<uttryck> for <föremål> in <serie>]

    Hakparenteserna runt list comprehensionsatsen signalerar till Python att resultatet ska vara en ny lista. En efter en bearbetas varje objekt i den ursprungliga listan och resultatet lagras i den nya listan, precis som i det iterativa tillvägagångssättet ovan. Som resultat har vi en ny lista med exakt lika många objekt som i originalet, och alla objekt har behandlats på ett identiskt sätt.

    (OBS: originalen till bilderna i denna del saknas tillfälligt, vilket är anledningen till att det finns en del finskt vokabulär i illustrationerna i denna del. Vi arbetar på att åtgärda detta).

    \n \n

    Skriv en funktion med namnet kvadratrot(nummer: list) som tar en lista med heltal som sitt argument. Funktionen ska returnera en ny lista som innehåller kvadratrötterna av de ursprungliga heltalen.

    Modulen math från Pythons standardbibliotek innehåller en lämplig funktion för att räkna ut kvadratrötter.

    Funktionen bör använda en list comprehension. Funktionen får vara högst två rader lång, inklusive rubrikraden som börjar med nyckelordet def.

    Funktionen ska fungera enligt följande:

    rader = kvadratrot([1,2,3,4])\nfor rad in rader:\n    print(rad)

    1.0\n1.4142135623730951\n1.7320508075688772\n2.0

    Skapa funktionen stjarnrader(nummer: list) som tar en lista med heltal som sitt argument. Funktionen ska returnera en ny lista som innehåller rader med stjärnor. Längden på varje rad ska motsvara heltalet på samma index i den ursprungliga listan. Funktionen bör använda en list comprehension för att uppnå detta.

    Funktionen får vara högst två rader lång, inklusive rubrikraden som börjar med nyckelordet def.

    Funktionen ska fungera på följande sätt:

    rader = stjarnrader([1,2,3,4])\nfor rad in rader:\n    print(rad)\n\nprint()\n\nrader = stjarnrader([4, 3, 2, 1, 10])\nfor rad in rader:\n    print(rad)
    \n*\n**\n***\n****\n\n****\n***\n**\n*\n**********\n

    I uppgiftsbotten finns färdigt en klassdefinition för Provresultat, som har följane offentliga attribut:

      \n
    • namn
    • \n
    • vitsord1
    • \n
    • vitsord2
    • \n
    • vitsord3
    • \n

    Skapa en funktion med namnet bast_resultat(resultat: list) som tar en lista med Provresultat-objekt som sitt argument.

    Funktionen ska returnera en ny lista som endast innehåller det bästa resultatet från varje Provresultat-objekt. Funktionen bör använda en list comprehension för att uppnå detta.

    Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet def.

    Funktionen ska fungera på följande sätt:

    resultat1 = Provresultat(\"Peter\",5,3,4)\nresultat2 = Provresultat(\"Pernilla\",3,4,1)\nresultat3 = Provresultat(\"Paulus\",2,1,3)\nprestationer = [resultat1, resultat2, resultat3]\nprint(bast_resultat(prestationer))

    [5, 4, 3]

    Skapa en funktion med namnet langder(listor: list) som tar en lista innehållande listor med heltal som argument. Funktionen ska returnera en ny lista som innehåller längderna på listorna i argumentlistan.

    Funktionen bör använda en list comprehension för att uppnå detta.

    Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet def.

    Funktionen ska fungera på följande sätt:

    listat = [[1,2,3,4,5], [324, -1, 31, 7],[]]\nprint(langder(listat))

    [5, 4, 0]

    Att filtrera föremål

    I exemplen ovan var alla våra listor lika långa före och efter en list comprehension-operation. I varje fall användes alla föremål i den ursprungliga listan som grund för den nya listan. Men ibland behöver vi bara några av de ursprungliga föremålen. Hur kan detta åstadkommas?

    En list comprehension-sats kan också innehålla ett villkor, så att vi kan kontrollera objekten mot villkoret och bara välja ut dem som matchar. Den allmänna syntaxen är enligt följande:

    [<uttryck> for <föremål> in <serie> if <boolskt uttryck>]

    Satsen ovan är i övrigt identisk med den allmänna form som introducerades i början av detta avsnitt, men nu finns det en if-sats i slutet. Endast de objekt från den ursprungliga listan för vilka det booleska uttrycket är sant används som grund för den nya listan.

    I exemplet nedan väljer vi alla jämna objekt från den ursprungliga listan som bas för den nya listan. I själva verket bearbetas inte dessa objekt ytterligare på något sätt, utan de tilldelas den nya listan som de är:

    lista = [1, 1, 2, 3, 4, 6, 4, 5, 7, 10, 12, 3]\n\njamna = [foremal for foremal in lista if foremal % 2 == 0]\nprint(jamna)

    [2, 4, 6, 4, 10, 12]

    Uttrycket i list comprehension-satsen ovan är bara ett enkelt foremal, vilket innebär att inga operationer ska utföras på föremålen i listan. Uttrycket kan vara vilket Python-uttryck som helst, precis som i de tidigare exemplen. Följande list comprehension-sats tar till exempel alla jämna föremål i en lista, multiplicerar varje föremål med tio och lagrar resultatet i en ny lista:

    lista = [1, 1, 2, 3, 4, 6, 4, 5, 7, 10, 12, 3]\n\njamna = [foremal * 10 for foremal in lista if foremal % 2 == 0]\nprint(jamna)

    [20, 40, 60, 40, 100, 120]

    När du stöter på mer och mer komplicerade list comprehensions kan det vara bra att försöka läsa villkoret först. Föremålen bearbetas ändå bara om de klarar testet, så det är ofta vettigt att först ta reda på vilka objekt som klarar filtreringssteget. Ibland skulle uttrycket i en list comprehension-sats inte ens vara möjligt för alla föremål i den ursprungliga listan.

    Till exempel är fakultettal bara definierat för icke-negativa heltal. Om vi inte kan vara säkra på att en lista bara innehåller värden på noll eller högre, måste innehållet filtreras innan det skickas vidare till den fakultetfunktion som vi skapade tidigare:

    def fakultet(n: int):\n    \"\"\" Funktionen räknar fakulteten n! för positiva heltal \"\"\"\n    k = 1\n    while n >= 2:\n        k *= n\n        n -= 1\n    return k\n\nif __name__ == \"__main__\":\n    lista = [-2, 3, -1, 4, -10, 5, 1]\n    fakulteter = [fakultet(tal) for tal in lista if tal > 0]\n    print(fakulteter)

    [6, 24, 120, 1]

    Som vi såg i vårt allra första exempel på list comprehension, där heltal omvandlades till strängar, behöver föremålen i den nya listan inte vara av samma typ som föremålen i den ursprungliga listan. Om vi fortsätter från fakultetexemplet ovan kan vi skapa en tupel från varje originella föremål och dess bearbetade motsvarighet och lagra dessa i en lista, vilket kombinerar allt vi har lärt oss hittills i en enda list comprehension-sats:

    \ndef fakultet(n: int):\n    \"\"\" Funktionen räknar fakulteten n! för positiva heltal \"\"\"\n    k = 1\n    while n >= 2:\n        k *= n\n        n -= 1\n    return k\n\nif __name__ == \"__main__\":\n    lista = [-2, 3, 2, 1, 4, -10, 5, 1, 6]\n    fakulteter = [(tal, fakultet(tal)) for tal in lista if tal > 0 and tal % 2 == 0]\n    print(fakulteter)\n

    [(2, 2), (4, 24), (6, 720)]

    Om vi plockar isär exemplet ovan har vi det booleska uttrycket n > 0 and n % 2 == 0. Detta innebär att endast föremål som är både positiva och delbara med två accepteras för vidare bearbetning från den ursprungliga listan.

    Dessa positiva, jämna tal bearbetas sedan i tur och ordning till formatet (n, fakultet(n)). Detta är en tupel, där det första objektet är själva talet och det andra objektet är resultatet som returneras av fakultetfunktionen.

    Skapa en funktion med namnet ta_bort_mindre(tal: list, grans: int) som tar en lista med heltal och ett gränsvärde (också i heltalsformat) som sina argument.

    Funktionen bör använda en list comprehension för att producera en ny lista utan de värden som är mindre än gränsvärdet.

    Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet def.

    Funktionen ska fungera på följande sätt:

    talen = [1,65, 32, -6, 9, 11]\nprint(ta_bort_mindre(talen, 10))\n\nprint(ta_bort_mindre([-4, 7, 8, -100], 0))

    [65, 32, 11]\n[7, 8]

    Skapa en funktion med namnet borjar_med_vokal(ord: list) som tar en lista med strängar som sitt argument.

    Funktionen ska använda en list comprehension teknik för att skapa och returnera en ny lista som endast innehåller de ord från den ursprungliga listan som börjar med en vokal (a, e, i, o, u, y, å, ä, ö). Både små och stora bokstäver bör accepteras.

    Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet def.

    Funktionen ska fungera på följande sätt:

    ord_lista = [\"automobil\",\"moped\",\"Enhörning\",\"katt\",\"Hund\",\"ÄPPEL\",\"appelsin\"]\nfor vok in borjar_med_vokal(ord_lista):\n    print(vok)

    automobil\nEnhörning\nÄPPEL\nappelsin

    Alternativ exekvering med list comprehension

    Ofta när vi har en villkorlig sats inkluderar vi också en else-gren. Eftersom vi kan använda villkor i list comprehensions är else-grenen också tillgänglig med list comprehension. Den allmänna syntaxen för villkoret som används med list comprehension ser ut så här:

    <uttryck 1> if <villkor> else <uttryck 2>

    Vi stötte på dessa enradiga villkor, eller ternära operatorer, redan i modul 7. Uttrycket ovan utvärderas till antingen uttryck 1 eller uttryck 2, beroende på om villkoret är sant eller falskt.

    Som en uppfräschning av ämnet kan vi säga att om vi behöver skriva ut det större av två tal och vi bara vill använda en enda utskriftssats, kan vi få plats med allt på en enda rad:

    tal1 = int(input(\"Ange tal 1:\"))\ntal2 = int(input(\"Ange tal 2:\"))\nprint (tal1 if tal1 > tal2 else tal2)

    Genom att kombinera den ternära operatorssyntaxen med en list comprehension-sats får man följande allmänna struktur:

    [<uttryck 1> if <villkor> else <uttryck 2> for <föremål> in <serie>]

    Det här kan se lite förvirrande ut, eftersom den villkorliga strukturen nu kommer före den faktiska list comprehensionen. Det är bara så här syntaxen har definierats, åtminstone för tillfället. Om det också finns en else-gren kommer villkoret först. Om det bara finns ett if, kommer det sist. Du kan prova att byta ut dem och se vad som händer.

    Att inkludera en else-operator innebär att vi återigen kommer att bearbeta varje objekt från den ursprungliga listan. Beroende på om villkoret är sant eller falskt utförs antingen uttryck 1 eller uttryck 2 på varje objekt i listan.

    I följande exempel kontrolleras om föremåleni en lista är noll eller högre. Alla sådana föremål accepteras som de är, men alla negativa föremål negeras, så att tecknet ändras från negativt till positivt. Resultatet är en lista som innehåller de absoluta värdena för föremålen i den ursprungliga listan.

    \ntalen = [1, -3, 45, -110, 2, 9, -11]\nabsolut_varde = [tal if tal >= 0 else -tal for tal in talen]\nprint(absolut_varde)\n

    [1, 3, 45, 110, 2, 9, 11]

    Vi upprepar vad som händer ovan: om villkoret nummer >= 0 är sant, genomgår föremålet uttrycket nummer, och resultatet är själva föremålet. Om villkoret är falskt genomgår föremålet uttrycket –nummer, så att det får ett positivt värde.

    I följande exempel har vi funktionen strang_langder som tar en lista som sitt argument och returnerar en annan lista med längderna på alla strängar i den ursprungliga listan. Den här funktionen är dock okej med listföremål av alla typer. Om föremålet är en sträng beräknar den dess längd. Om objektet är något annat infogar den -1 i listan som den returnerar.

    \ndef strang_langder(lista: list):\n    \"\"\" Funktionen returnerar längden på strängarna i en ny lista \"\"\"\n    return [len(foremal) if type(foremal) == str else -1 for foremal in lista]\n\nif __name__ == \"__main__\":\n    testlista = [\"hej\", 3, True, \"hejsan\", -123.344, \"hejsansvejsan\", 2, False]\n    langder = strang_langder(testlista)\n    print(langder)\n

    [3, -1, -1, 6, -1, 13, -1, -1]

    LotteriNummer matchade

    Skapa en klass med namnet LotteriNummer som tar veckonumret (ett heltalsvärde) och en lista med sju heltal som sina konstruktorsargument. Listan ska innehålla de korrekta lotterinumren för den givna veckan.

    Skapa också en metod med namnet antalet_traffar(nummer: list) som tar en lista med heltal som sitt argument. Metoden returnerar antalet korrekta inlägg i parameterlistan.

    Metoden bör använda en list comprehension för att uppnå detta. Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet def.

    Funktionen ska fungera på följande sätt:

    ratta = LotteriNummer(5, [1,2,3,4,5,6,7])\negen_rad = [1,4,7,11,13,19,24]\n\nprint(ratta.antalet_traffar(egen_rad))

    3

    LotteriNummer matchade på plats

    Skapa en metod med namnet traffar_pa_plats(nummer) som tar en lista med sju heltal som sitt argument och returnerar en ny lista med sju heltal. Den nya listan innehåller endast de inlägg från den ursprungliga listan som matchar veckans korrekta nummer. Dessa måste ligga kvar på samma index som de gjorde i den ursprungliga listan. Resten av indexen bör fyllas med värdena -1.

    Funktionen bör använda en list comprehension för att uppnå detta. Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet def.

    Funktionen ska fungera på följande sätt:

    ratta = LotteriNummer(8, [1,2,3,10,20,30,33])\negen_rad = [1,4,7,10,11,20,30]\n\nprint(ratta.traffar_pa_plats(egen_rad))

    [1, -1, -1, 10, -1, 20, 30]

    ","frontmatter":{"path":"/osa-11/1-list-comprehension","title":"List comprehension"},"fileAbsolutePath":"/home/runner/work/ohjelmointi-24-sv/ohjelmointi-24-sv/data/osa-11/1-list-comprehension.md"},"allPages":{"edges":[{"node":{"id":"b5e8ae41-d492-55f7-88a7-1c7292333ab1","frontmatter":{"path":"/arvostelu-ja-kokeet","title":"Arvostelu ja kokeet"}}},{"node":{"id":"af4df6be-211d-5ba1-acea-9edbefa06c49","frontmatter":{"path":"/frontmatter-guide","title":"Frontmatter-guide"}}},{"node":{"id":"56769133-4836-5fbb-a857-8fb0c6803e6d","frontmatter":{"path":"/","title":"Tietoa kurssista"}}},{"node":{"id":"e86762f0-c2a9-5598-aba3-2b8d7db7807c","frontmatter":{"path":"/kaikki-tehtavat","title":"Kaikki tehtävät"}}},{"node":{"id":"5d065309-85e8-5823-9527-ec1c3cf38d4d","frontmatter":{"path":"/tuki","title":"Tukea tehtäviin"}}},{"node":{"id":"ac195ee0-ad04-5cc9-9643-963f93d29ad2","frontmatter":{"path":"/usein-kysytyt-kysymykset","title":"Usein kysytyt kysymykset"}}},{"node":{"id":"51a165d7-8ce5-5d53-9c15-5321b6adef8c","frontmatter":{"path":"/verkkotentti","title":"Verkkotentti 4.6."}}},{"node":{"id":"4d9cf293-01e9-5e6c-a88f-599560e33c9a","frontmatter":{"path":"/verkkotentti-ohja","title":"Ohjelmoinnin jatkokurssin verkkotentti 16.12."}}},{"node":{"id":"279e1cca-fb0b-5d3f-b527-be05243d138d","frontmatter":{"path":"/verkkotentti-ohpe","title":"Ohjelmoinnin perusteiden verkkotentti 09.03."}}},{"node":{"id":"347bdde4-ba21-5f22-8a88-0287dfe29a45","frontmatter":{"path":"/virheilmoitukset","title":"Yleiset virheilmoitukset"}}},{"node":{"id":"3bf12e3a-1542-57f4-812d-dd32cebc99e2","frontmatter":{"path":"/sanasto","title":"Sanasto"}}},{"node":{"id":"9910673b-d62d-5d8d-a756-5267160d891f","frontmatter":{"path":"/osa-1/1-introduktion","title":"Introduktion"}}},{"node":{"id":"0b17a28e-f939-57cc-aa5b-4db407cdf34a","frontmatter":{"path":"/osa-1/2-info-fran-anvandaren","title":"Information från användaren"}}},{"node":{"id":"b95794f2-f3b3-597c-a4ec-6f023b584f81","frontmatter":{"path":"/osa-1/3-mer-om-variabler","title":"Mer om variabler"}}},{"node":{"id":"02cd0849-e7a5-5fd1-bf66-35f0197d3e75","frontmatter":{"path":"/osa-1/4-rakneoperationer","title":"Räkneoperationer"}}},{"node":{"id":"42690a69-3997-5b84-b999-15d9c3212884","frontmatter":{"path":"/osa-1/5-villkorssatser","title":"If-satser"}}},{"node":{"id":"96a0ec65-c0a3-5150-95c5-48c260f88162","frontmatter":{"path":"/osa-1","title":"Modul 1"}}},{"node":{"id":"e7a4d0c8-b8c1-53fa-ab51-9cc06fd417a3","frontmatter":{"path":"/osa-10/1-klasshierarkier","title":"Klasshierarkier"}}},{"node":{"id":"5f6d4b8b-7d05-5c79-9f2f-9e30b397167b","frontmatter":{"path":"/osa-10/2-atkamstmodifierare","title":"Åtkomstmodifierare"}}},{"node":{"id":"bb896c90-aabc-5a9d-8d4b-50839da286db","frontmatter":{"path":"/osa-10/3-objektorienterade-programmeringstekniker","title":"Objektorienterade programmeringstekniker"}}},{"node":{"id":"a2dca4f1-d64d-5e77-a3ca-8b2a208e9afa","frontmatter":{"path":"/osa-10/4-storre-applikation","title":"Att utveckla en större applikation"}}},{"node":{"id":"8c9cf5a7-f02e-5ccf-ab8f-f078c3ccecb6","frontmatter":{"path":"/osa-10","title":"Modul 10"}}},{"node":{"id":"f6688d26-5502-5c17-a8ee-db66f650f1f1","frontmatter":{"path":"/osa-11/1-list-comprehension","title":"List comprehension"}}},{"node":{"id":"1eac8489-72f2-5d53-904b-c960e2622018","frontmatter":{"path":"/osa-11/2-mer-om-comprehensions","title":"Mer om comprehensions"}}},{"node":{"id":"09630fca-7768-53f3-8aca-6e5ac638fc68","frontmatter":{"path":"/osa-11/3-rekursion","title":"Rekursion"}}},{"node":{"id":"70f6008e-a762-574c-a92a-c5c585d9677e","frontmatter":{"path":"/osa-11/4-lisaa-esimerkkeja","title":"Fler exempel på rekursion"}}},{"node":{"id":"eb8ed7d7-c39d-52db-949d-f75649498c67","frontmatter":{"path":"/osa-11","title":"Modul 11"}}},{"node":{"id":"9bba31dc-e14c-5400-a25b-7339107e9ba7","frontmatter":{"path":"/osa-12/1-funktioner-som-argument","title":"Funktioner som argument"}}},{"node":{"id":"5b9e4584-7234-5216-a118-d2a1bc617e13","frontmatter":{"path":"/osa-12/2-generatorer","title":"Generatorer"}}},{"node":{"id":"1d27636e-74f4-5c30-a1d8-08a303684945","frontmatter":{"path":"/osa-12/3-funktionell-programmering","title":"Funktionell programmering"}}},{"node":{"id":"6785750f-f145-5b88-81e9-b52e36ba53c6","frontmatter":{"path":"/osa-12/4-reguljara-uttryck","title":"Reguljära uttryck"}}},{"node":{"id":"d21df33a-4bf4-5ee3-9e2a-431d57561f09","frontmatter":{"path":"/osa-12","title":"Modul 12"}}},{"node":{"id":"14e3c129-50ec-581f-8679-8132248d41c1","frontmatter":{"path":"/osa-13/1-pygame","title":"Pygame"}}},{"node":{"id":"01bc3b9b-4f80-5561-8b56-3a7f09082263","frontmatter":{"path":"/osa-13/2-animation","title":"Animation"}}},{"node":{"id":"dd68786f-e2fc-5957-b47a-52b74c5199ef","frontmatter":{"path":"/osa-13/3-handelser","title":"Händelser"}}},{"node":{"id":"4a1aaa41-d6f7-51cd-8b89-95842cb9e02d","frontmatter":{"path":"/osa-13/4-fler-pygame-tekniker","title":"Fler pygame-tekniker"}}},{"node":{"id":"cdcf0ce1-e881-5ca6-8fa9-d0d343ec4e15","frontmatter":{"path":"/osa-13","title":"Modul 13"}}},{"node":{"id":"0ab28435-7654-5a8e-88d6-daa17d78103b","frontmatter":{"path":"/osa-14/1-spelprojekt","title":"Spelprojekt"}}},{"node":{"id":"b7a0628c-e4ba-583e-a52a-dd0ad78028d8","frontmatter":{"path":"/osa-14/2-robot-och-ladar","title":"Robot och lådor"}}},{"node":{"id":"6ccdbdff-7539-5a23-b23c-2ad48a99386f","frontmatter":{"path":"/osa-14/3-fardigstallande-av-spelet","title":"Färdigställande av spelet"}}},{"node":{"id":"1b505c9f-9b1b-58bd-8df7-553fef49cc8d","frontmatter":{"path":"/osa-14/4-ditt-eget-sepl","title":"Ditt eget spel"}}},{"node":{"id":"55c54859-8c7f-5fd9-8a8d-2c54ee677577","frontmatter":{"path":"/osa-14","title":"Modul 14"}}},{"node":{"id":"b5c346d1-d175-5824-98bb-4a4c3b45204d","frontmatter":{"path":"/osa-2/1-terminologi","title":"Programmeringsterminologi"}}},{"node":{"id":"db7188b0-0253-5c30-b8d2-0e115e235fb3","frontmatter":{"path":"/osa-2/2-else-elif","title":"Mera om if-satser"}}},{"node":{"id":"49d15928-f8b9-5883-9f29-86c307f6929e","frontmatter":{"path":"/osa-2/3-kombinera-villkor","title":"Kombinera villkor"}}},{"node":{"id":"93f1f9c8-6b27-5892-8bd4-7d1d008bf07a","frontmatter":{"path":"/osa-2/4-loopar","title":"Enkla loopar"}}},{"node":{"id":"5523b5b8-61f8-506d-bfe0-c6cc774390ce","frontmatter":{"path":"/osa-2","title":"Modul 2"}}},{"node":{"id":"02012307-c2a6-5cf2-9105-c10933c14b37","frontmatter":{"path":"/osa-3/1-loopar-med-villkor","title":"Loopar med villkor"}}},{"node":{"id":"efb889f4-4a19-515e-a0f6-4297d76a2757","frontmatter":{"path":"/osa-3/2-behandla-strangar","title":"Behandla strängar"}}},{"node":{"id":"a602077d-bbae-5eb7-a354-cc44b29ae96a","frontmatter":{"path":"/osa-3/3-mer-om-loopar","title":"Mera om loopar"}}},{"node":{"id":"6d878692-b9c7-57e6-ae58-044e5a6bef6f","frontmatter":{"path":"/osa-3/4-definiera-funktioner","title":"Definiera funktioner"}}},{"node":{"id":"682b5a18-73c5-56e2-8374-237baccbab40","frontmatter":{"path":"/osa-3","title":"Modul 3"}}},{"node":{"id":"3de95518-6b44-54db-9bcd-0c90a41d2fd5","frontmatter":{"path":"/osa-4/1-vscode","title":"Editorn Visual Studio Code, Pythontolken och det inbyggda debuggningsverktyget"}}},{"node":{"id":"7de9921c-7f94-58fe-84b9-7676dddb3b94","frontmatter":{"path":"/osa-4/2-mer-om-funktioner","title":"Mer om funktioner"}}},{"node":{"id":"29e29c69-360c-5f5c-8f34-5aef22eb327f","frontmatter":{"path":"/osa-4/3-listor","title":"Listor"}}},{"node":{"id":"bfe57880-0cbb-54e4-be9c-8fa180eafe6b","frontmatter":{"path":"/osa-4/4-iteration","title":"Iteration"}}},{"node":{"id":"2eab46f0-5373-5cbe-b2a0-1d071854a053","frontmatter":{"path":"/osa-4/5-utskrift","title":"Formatera utskrift"}}},{"node":{"id":"a5974fee-f2eb-5b89-88a5-6dd3754baaad","frontmatter":{"path":"/osa-4/6-strangar-listor","title":"Mera strängar och listor"}}},{"node":{"id":"e125c469-ee19-505e-9a41-83da6143ecd8","frontmatter":{"path":"/osa-4","title":"Modul 4"}}},{"node":{"id":"2558444a-be1d-5bc6-95ab-e091da2443fc","frontmatter":{"path":"/osa-5/1-mer-om-listor","title":"Mer om listor"}}},{"node":{"id":"b452d9be-0569-56c2-ba89-a040d4cb40dc","frontmatter":{"path":"/osa-5/2-referenser","title":"Referenser"}}},{"node":{"id":"ebe4ca3f-e657-5907-bfcc-ae84d9947aff","frontmatter":{"path":"/osa-5/3-lexikon","title":"Lexikon"}}},{"node":{"id":"f1dd5d66-ac87-5e53-92a0-0b7e3ece6ed8","frontmatter":{"path":"/osa-5/4-tuple","title":"Tuple"}}},{"node":{"id":"161c0109-5c00-5bed-b7af-90dc7ddf5713","frontmatter":{"path":"/osa-5","title":"Modul 5"}}},{"node":{"id":"e6cfa6e1-e99b-50e0-bc6a-3c0f153420e8","frontmatter":{"path":"/osa-6/1-lasa-filer","title":"Läsa filer"}}},{"node":{"id":"ce8d90a4-ca7c-5797-abc1-3fe0094bfa4b","frontmatter":{"path":"/osa-6/2-skriva-filer","title":"Skriva filer"}}},{"node":{"id":"519d5330-277a-59ba-be50-c2f63080df94","frontmatter":{"path":"/osa-6/3-fel","title":"Förbered dig på fel"}}},{"node":{"id":"82393756-3ef8-5d07-a8da-fed818ca43f0","frontmatter":{"path":"/osa-6/4-lokala-globala-variabler","title":"Lokala och globala variabler"}}},{"node":{"id":"007d85ae-a118-5b10-8a7e-18302b15eba8","frontmatter":{"path":"/osa-6","title":"Modul 6"}}},{"node":{"id":"bbb2346d-b1ee-551d-89c1-516f119b0eed","frontmatter":{"path":"/osa-7/1-moduler","title":"Moduler"}}},{"node":{"id":"ecb9af64-49f9-5e28-a544-3934e95233cf","frontmatter":{"path":"/osa-7/2-slumpmassighet","title":"Slumpmässighet"}}},{"node":{"id":"ebe469ef-c486-523a-9621-5dc4040c5cd8","frontmatter":{"path":"/osa-7/3-tid-datum","title":"Tid och datum"}}},{"node":{"id":"b9cf2d99-08f6-5de5-8425-c9b483241567","frontmatter":{"path":"/osa-7/4-behandla-data","title":"Behandla data"}}},{"node":{"id":"27075b37-8a6a-5554-9079-465a36d2da2d","frontmatter":{"path":"/osa-7/5-egna-moduler","title":"Skapa dina egna moduler"}}},{"node":{"id":"69492225-4d69-59ea-b33d-5301d35cf4ed","frontmatter":{"path":"/osa-7/6-funktionaliteter-python","title":"Flera funktionaliteter i Python"}}},{"node":{"id":"70ae841a-e6e9-5252-afae-6329fb67bcad","frontmatter":{"path":"/osa-7","title":"Modul 7"}}},{"node":{"id":"4afc4486-3cfe-53d1-b4c0-6db26484acfa","frontmatter":{"path":"/osa-8/1-objekt-och-metoder","title":"Objekt och metoder"}}},{"node":{"id":"6be37772-e94b-5b36-8a02-fffa7eef9feb","frontmatter":{"path":"/osa-8/2-klasser-och-objekt","title":"Klasser och objekt"}}},{"node":{"id":"8b6aec39-f8b9-525c-9f25-d8e73389fa42","frontmatter":{"path":"/osa-8/3-egna-klasser","title":"Egna klasser"}}},{"node":{"id":"85db460a-77c6-5087-8e97-a3c772186fd9","frontmatter":{"path":"/osa-8/4-metoder-i-egna-klasser","title":"Metoder i egna klasser"}}},{"node":{"id":"0e59dee0-5dd9-5827-83b9-a55e7d585c31","frontmatter":{"path":"/osa-8/5-fler-exempel","title":"Fler exempel"}}},{"node":{"id":"64715d0c-54f1-5aa7-a566-d2c5be6523ea","frontmatter":{"path":"/osa-8","title":"Modul 8"}}},{"node":{"id":"f7457509-a9a6-5420-8d03-ff1c61df8dc4","frontmatter":{"path":"/osa-9/1-objekt-och-referenser","title":"Objekt och referenser"}}},{"node":{"id":"16689ce4-b6aa-5bc4-9a30-44820994d6ea","frontmatter":{"path":"/osa-9/2-objekt-som-attribut","title":"Objekt som attribut "}}},{"node":{"id":"07985959-e85a-5f45-8923-babacb943c04","frontmatter":{"path":"/osa-9/3-inkapsling","title":"Inkapsling"}}},{"node":{"id":"83108600-9a37-5fd1-9a2b-13492879a9d6","frontmatter":{"path":"/osa-9/4-metodernas-rackvidd","title":"Metodernas räckvidd"}}},{"node":{"id":"a553cdc9-d6ac-5a14-ab43-d44811b407a2","frontmatter":{"path":"/osa-9/5-klassattribut","title":"Klassattribut"}}},{"node":{"id":"f7d7c9f1-6b54-5268-a308-995d49dd913d","frontmatter":{"path":"/osa-9/6-fler-exempel-med-klasser","title":"Fler exempel med klasser"}}},{"node":{"id":"c1fef3f7-8ca3-5780-9dec-19bd672b4627","frontmatter":{"path":"/osa-9","title":"Modul 9"}}}]}},"pageContext":{}}, + "result": {"data":{"page":{"htmlAst":{"type":"element","tagName":"div","properties":{},"children":[{"type":"element","tagName":"text-box","properties":{"variant":"learningObjectives","name":"Inlärningsmål"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Efter den här delen"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Vet du vad list comprehension är"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Kommer du att kunna använda list comprehensions för att skapa nya listor"}]},{"type":"text","value":"\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"En av de situationer där programmering är som mest kraftfull är vid bearbetning av sekvenser av objekt och händelser. Datorer är bra på att upprepa saker. I de tidigare delarna av det här materialet har vi till exempel itererat strängar, listor och ordlistor på olika sätt."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss anta att vi har en lista med heltal och att vi skulle behöva samma lista med objekt i strängformat. Ett traditionellt sätt att utföra uppgiften skulle kunna se ut så här:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"talen "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"6"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\nstrangar "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" talen"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n strangar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"list-comprehension","style":"position:relative;"},"children":[{"type":"text","value":"List comprehension"},{"type":"element","tagName":"a","properties":{"href":"#list-comprehension","ariaLabel":"list comprehension permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Det finns också ett mer \"pythoniskt\" sätt att generera listor från befintliga listor. Dessa kallas list comprehensions."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Tanken är att på en enda rad få plats med både beskrivningen av vad som ska göras med varje objekt i listan och tilldelningen av resultatet till en ny lista."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I exemplet ovan var operationen som utfördes på varje objekt i listan mycket enkel: varje heltal omvandlades till en sträng. Låt oss se hur detta skulle se ut implementerat med en list comprehension:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"talen "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"6"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\nstrangar "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" talen"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Den andra raden ovan innehåller många av samma element som den mer traditionella iterativa metoden, men syntaxen är annorlunda. Ett sätt att generalisera en list comprehension skulle kunna vara"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"[ for in ]"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Hakparenteserna runt list comprehensionsatsen signalerar till Python att resultatet ska vara en ny lista. En efter en bearbetas varje objekt i den ursprungliga listan och resultatet lagras i den nya listan, precis som i det iterativa tillvägagångssättet ovan. Som resultat har vi en ny lista med exakt lika många objekt som i originalet, och alla objekt har behandlats på ett identiskt sätt."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"(OBS: originalen till bilderna i denna del saknas tillfälligt, vilket är anledningen till att det finns en del finskt vokabulär i illustrationerna i denna del. Vi arbetar på att åtgärda detta)."}]},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-wrapper"],"style":"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 301px; margin-bottom: 1rem;"},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"a","properties":{"className":["gatsby-resp-image-link"],"href":"/ohjelmointi-24-sv/static/bb2be65b36f7fdf4ea48dfde815e9fbf/fb933/11_1_2.png","style":"display: block","target":"_blank","rel":["noopener"]},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-background-image"],"style":"padding-bottom: 131.7391304347826%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAaCAYAAAC3g3x9AAAACXBIWXMAAA7EAAAOxAGVKw4bAAACVUlEQVRIx42V247aQAyG5/0fibtWlZYLDqLAcgOoBDblHMIpgQRcfVYdDasku5as+ceneOwZx0kNPfJcRsOh9PsDSZJUvkPucDhIFcdxLNfrVRlcZ2vsVquVZFkmaZoKmJX9ZrOR8/mseL/fSxRFkue5ytCV+YAdhkY+JiOMoMvlogwhQ1fmA3a73a4QbLdbeT6fisnqdrspJisYQoYOwhYfI2K59Xqtqc7ncz0KvFgsdMUYjA0MRmbY7PElBnJnXyKD4/GoX2KlERAO6KmfnQadb4uvncwZgJIk0U5BrASxWuJEIJOZDT5GxHL+Brrf72pIrU6nkzrABERHRuhoAHvfVzP0BbY+Hg8NBlMrmBoRhIDIsSnzLQJ+Zo7V6XSk3W5Lo9GQVqslg8FAut2u6sp8ioB+UCu03bsy8pvi+70E9NPmaBzpbxjK21tTms2m/Pr5Q1rtrqS3u2TZvWieH6wyIMYU/Jameu9oir7n/1nRlC8D+qnb+6WzBBuPx8pJctWGoPM7XNtlv9MUfzabSa/XUwYj8ztc22Uju28clwA2HMDI0FmGn/1fXgpftnuGM2MJtoC2R4cNtpbty0vhOWFAoW2Y2lvm4aOHwXZtzAYffNFrhkyI6XSqNWIQLJdLvdBgXsdwONTVx+iwMYwvMXTa+POsah7aM/xqHoJrJ7Ydw/4rVp7aiR0EgRrwVTBC9jZwwWEYSvjxoU2wgYocW3zwZQ92tL+K/Q5adnX2sKv7xx6iSEfX6H0k/f7vb/2bXdkYKqZOHMufINAjTiaTImCVD/fwH00l3UL1OMHGAAAAAElFTkSuQmCC'); background-size: cover; display: block;"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"picture","properties":{},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/bb2be65b36f7fdf4ea48dfde815e9fbf/a0b58/11_1_2.webp 230w","/ohjelmointi-24-sv/static/bb2be65b36f7fdf4ea48dfde815e9fbf/c4c4c/11_1_2.webp 301w"],"sizes":"(max-width: 301px) 100vw, 301px","type":"image/webp"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/bb2be65b36f7fdf4ea48dfde815e9fbf/81c8e/11_1_2.png 230w","/ohjelmointi-24-sv/static/bb2be65b36f7fdf4ea48dfde815e9fbf/fb933/11_1_2.png 301w"],"sizes":"(max-width: 301px) 100vw, 301px","type":"image/png"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"img","properties":{"className":["gatsby-resp-image-image"],"src":"/ohjelmointi-24-sv/static/bb2be65b36f7fdf4ea48dfde815e9fbf/fb933/11_1_2.png","alt":"11 1 2","title":"11 1 2","loading":"lazy","decoding":"async","style":"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"},"children":[]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"List comprehensions kan också hantera mycket mer komplicerade operationer. Vi kan utföra beräkningar, till exempel multiplicera de ursprungliga objekten med tio:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"talen "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"list"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"range"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"talen"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\ntalen_multiplicerade "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"tal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" talen"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"talen_multiplicerade"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[1, 2, 3, 4, 5, 6, 7, 8, 9]\n[10, 20, 30, 40, 50, 60, 70, 80, 90]"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Faktum är att uttrycket i list comprehension-satsen kan vara vilket Python-uttryck som helst. Du kan till och med anropa funktioner som du själv har definierat:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"fakultet"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","triple-quoted-string","string"]},"children":[{"type":"text","value":"\"\"\" Funktionen räknar fakulteten n! för positiva heltal \"\"\""}]},{"type":"text","value":"\n k "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"while"}]},{"type":"text","value":" n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n k "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*="}]},{"type":"text","value":" n\n n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" k\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n lista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n fakulteter "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"fakultet"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"fakulteter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[120, 2, 24, 6, 1]"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Med den mer välbekanta "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":"-loopen skulle samma process kunna uttryckas så här:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"fakultet"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","triple-quoted-string","string"]},"children":[{"type":"text","value":"\"\"\" Funktionen räknar fakulteten n! för positiva heltal \"\"\""}]},{"type":"text","value":"\n k "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"while"}]},{"type":"text","value":" n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n k "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*="}]},{"type":"text","value":" n\n n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" k\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n lista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n fakulteter "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n fakulteter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"fakultet"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"fakulteter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"List Comprehensions gör att vi kan uttrycka samma funktionalitet på ett mer konsekvent sätt, vanligtvis utan att förlora något av läsbarheten."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Vi kan också returnera en list comprehension-sats direkt från en funktion. Om vi behövde en funktion för att producera fakultettal för listor med tal, skulle vi kunna göra det på ett mycket kortfattat sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"fakulteter"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"talen"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"list"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"fakultet"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" talen"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Kvadratrötter","tmcname":"osa11-01_kvadratrotter"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skriv en funktion med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"kvadratrot(nummer: list)"}]},{"type":"text","value":" som tar en lista med heltal som sitt argument. Funktionen ska returnera en ny lista som innehåller kvadratrötterna av de ursprungliga heltalen."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Modulen "},{"type":"element","tagName":"a","properties":{"href":"https://docs.python.org/3/library/math.html","target":"_blank","rel":["noopener","noreferrer"]},"children":[{"type":"text","value":"math"}]},{"type":"text","value":" från Pythons standardbibliotek innehåller en lämplig funktion för att räkna ut kvadratrötter."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen bör använda en list comprehension. Funktionen får vara högst två rader lång, inklusive rubrikraden som börjar med nyckelordet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska fungera enligt följande:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"rader "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" kvadratrot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" rad "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" rader"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"1.0\n1.4142135623730951\n1.7320508075688772\n2.0"}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Stjärnrader","tmcname":"osa11-02_stjarnrader"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa funktionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"stjarnrader(nummer: list)"}]},{"type":"text","value":" som tar en lista med heltal som sitt argument. Funktionen ska returnera en ny lista som innehåller rader med stjärnor. Längden på varje rad ska motsvara heltalet på samma index i den ursprungliga listan. Funktionen bör använda en list comprehension för att uppnå detta."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen får vara högst två rader lång, inklusive rubrikraden som börjar med nyckelordet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska fungera på följande sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"rader "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" stjarnrader"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" rad "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" rader"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nrader "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" stjarnrader"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" rad "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" rader"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"pre","properties":{},"children":[{"type":"text","value":"*\n**\n***\n****\n\n****\n***\n**\n*\n**********\n"}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Bäst provresultat","tmcname":"osa11-03_bast_provresultat"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I uppgiftsbotten finns färdigt en klassdefinition för "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Provresultat"}]},{"type":"text","value":", som har följane offentliga attribut:"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"namn"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"vitsord1"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"vitsord2"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"vitsord3"}]},{"type":"text","value":"\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en funktion med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"bast_resultat(resultat: list)"}]},{"type":"text","value":" som tar en lista med Provresultat-objekt som sitt argument."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska returnera en ny lista som endast innehåller det bästa resultatet från varje Provresultat-objekt. Funktionen bör använda en list comprehension för att uppnå detta."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska fungera på följande sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"resultat1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Provresultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nresultat2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Provresultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Pernilla\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nresultat3 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Provresultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Paulus\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nprestationer "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"resultat1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" resultat2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" resultat3"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"bast_resultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"prestationer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[5, 4, 3]"}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Längder","tmcname":"osa11-04_langder"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en funktion med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"langder(listor: list)"}]},{"type":"text","value":" som tar en lista innehållande listor med heltal som argument. Funktionen ska returnera en ny lista som innehåller längderna på listorna i argumentlistan."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen bör använda en list comprehension för att uppnå detta."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska fungera på följande sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"listat "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"324"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"31"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"langder"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"listat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[5, 4, 0]"}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"att-filtrera-foremal","style":"position:relative;"},"children":[{"type":"text","value":"Att filtrera föremål"},{"type":"element","tagName":"a","properties":{"href":"#att-filtrera-foremal","ariaLabel":"att filtrera foremal permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I exemplen ovan var alla våra listor lika långa före och efter en list comprehension-operation. I varje fall användes alla föremål i den ursprungliga listan som grund för den nya listan. Men ibland behöver vi bara några av de ursprungliga föremålen. Hur kan detta åstadkommas?"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"En list comprehension-sats kan också innehålla ett villkor, så att vi kan kontrollera objekten mot villkoret och bara välja ut dem som matchar. Den allmänna syntaxen är enligt följande:"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"[ for in if ]"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Satsen ovan är i övrigt identisk med den allmänna form som introducerades i början av detta avsnitt, men nu finns det en if-sats i slutet. Endast de objekt från den ursprungliga listan för vilka det booleska uttrycket är sant används som grund för den nya listan."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I exemplet nedan väljer vi alla jämna objekt från den ursprungliga listan som bas för den nya listan. I själva verket bearbetas inte dessa objekt ytterligare på något sätt, utan de tilldelas den nya listan som de är:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"lista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"6"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"12"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\njamna "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"foremal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" foremal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" lista "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" foremal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"%"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"jamna"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[2, 4, 6, 4, 10, 12]"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Uttrycket i list comprehension-satsen ovan är bara ett enkelt "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"foremal"}]},{"type":"text","value":", vilket innebär att inga operationer ska utföras på föremålen i listan. Uttrycket kan vara vilket Python-uttryck som helst, precis som i de tidigare exemplen. Följande list comprehension-sats tar till exempel alla jämna föremål i en lista, multiplicerar varje föremål med tio och lagrar resultatet i en ny lista:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"lista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"6"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"12"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\njamna "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"foremal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" foremal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" lista "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" foremal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"%"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"jamna"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[20, 40, 60, 40, 100, 120]"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"När du stöter på mer och mer komplicerade list comprehensions kan det vara bra att försöka läsa villkoret först. Föremålen bearbetas ändå bara om de klarar testet, så det är ofta vettigt att först ta reda på vilka objekt som klarar filtreringssteget. Ibland skulle uttrycket i en list comprehension-sats inte ens vara möjligt för alla föremål i den ursprungliga listan."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Till exempel är fakultettal bara definierat för icke-negativa heltal. Om vi inte kan vara säkra på att en lista bara innehåller värden på noll eller högre, måste innehållet filtreras innan det skickas vidare till den fakultetfunktion som vi skapade tidigare:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"fakultet"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","triple-quoted-string","string"]},"children":[{"type":"text","value":"\"\"\" Funktionen räknar fakulteten n! för positiva heltal \"\"\""}]},{"type":"text","value":"\n k "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"while"}]},{"type":"text","value":" n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n k "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*="}]},{"type":"text","value":" n\n n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" k\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n lista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n fakulteter "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"fakultet"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" lista "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"fakulteter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[6, 24, 120, 1]"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Som vi såg i vårt allra första exempel på list comprehension, där heltal omvandlades till strängar, behöver föremålen i den nya listan inte vara av samma typ som föremålen i den ursprungliga listan. Om vi fortsätter från fakultetexemplet ovan kan vi skapa en tupel från varje originella föremål och dess bearbetade motsvarighet och lagra dessa i en lista, vilket kombinerar allt vi har lärt oss hittills i en enda list comprehension-sats:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"fakultet"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","triple-quoted-string","string"]},"children":[{"type":"text","value":"\"\"\" Funktionen räknar fakulteten n! för positiva heltal \"\"\""}]},{"type":"text","value":"\n k "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"while"}]},{"type":"text","value":" n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n k "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*="}]},{"type":"text","value":" n\n n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" k\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n lista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"6"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n fakulteter "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" fakultet"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" lista "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"and"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"%"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"fakulteter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[(2, 2), (4, 24), (6, 720)]"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Om vi plockar isär exemplet ovan har vi det booleska uttrycket "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"n > 0 and n % 2 == 0"}]},{"type":"text","value":". Detta innebär att endast föremål som är både positiva och delbara med två accepteras för vidare bearbetning från den ursprungliga listan."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Dessa positiva, jämna tal bearbetas sedan i tur och ordning till formatet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"(n, fakultet(n))"}]},{"type":"text","value":". Detta är en tupel, där det första objektet är själva talet och det andra objektet är resultatet som returneras av fakultetfunktionen."}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Ta bort mindre","tmcname":"osa11-05_ta_bort_mindre"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en funktion med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"ta_bort_mindre(tal: list, grans: int)"}]},{"type":"text","value":" som tar en lista med heltal och ett gränsvärde (också i heltalsformat) som sina argument."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen bör använda en list comprehension för att producera en ny lista utan de värden som är mindre än gränsvärdet."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska fungera på följande sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"talen "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"65"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"32"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"6"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"9"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"11"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ta_bort_mindre"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"talen"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ta_bort_mindre"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"8"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"100"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[65, 32, 11]\n[7, 8]"}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Börjar med vokal","tmcname":"osa11-06_borjar_med_vokal"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en funktion med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"borjar_med_vokal(ord: list)"}]},{"type":"text","value":" som tar en lista med strängar som sitt argument."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska använda en list comprehension teknik för att skapa och returnera en ny lista som endast innehåller de ord från den ursprungliga listan som börjar med en vokal (a, e, i, o, u, y, å, ä, ö). Både små och stora bokstäver bör accepteras."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska fungera på följande sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"ord_lista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"automobil\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"moped\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Enhörning\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"katt\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Hund\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"ÄPPEL\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"appelsin\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" vok "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" borjar_med_vokal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ord_lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"vok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"automobil\nEnhörning\nÄPPEL\nappelsin"}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"alternativ-exekvering-med-list-comprehension","style":"position:relative;"},"children":[{"type":"text","value":"Alternativ exekvering med list comprehension"},{"type":"element","tagName":"a","properties":{"href":"#alternativ-exekvering-med-list-comprehension","ariaLabel":"alternativ exekvering med list comprehension permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ofta när vi har en villkorlig sats inkluderar vi också en else-gren. Eftersom vi kan använda villkor i list comprehensions är else-grenen också tillgänglig med list comprehension. Den allmänna syntaxen för villkoret som används med list comprehension ser ut så här:"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":" if else "}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Vi stötte på dessa enradiga villkor, eller ternära operatorer, redan i "},{"type":"element","tagName":"a","properties":{"href":"https://programming-24.mooc.fi/part-7/6-more-features","target":"_blank","rel":["noopener","noreferrer"]},"children":[{"type":"text","value":"modul 7"}]},{"type":"text","value":". Uttrycket ovan utvärderas till antingen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"uttryck 1"}]},{"type":"text","value":" eller "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"uttryck 2"}]},{"type":"text","value":", beroende på om villkoret är sant eller falskt."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Som en uppfräschning av ämnet kan vi säga att om vi behöver skriva ut det större av två tal och vi bara vill använda en enda utskriftssats, kan vi få plats med allt på en enda rad:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"tal1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"input"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Ange tal 1:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\ntal2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"input"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Ange tal 2:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal1 "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" tal1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">"}]},{"type":"text","value":" tal2 "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"text","value":" tal2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Genom att kombinera den ternära operatorssyntaxen med en list comprehension-sats får man följande allmänna struktur:"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"[ if else for in ]"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Det här kan se lite förvirrande ut, eftersom den villkorliga strukturen nu kommer före den faktiska list comprehensionen. Det är bara så här syntaxen har definierats, åtminstone för tillfället. Om det också finns en "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"else"}]},{"type":"text","value":"-gren kommer villkoret först. Om det bara finns ett "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":", kommer det sist. Du kan prova att byta ut dem och se vad som händer."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Att inkludera en else-operator innebär att vi återigen kommer att bearbeta varje objekt från den ursprungliga listan. Beroende på om villkoret är sant eller falskt utförs antingen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"uttryck 1"}]},{"type":"text","value":" eller "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"uttryck 2"}]},{"type":"text","value":" på varje objekt i listan."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I följande exempel kontrolleras om föremåleni en lista är noll eller högre. Alla sådana föremål accepteras som de är, men alla negativa föremål negeras, så att tecknet ändras från negativt till positivt. Resultatet är en lista som innehåller de absoluta värdena för föremålen i den ursprungliga listan."}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"\ntalen "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"45"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"110"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"9"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"11"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\nabsolut_varde "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"text","value":"tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" talen"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"absolut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[1, 3, 45, 110, 2, 9, 11]"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Vi upprepar vad som händer ovan: om villkoret "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"nummer >= 0"}]},{"type":"text","value":" är sant, genomgår föremålet uttrycket "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"nummer"}]},{"type":"text","value":", och resultatet är själva föremålet. Om villkoret är falskt genomgår föremålet uttrycket "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"–nummer"}]},{"type":"text","value":", så att det får ett positivt värde."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I följande exempel har vi funktionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"strang_langder"}]},{"type":"text","value":" som tar en lista som sitt argument och returnerar en annan lista med längderna på alla strängar i den ursprungliga listan. Den här funktionen är dock okej med listföremål av alla typer. Om föremålet är en sträng beräknar den dess längd. Om objektet är något annat infogar den -1 i listan som den returnerar."}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"strang_langder"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"list"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","triple-quoted-string","string"]},"children":[{"type":"text","value":"\"\"\" Funktionen returnerar längden på strängarna i en ny lista \"\"\""}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"foremal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"type"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"foremal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" foremal "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n testlista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"hej\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"True"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"hejsan\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"123.344"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"hejsansvejsan\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"False"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n langder "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" strang_langder"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"testlista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"langder"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[3, -1, -1, 6, -1, 13, -1, -1]"}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Lotterinummer","tmcname":"osa11-07_lotterinummer"},"children":[{"type":"element","tagName":"h2","properties":{"id":"lotterinummer-matchade","style":"position:relative;"},"children":[{"type":"text","value":"LotteriNummer matchade"},{"type":"element","tagName":"a","properties":{"href":"#lotterinummer-matchade","ariaLabel":"lotterinummer matchade permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en klass med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"LotteriNummer"}]},{"type":"text","value":" som tar veckonumret (ett heltalsvärde) och en lista med sju heltal som sina konstruktorsargument. Listan ska innehålla de korrekta lotterinumren för den givna veckan."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa också en metod med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"antalet_traffar(nummer: list)"}]},{"type":"text","value":" som tar en lista med heltal som sitt argument. Metoden returnerar antalet korrekta inlägg i parameterlistan."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Metoden bör använda en list comprehension för att uppnå detta. Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska fungera på följande sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"ratta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" LotteriNummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"6"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\negen_rad "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"11"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"13"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"19"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"24"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ratta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"antalet_traffar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"egen_rad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"3"}]}]},{"type":"element","tagName":"h2","properties":{"id":"lotterinummer-matchade-pa-plats","style":"position:relative;"},"children":[{"type":"text","value":"LotteriNummer matchade på plats"},{"type":"element","tagName":"a","properties":{"href":"#lotterinummer-matchade-pa-plats","ariaLabel":"lotterinummer matchade pa plats permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en metod med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"traffar_pa_plats(nummer)"}]},{"type":"text","value":" som tar en lista med sju heltal som sitt argument och returnerar en ny lista med sju heltal. Den nya listan innehåller endast de inlägg från den ursprungliga listan som matchar veckans korrekta nummer. Dessa måste ligga kvar på samma index som de gjorde i den ursprungliga listan. Resten av indexen bör fyllas med värdena "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"-1"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen bör använda en list comprehension för att uppnå detta. Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska fungera på följande sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"ratta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" LotteriNummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"8"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"20"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"30"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"33"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\negen_rad "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"11"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"20"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"30"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ratta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"traffar_pa_plats"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"egen_rad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[1, -1, -1, 10, -1, 20, 30]"}]}]}]}]},"html":"

    Efter den här delen

      \n
    • Vet du vad list comprehension är
    • \n
    • Kommer du att kunna använda list comprehensions för att skapa nya listor
    • \n

    En av de situationer där programmering är som mest kraftfull är vid bearbetning av sekvenser av objekt och händelser. Datorer är bra på att upprepa saker. I de tidigare delarna av det här materialet har vi till exempel itererat strängar, listor och ordlistor på olika sätt.

    Låt oss anta att vi har en lista med heltal och att vi skulle behöva samma lista med objekt i strängformat. Ett traditionellt sätt att utföra uppgiften skulle kunna se ut så här:

    talen = [1, 2, 3, 6, 5, 4, 7]\n\nstrangar = []\nfor tal in talen:\n    strangar.append(str(tal))

    List comprehension

    Det finns också ett mer \"pythoniskt\" sätt att generera listor från befintliga listor. Dessa kallas list comprehensions.

    Tanken är att på en enda rad få plats med både beskrivningen av vad som ska göras med varje objekt i listan och tilldelningen av resultatet till en ny lista.

    I exemplet ovan var operationen som utfördes på varje objekt i listan mycket enkel: varje heltal omvandlades till en sträng. Låt oss se hur detta skulle se ut implementerat med en list comprehension:

    talen = [1, 2, 3, 6, 5, 4, 7]\nstrangar = [str(tal) for tal in talen]

    Den andra raden ovan innehåller många av samma element som den mer traditionella iterativa metoden, men syntaxen är annorlunda. Ett sätt att generalisera en list comprehension skulle kunna vara

    [<uttryck> for <föremål> in <serie>]

    Hakparenteserna runt list comprehensionsatsen signalerar till Python att resultatet ska vara en ny lista. En efter en bearbetas varje objekt i den ursprungliga listan och resultatet lagras i den nya listan, precis som i det iterativa tillvägagångssättet ovan. Som resultat har vi en ny lista med exakt lika många objekt som i originalet, och alla objekt har behandlats på ett identiskt sätt.

    (OBS: originalen till bilderna i denna del saknas tillfälligt, vilket är anledningen till att det finns en del finskt vokabulär i illustrationerna i denna del. Vi arbetar på att åtgärda detta).

    \n \n \n \n \n \n \"11\n \n \n

    List comprehensions kan också hantera mycket mer komplicerade operationer. Vi kan utföra beräkningar, till exempel multiplicera de ursprungliga objekten med tio:

    talen = list(range(1,10))\nprint(talen)\n\ntalen_multiplicerade = [tal * 10 for tal in talen]\nprint(talen_multiplicerade)

    [1, 2, 3, 4, 5, 6, 7, 8, 9]\n[10, 20, 30, 40, 50, 60, 70, 80, 90]

    Faktum är att uttrycket i list comprehension-satsen kan vara vilket Python-uttryck som helst. Du kan till och med anropa funktioner som du själv har definierat:

    def fakultet(n: int):\n    \"\"\" Funktionen räknar fakulteten n! för positiva heltal \"\"\"\n    k = 1\n    while n >= 2:\n        k *= n\n        n -= 1\n    return k\n\nif __name__ == \"__main__\":\n    lista = [5, 2, 4, 3, 0]\n    fakulteter = [fakultet(tal) for tal in lista]\n    print(fakulteter)

    [120, 2, 24, 6, 1]

    Med den mer välbekanta for-loopen skulle samma process kunna uttryckas så här:

    \ndef fakultet(n: int):\n    \"\"\" Funktionen räknar fakulteten n! för positiva heltal \"\"\"\n    k = 1\n    while n >= 2:\n        k *= n\n        n -= 1\n    return k\n\nif __name__ == \"__main__\":\n    lista = [5, 2, 4, 3, 0]\n    fakulteter = []\n    for tal in lista:\n        fakulteter.append(fakultet(tal))\n    print(fakulteter)\n

    List Comprehensions gör att vi kan uttrycka samma funktionalitet på ett mer konsekvent sätt, vanligtvis utan att förlora något av läsbarheten.

    Vi kan också returnera en list comprehension-sats direkt från en funktion. Om vi behövde en funktion för att producera fakultettal för listor med tal, skulle vi kunna göra det på ett mycket kortfattat sätt:

    def fakulteter(talen: list):\n    return [fakultet(tal) for tal in talen]

    Skriv en funktion med namnet kvadratrot(nummer: list) som tar en lista med heltal som sitt argument. Funktionen ska returnera en ny lista som innehåller kvadratrötterna av de ursprungliga heltalen.

    Modulen math från Pythons standardbibliotek innehåller en lämplig funktion för att räkna ut kvadratrötter.

    Funktionen bör använda en list comprehension. Funktionen får vara högst två rader lång, inklusive rubrikraden som börjar med nyckelordet def.

    Funktionen ska fungera enligt följande:

    rader = kvadratrot([1,2,3,4])\nfor rad in rader:\n    print(rad)

    1.0\n1.4142135623730951\n1.7320508075688772\n2.0

    Skapa funktionen stjarnrader(nummer: list) som tar en lista med heltal som sitt argument. Funktionen ska returnera en ny lista som innehåller rader med stjärnor. Längden på varje rad ska motsvara heltalet på samma index i den ursprungliga listan. Funktionen bör använda en list comprehension för att uppnå detta.

    Funktionen får vara högst två rader lång, inklusive rubrikraden som börjar med nyckelordet def.

    Funktionen ska fungera på följande sätt:

    rader = stjarnrader([1,2,3,4])\nfor rad in rader:\n    print(rad)\n\nprint()\n\nrader = stjarnrader([4, 3, 2, 1, 10])\nfor rad in rader:\n    print(rad)
    \n*\n**\n***\n****\n\n****\n***\n**\n*\n**********\n

    I uppgiftsbotten finns färdigt en klassdefinition för Provresultat, som har följane offentliga attribut:

      \n
    • namn
    • \n
    • vitsord1
    • \n
    • vitsord2
    • \n
    • vitsord3
    • \n

    Skapa en funktion med namnet bast_resultat(resultat: list) som tar en lista med Provresultat-objekt som sitt argument.

    Funktionen ska returnera en ny lista som endast innehåller det bästa resultatet från varje Provresultat-objekt. Funktionen bör använda en list comprehension för att uppnå detta.

    Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet def.

    Funktionen ska fungera på följande sätt:

    resultat1 = Provresultat(\"Peter\",5,3,4)\nresultat2 = Provresultat(\"Pernilla\",3,4,1)\nresultat3 = Provresultat(\"Paulus\",2,1,3)\nprestationer = [resultat1, resultat2, resultat3]\nprint(bast_resultat(prestationer))

    [5, 4, 3]

    Skapa en funktion med namnet langder(listor: list) som tar en lista innehållande listor med heltal som argument. Funktionen ska returnera en ny lista som innehåller längderna på listorna i argumentlistan.

    Funktionen bör använda en list comprehension för att uppnå detta.

    Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet def.

    Funktionen ska fungera på följande sätt:

    listat = [[1,2,3,4,5], [324, -1, 31, 7],[]]\nprint(langder(listat))

    [5, 4, 0]

    Att filtrera föremål

    I exemplen ovan var alla våra listor lika långa före och efter en list comprehension-operation. I varje fall användes alla föremål i den ursprungliga listan som grund för den nya listan. Men ibland behöver vi bara några av de ursprungliga föremålen. Hur kan detta åstadkommas?

    En list comprehension-sats kan också innehålla ett villkor, så att vi kan kontrollera objekten mot villkoret och bara välja ut dem som matchar. Den allmänna syntaxen är enligt följande:

    [<uttryck> for <föremål> in <serie> if <boolskt uttryck>]

    Satsen ovan är i övrigt identisk med den allmänna form som introducerades i början av detta avsnitt, men nu finns det en if-sats i slutet. Endast de objekt från den ursprungliga listan för vilka det booleska uttrycket är sant används som grund för den nya listan.

    I exemplet nedan väljer vi alla jämna objekt från den ursprungliga listan som bas för den nya listan. I själva verket bearbetas inte dessa objekt ytterligare på något sätt, utan de tilldelas den nya listan som de är:

    lista = [1, 1, 2, 3, 4, 6, 4, 5, 7, 10, 12, 3]\n\njamna = [foremal for foremal in lista if foremal % 2 == 0]\nprint(jamna)

    [2, 4, 6, 4, 10, 12]

    Uttrycket i list comprehension-satsen ovan är bara ett enkelt foremal, vilket innebär att inga operationer ska utföras på föremålen i listan. Uttrycket kan vara vilket Python-uttryck som helst, precis som i de tidigare exemplen. Följande list comprehension-sats tar till exempel alla jämna föremål i en lista, multiplicerar varje föremål med tio och lagrar resultatet i en ny lista:

    lista = [1, 1, 2, 3, 4, 6, 4, 5, 7, 10, 12, 3]\n\njamna = [foremal * 10 for foremal in lista if foremal % 2 == 0]\nprint(jamna)

    [20, 40, 60, 40, 100, 120]

    När du stöter på mer och mer komplicerade list comprehensions kan det vara bra att försöka läsa villkoret först. Föremålen bearbetas ändå bara om de klarar testet, så det är ofta vettigt att först ta reda på vilka objekt som klarar filtreringssteget. Ibland skulle uttrycket i en list comprehension-sats inte ens vara möjligt för alla föremål i den ursprungliga listan.

    Till exempel är fakultettal bara definierat för icke-negativa heltal. Om vi inte kan vara säkra på att en lista bara innehåller värden på noll eller högre, måste innehållet filtreras innan det skickas vidare till den fakultetfunktion som vi skapade tidigare:

    def fakultet(n: int):\n    \"\"\" Funktionen räknar fakulteten n! för positiva heltal \"\"\"\n    k = 1\n    while n >= 2:\n        k *= n\n        n -= 1\n    return k\n\nif __name__ == \"__main__\":\n    lista = [-2, 3, -1, 4, -10, 5, 1]\n    fakulteter = [fakultet(tal) for tal in lista if tal > 0]\n    print(fakulteter)

    [6, 24, 120, 1]

    Som vi såg i vårt allra första exempel på list comprehension, där heltal omvandlades till strängar, behöver föremålen i den nya listan inte vara av samma typ som föremålen i den ursprungliga listan. Om vi fortsätter från fakultetexemplet ovan kan vi skapa en tupel från varje originella föremål och dess bearbetade motsvarighet och lagra dessa i en lista, vilket kombinerar allt vi har lärt oss hittills i en enda list comprehension-sats:

    \ndef fakultet(n: int):\n    \"\"\" Funktionen räknar fakulteten n! för positiva heltal \"\"\"\n    k = 1\n    while n >= 2:\n        k *= n\n        n -= 1\n    return k\n\nif __name__ == \"__main__\":\n    lista = [-2, 3, 2, 1, 4, -10, 5, 1, 6]\n    fakulteter = [(tal, fakultet(tal)) for tal in lista if tal > 0 and tal % 2 == 0]\n    print(fakulteter)\n

    [(2, 2), (4, 24), (6, 720)]

    Om vi plockar isär exemplet ovan har vi det booleska uttrycket n > 0 and n % 2 == 0. Detta innebär att endast föremål som är både positiva och delbara med två accepteras för vidare bearbetning från den ursprungliga listan.

    Dessa positiva, jämna tal bearbetas sedan i tur och ordning till formatet (n, fakultet(n)). Detta är en tupel, där det första objektet är själva talet och det andra objektet är resultatet som returneras av fakultetfunktionen.

    Skapa en funktion med namnet ta_bort_mindre(tal: list, grans: int) som tar en lista med heltal och ett gränsvärde (också i heltalsformat) som sina argument.

    Funktionen bör använda en list comprehension för att producera en ny lista utan de värden som är mindre än gränsvärdet.

    Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet def.

    Funktionen ska fungera på följande sätt:

    talen = [1,65, 32, -6, 9, 11]\nprint(ta_bort_mindre(talen, 10))\n\nprint(ta_bort_mindre([-4, 7, 8, -100], 0))

    [65, 32, 11]\n[7, 8]

    Skapa en funktion med namnet borjar_med_vokal(ord: list) som tar en lista med strängar som sitt argument.

    Funktionen ska använda en list comprehension teknik för att skapa och returnera en ny lista som endast innehåller de ord från den ursprungliga listan som börjar med en vokal (a, e, i, o, u, y, å, ä, ö). Både små och stora bokstäver bör accepteras.

    Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet def.

    Funktionen ska fungera på följande sätt:

    ord_lista = [\"automobil\",\"moped\",\"Enhörning\",\"katt\",\"Hund\",\"ÄPPEL\",\"appelsin\"]\nfor vok in borjar_med_vokal(ord_lista):\n    print(vok)

    automobil\nEnhörning\nÄPPEL\nappelsin

    Alternativ exekvering med list comprehension

    Ofta när vi har en villkorlig sats inkluderar vi också en else-gren. Eftersom vi kan använda villkor i list comprehensions är else-grenen också tillgänglig med list comprehension. Den allmänna syntaxen för villkoret som används med list comprehension ser ut så här:

    <uttryck 1> if <villkor> else <uttryck 2>

    Vi stötte på dessa enradiga villkor, eller ternära operatorer, redan i modul 7. Uttrycket ovan utvärderas till antingen uttryck 1 eller uttryck 2, beroende på om villkoret är sant eller falskt.

    Som en uppfräschning av ämnet kan vi säga att om vi behöver skriva ut det större av två tal och vi bara vill använda en enda utskriftssats, kan vi få plats med allt på en enda rad:

    tal1 = int(input(\"Ange tal 1:\"))\ntal2 = int(input(\"Ange tal 2:\"))\nprint (tal1 if tal1 > tal2 else tal2)

    Genom att kombinera den ternära operatorssyntaxen med en list comprehension-sats får man följande allmänna struktur:

    [<uttryck 1> if <villkor> else <uttryck 2> for <föremål> in <serie>]

    Det här kan se lite förvirrande ut, eftersom den villkorliga strukturen nu kommer före den faktiska list comprehensionen. Det är bara så här syntaxen har definierats, åtminstone för tillfället. Om det också finns en else-gren kommer villkoret först. Om det bara finns ett if, kommer det sist. Du kan prova att byta ut dem och se vad som händer.

    Att inkludera en else-operator innebär att vi återigen kommer att bearbeta varje objekt från den ursprungliga listan. Beroende på om villkoret är sant eller falskt utförs antingen uttryck 1 eller uttryck 2 på varje objekt i listan.

    I följande exempel kontrolleras om föremåleni en lista är noll eller högre. Alla sådana föremål accepteras som de är, men alla negativa föremål negeras, så att tecknet ändras från negativt till positivt. Resultatet är en lista som innehåller de absoluta värdena för föremålen i den ursprungliga listan.

    \ntalen = [1, -3, 45, -110, 2, 9, -11]\nabsolut_varde = [tal if tal >= 0 else -tal for tal in talen]\nprint(absolut_varde)\n

    [1, 3, 45, 110, 2, 9, 11]

    Vi upprepar vad som händer ovan: om villkoret nummer >= 0 är sant, genomgår föremålet uttrycket nummer, och resultatet är själva föremålet. Om villkoret är falskt genomgår föremålet uttrycket –nummer, så att det får ett positivt värde.

    I följande exempel har vi funktionen strang_langder som tar en lista som sitt argument och returnerar en annan lista med längderna på alla strängar i den ursprungliga listan. Den här funktionen är dock okej med listföremål av alla typer. Om föremålet är en sträng beräknar den dess längd. Om objektet är något annat infogar den -1 i listan som den returnerar.

    \ndef strang_langder(lista: list):\n    \"\"\" Funktionen returnerar längden på strängarna i en ny lista \"\"\"\n    return [len(foremal) if type(foremal) == str else -1 for foremal in lista]\n\nif __name__ == \"__main__\":\n    testlista = [\"hej\", 3, True, \"hejsan\", -123.344, \"hejsansvejsan\", 2, False]\n    langder = strang_langder(testlista)\n    print(langder)\n

    [3, -1, -1, 6, -1, 13, -1, -1]

    LotteriNummer matchade

    Skapa en klass med namnet LotteriNummer som tar veckonumret (ett heltalsvärde) och en lista med sju heltal som sina konstruktorsargument. Listan ska innehålla de korrekta lotterinumren för den givna veckan.

    Skapa också en metod med namnet antalet_traffar(nummer: list) som tar en lista med heltal som sitt argument. Metoden returnerar antalet korrekta inlägg i parameterlistan.

    Metoden bör använda en list comprehension för att uppnå detta. Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet def.

    Funktionen ska fungera på följande sätt:

    ratta = LotteriNummer(5, [1,2,3,4,5,6,7])\negen_rad = [1,4,7,11,13,19,24]\n\nprint(ratta.antalet_traffar(egen_rad))

    3

    LotteriNummer matchade på plats

    Skapa en metod med namnet traffar_pa_plats(nummer) som tar en lista med sju heltal som sitt argument och returnerar en ny lista med sju heltal. Den nya listan innehåller endast de inlägg från den ursprungliga listan som matchar veckans korrekta nummer. Dessa måste ligga kvar på samma index som de gjorde i den ursprungliga listan. Resten av indexen bör fyllas med värdena -1.

    Funktionen bör använda en list comprehension för att uppnå detta. Funktionen får maximalt omfatta två rader kod, inklusive den rubrikrad som börjar med nyckelordet def.

    Funktionen ska fungera på följande sätt:

    ratta = LotteriNummer(8, [1,2,3,10,20,30,33])\negen_rad = [1,4,7,10,11,20,30]\n\nprint(ratta.traffar_pa_plats(egen_rad))

    [1, -1, -1, 10, -1, 20, 30]

    ","frontmatter":{"path":"/osa-11/1-list-comprehension","title":"List comprehension"},"fileAbsolutePath":"/home/runner/work/ohjelmointi-24-sv/ohjelmointi-24-sv/data/osa-11/1-list-comprehension.md"},"allPages":{"edges":[{"node":{"id":"b5e8ae41-d492-55f7-88a7-1c7292333ab1","frontmatter":{"path":"/arvostelu-ja-kokeet","title":"Arvostelu ja kokeet"}}},{"node":{"id":"af4df6be-211d-5ba1-acea-9edbefa06c49","frontmatter":{"path":"/frontmatter-guide","title":"Frontmatter-guide"}}},{"node":{"id":"56769133-4836-5fbb-a857-8fb0c6803e6d","frontmatter":{"path":"/","title":"Tietoa kurssista"}}},{"node":{"id":"e86762f0-c2a9-5598-aba3-2b8d7db7807c","frontmatter":{"path":"/kaikki-tehtavat","title":"Kaikki tehtävät"}}},{"node":{"id":"5d065309-85e8-5823-9527-ec1c3cf38d4d","frontmatter":{"path":"/tuki","title":"Tukea tehtäviin"}}},{"node":{"id":"ac195ee0-ad04-5cc9-9643-963f93d29ad2","frontmatter":{"path":"/usein-kysytyt-kysymykset","title":"Usein kysytyt kysymykset"}}},{"node":{"id":"51a165d7-8ce5-5d53-9c15-5321b6adef8c","frontmatter":{"path":"/verkkotentti","title":"Verkkotentti 4.6."}}},{"node":{"id":"4d9cf293-01e9-5e6c-a88f-599560e33c9a","frontmatter":{"path":"/verkkotentti-ohja","title":"Ohjelmoinnin jatkokurssin verkkotentti 16.12."}}},{"node":{"id":"279e1cca-fb0b-5d3f-b527-be05243d138d","frontmatter":{"path":"/verkkotentti-ohpe","title":"Ohjelmoinnin perusteiden verkkotentti 09.03."}}},{"node":{"id":"347bdde4-ba21-5f22-8a88-0287dfe29a45","frontmatter":{"path":"/virheilmoitukset","title":"Yleiset virheilmoitukset"}}},{"node":{"id":"3bf12e3a-1542-57f4-812d-dd32cebc99e2","frontmatter":{"path":"/sanasto","title":"Sanasto"}}},{"node":{"id":"9910673b-d62d-5d8d-a756-5267160d891f","frontmatter":{"path":"/osa-1/1-introduktion","title":"Introduktion"}}},{"node":{"id":"0b17a28e-f939-57cc-aa5b-4db407cdf34a","frontmatter":{"path":"/osa-1/2-info-fran-anvandaren","title":"Information från användaren"}}},{"node":{"id":"b95794f2-f3b3-597c-a4ec-6f023b584f81","frontmatter":{"path":"/osa-1/3-mer-om-variabler","title":"Mer om variabler"}}},{"node":{"id":"02cd0849-e7a5-5fd1-bf66-35f0197d3e75","frontmatter":{"path":"/osa-1/4-rakneoperationer","title":"Räkneoperationer"}}},{"node":{"id":"42690a69-3997-5b84-b999-15d9c3212884","frontmatter":{"path":"/osa-1/5-villkorssatser","title":"If-satser"}}},{"node":{"id":"96a0ec65-c0a3-5150-95c5-48c260f88162","frontmatter":{"path":"/osa-1","title":"Modul 1"}}},{"node":{"id":"e7a4d0c8-b8c1-53fa-ab51-9cc06fd417a3","frontmatter":{"path":"/osa-10/1-klasshierarkier","title":"Klasshierarkier"}}},{"node":{"id":"5f6d4b8b-7d05-5c79-9f2f-9e30b397167b","frontmatter":{"path":"/osa-10/2-atkamstmodifierare","title":"Åtkomstmodifierare"}}},{"node":{"id":"bb896c90-aabc-5a9d-8d4b-50839da286db","frontmatter":{"path":"/osa-10/3-objektorienterade-programmeringstekniker","title":"Objektorienterade programmeringstekniker"}}},{"node":{"id":"a2dca4f1-d64d-5e77-a3ca-8b2a208e9afa","frontmatter":{"path":"/osa-10/4-storre-applikation","title":"Att utveckla en större applikation"}}},{"node":{"id":"8c9cf5a7-f02e-5ccf-ab8f-f078c3ccecb6","frontmatter":{"path":"/osa-10","title":"Modul 10"}}},{"node":{"id":"f6688d26-5502-5c17-a8ee-db66f650f1f1","frontmatter":{"path":"/osa-11/1-list-comprehension","title":"List comprehension"}}},{"node":{"id":"1eac8489-72f2-5d53-904b-c960e2622018","frontmatter":{"path":"/osa-11/2-mer-om-comprehensions","title":"Mer om comprehensions"}}},{"node":{"id":"09630fca-7768-53f3-8aca-6e5ac638fc68","frontmatter":{"path":"/osa-11/3-rekursion","title":"Rekursion"}}},{"node":{"id":"70f6008e-a762-574c-a92a-c5c585d9677e","frontmatter":{"path":"/osa-11/4-lisaa-esimerkkeja","title":"Fler exempel på rekursion"}}},{"node":{"id":"eb8ed7d7-c39d-52db-949d-f75649498c67","frontmatter":{"path":"/osa-11","title":"Modul 11"}}},{"node":{"id":"9bba31dc-e14c-5400-a25b-7339107e9ba7","frontmatter":{"path":"/osa-12/1-funktioner-som-argument","title":"Funktioner som argument"}}},{"node":{"id":"5b9e4584-7234-5216-a118-d2a1bc617e13","frontmatter":{"path":"/osa-12/2-generatorer","title":"Generatorer"}}},{"node":{"id":"1d27636e-74f4-5c30-a1d8-08a303684945","frontmatter":{"path":"/osa-12/3-funktionell-programmering","title":"Funktionell programmering"}}},{"node":{"id":"6785750f-f145-5b88-81e9-b52e36ba53c6","frontmatter":{"path":"/osa-12/4-reguljara-uttryck","title":"Reguljära uttryck"}}},{"node":{"id":"d21df33a-4bf4-5ee3-9e2a-431d57561f09","frontmatter":{"path":"/osa-12","title":"Modul 12"}}},{"node":{"id":"14e3c129-50ec-581f-8679-8132248d41c1","frontmatter":{"path":"/osa-13/1-pygame","title":"Pygame"}}},{"node":{"id":"01bc3b9b-4f80-5561-8b56-3a7f09082263","frontmatter":{"path":"/osa-13/2-animation","title":"Animation"}}},{"node":{"id":"dd68786f-e2fc-5957-b47a-52b74c5199ef","frontmatter":{"path":"/osa-13/3-handelser","title":"Händelser"}}},{"node":{"id":"4a1aaa41-d6f7-51cd-8b89-95842cb9e02d","frontmatter":{"path":"/osa-13/4-fler-pygame-tekniker","title":"Fler pygame-tekniker"}}},{"node":{"id":"cdcf0ce1-e881-5ca6-8fa9-d0d343ec4e15","frontmatter":{"path":"/osa-13","title":"Modul 13"}}},{"node":{"id":"0ab28435-7654-5a8e-88d6-daa17d78103b","frontmatter":{"path":"/osa-14/1-spelprojekt","title":"Spelprojekt"}}},{"node":{"id":"b7a0628c-e4ba-583e-a52a-dd0ad78028d8","frontmatter":{"path":"/osa-14/2-robot-och-ladar","title":"Robot och lådor"}}},{"node":{"id":"6ccdbdff-7539-5a23-b23c-2ad48a99386f","frontmatter":{"path":"/osa-14/3-fardigstallande-av-spelet","title":"Färdigställande av spelet"}}},{"node":{"id":"1b505c9f-9b1b-58bd-8df7-553fef49cc8d","frontmatter":{"path":"/osa-14/4-ditt-eget-sepl","title":"Ditt eget spel"}}},{"node":{"id":"55c54859-8c7f-5fd9-8a8d-2c54ee677577","frontmatter":{"path":"/osa-14","title":"Modul 14"}}},{"node":{"id":"b5c346d1-d175-5824-98bb-4a4c3b45204d","frontmatter":{"path":"/osa-2/1-terminologi","title":"Programmeringsterminologi"}}},{"node":{"id":"db7188b0-0253-5c30-b8d2-0e115e235fb3","frontmatter":{"path":"/osa-2/2-else-elif","title":"Mera om if-satser"}}},{"node":{"id":"49d15928-f8b9-5883-9f29-86c307f6929e","frontmatter":{"path":"/osa-2/3-kombinera-villkor","title":"Kombinera villkor"}}},{"node":{"id":"93f1f9c8-6b27-5892-8bd4-7d1d008bf07a","frontmatter":{"path":"/osa-2/4-loopar","title":"Enkla loopar"}}},{"node":{"id":"5523b5b8-61f8-506d-bfe0-c6cc774390ce","frontmatter":{"path":"/osa-2","title":"Modul 2"}}},{"node":{"id":"02012307-c2a6-5cf2-9105-c10933c14b37","frontmatter":{"path":"/osa-3/1-loopar-med-villkor","title":"Loopar med villkor"}}},{"node":{"id":"efb889f4-4a19-515e-a0f6-4297d76a2757","frontmatter":{"path":"/osa-3/2-behandla-strangar","title":"Behandla strängar"}}},{"node":{"id":"a602077d-bbae-5eb7-a354-cc44b29ae96a","frontmatter":{"path":"/osa-3/3-mer-om-loopar","title":"Mera om loopar"}}},{"node":{"id":"6d878692-b9c7-57e6-ae58-044e5a6bef6f","frontmatter":{"path":"/osa-3/4-definiera-funktioner","title":"Definiera funktioner"}}},{"node":{"id":"682b5a18-73c5-56e2-8374-237baccbab40","frontmatter":{"path":"/osa-3","title":"Modul 3"}}},{"node":{"id":"3de95518-6b44-54db-9bcd-0c90a41d2fd5","frontmatter":{"path":"/osa-4/1-vscode","title":"Editorn Visual Studio Code, Pythontolken och det inbyggda debuggningsverktyget"}}},{"node":{"id":"7de9921c-7f94-58fe-84b9-7676dddb3b94","frontmatter":{"path":"/osa-4/2-mer-om-funktioner","title":"Mer om funktioner"}}},{"node":{"id":"29e29c69-360c-5f5c-8f34-5aef22eb327f","frontmatter":{"path":"/osa-4/3-listor","title":"Listor"}}},{"node":{"id":"bfe57880-0cbb-54e4-be9c-8fa180eafe6b","frontmatter":{"path":"/osa-4/4-iteration","title":"Iteration"}}},{"node":{"id":"2eab46f0-5373-5cbe-b2a0-1d071854a053","frontmatter":{"path":"/osa-4/5-utskrift","title":"Formatera utskrift"}}},{"node":{"id":"a5974fee-f2eb-5b89-88a5-6dd3754baaad","frontmatter":{"path":"/osa-4/6-strangar-listor","title":"Mera strängar och listor"}}},{"node":{"id":"e125c469-ee19-505e-9a41-83da6143ecd8","frontmatter":{"path":"/osa-4","title":"Modul 4"}}},{"node":{"id":"2558444a-be1d-5bc6-95ab-e091da2443fc","frontmatter":{"path":"/osa-5/1-mer-om-listor","title":"Mer om listor"}}},{"node":{"id":"b452d9be-0569-56c2-ba89-a040d4cb40dc","frontmatter":{"path":"/osa-5/2-referenser","title":"Referenser"}}},{"node":{"id":"ebe4ca3f-e657-5907-bfcc-ae84d9947aff","frontmatter":{"path":"/osa-5/3-lexikon","title":"Lexikon"}}},{"node":{"id":"f1dd5d66-ac87-5e53-92a0-0b7e3ece6ed8","frontmatter":{"path":"/osa-5/4-tuple","title":"Tuple"}}},{"node":{"id":"161c0109-5c00-5bed-b7af-90dc7ddf5713","frontmatter":{"path":"/osa-5","title":"Modul 5"}}},{"node":{"id":"e6cfa6e1-e99b-50e0-bc6a-3c0f153420e8","frontmatter":{"path":"/osa-6/1-lasa-filer","title":"Läsa filer"}}},{"node":{"id":"ce8d90a4-ca7c-5797-abc1-3fe0094bfa4b","frontmatter":{"path":"/osa-6/2-skriva-filer","title":"Skriva filer"}}},{"node":{"id":"519d5330-277a-59ba-be50-c2f63080df94","frontmatter":{"path":"/osa-6/3-fel","title":"Förbered dig på fel"}}},{"node":{"id":"82393756-3ef8-5d07-a8da-fed818ca43f0","frontmatter":{"path":"/osa-6/4-lokala-globala-variabler","title":"Lokala och globala variabler"}}},{"node":{"id":"007d85ae-a118-5b10-8a7e-18302b15eba8","frontmatter":{"path":"/osa-6","title":"Modul 6"}}},{"node":{"id":"bbb2346d-b1ee-551d-89c1-516f119b0eed","frontmatter":{"path":"/osa-7/1-moduler","title":"Moduler"}}},{"node":{"id":"ecb9af64-49f9-5e28-a544-3934e95233cf","frontmatter":{"path":"/osa-7/2-slumpmassighet","title":"Slumpmässighet"}}},{"node":{"id":"ebe469ef-c486-523a-9621-5dc4040c5cd8","frontmatter":{"path":"/osa-7/3-tid-datum","title":"Tid och datum"}}},{"node":{"id":"b9cf2d99-08f6-5de5-8425-c9b483241567","frontmatter":{"path":"/osa-7/4-behandla-data","title":"Behandla data"}}},{"node":{"id":"27075b37-8a6a-5554-9079-465a36d2da2d","frontmatter":{"path":"/osa-7/5-egna-moduler","title":"Skapa dina egna moduler"}}},{"node":{"id":"69492225-4d69-59ea-b33d-5301d35cf4ed","frontmatter":{"path":"/osa-7/6-funktionaliteter-python","title":"Flera funktionaliteter i Python"}}},{"node":{"id":"70ae841a-e6e9-5252-afae-6329fb67bcad","frontmatter":{"path":"/osa-7","title":"Modul 7"}}},{"node":{"id":"4afc4486-3cfe-53d1-b4c0-6db26484acfa","frontmatter":{"path":"/osa-8/1-objekt-och-metoder","title":"Objekt och metoder"}}},{"node":{"id":"6be37772-e94b-5b36-8a02-fffa7eef9feb","frontmatter":{"path":"/osa-8/2-klasser-och-objekt","title":"Klasser och objekt"}}},{"node":{"id":"8b6aec39-f8b9-525c-9f25-d8e73389fa42","frontmatter":{"path":"/osa-8/3-egna-klasser","title":"Egna klasser"}}},{"node":{"id":"85db460a-77c6-5087-8e97-a3c772186fd9","frontmatter":{"path":"/osa-8/4-metoder-i-egna-klasser","title":"Metoder i egna klasser"}}},{"node":{"id":"0e59dee0-5dd9-5827-83b9-a55e7d585c31","frontmatter":{"path":"/osa-8/5-fler-exempel","title":"Fler exempel"}}},{"node":{"id":"64715d0c-54f1-5aa7-a566-d2c5be6523ea","frontmatter":{"path":"/osa-8","title":"Modul 8"}}},{"node":{"id":"f7457509-a9a6-5420-8d03-ff1c61df8dc4","frontmatter":{"path":"/osa-9/1-objekt-och-referenser","title":"Objekt och referenser"}}},{"node":{"id":"16689ce4-b6aa-5bc4-9a30-44820994d6ea","frontmatter":{"path":"/osa-9/2-objekt-som-attribut","title":"Objekt som attribut "}}},{"node":{"id":"07985959-e85a-5f45-8923-babacb943c04","frontmatter":{"path":"/osa-9/3-inkapsling","title":"Inkapsling"}}},{"node":{"id":"83108600-9a37-5fd1-9a2b-13492879a9d6","frontmatter":{"path":"/osa-9/4-metodernas-rackvidd","title":"Metodernas räckvidd"}}},{"node":{"id":"a553cdc9-d6ac-5a14-ab43-d44811b407a2","frontmatter":{"path":"/osa-9/5-klassattribut","title":"Klassattribut"}}},{"node":{"id":"f7d7c9f1-6b54-5268-a308-995d49dd913d","frontmatter":{"path":"/osa-9/6-fler-exempel-med-klasser","title":"Fler exempel med klasser"}}},{"node":{"id":"c1fef3f7-8ca3-5780-9dec-19bd672b4627","frontmatter":{"path":"/osa-9","title":"Modul 9"}}}]}},"pageContext":{}}, "staticQueryHashes": ["1357757885","994120085"]} \ No newline at end of file diff --git a/page-data/osa-11/3-rekursion/page-data.json b/page-data/osa-11/3-rekursion/page-data.json index 9fe3949df..10b546496 100644 --- a/page-data/osa-11/3-rekursion/page-data.json +++ b/page-data/osa-11/3-rekursion/page-data.json @@ -1,5 +1,5 @@ { "componentChunkName": "component---src-templates-course-content-template-js", "path": "/osa-11/3-rekursion", - "result": {"data":{"page":{"htmlAst":{"type":"element","tagName":"div","properties":{},"children":[{"type":"element","tagName":"text-box","properties":{"variant":"learningObjectives","name":"Inlärningsmål"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Efter den här delen"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Vet du vad rekursion innebär"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Kommer du att kunna skriva en enkel rekursiv funktion"}]},{"type":"text","value":"\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Som vi har sett många gånger tidigare kan funktioner anropa andra funktioner. Till exempel:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"hej"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Hejsan,\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"hej_flera"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" ganger "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" i "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"range"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ganger"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n hej"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"En funktion kan också anropa sig själv, men vi som programmerare måste vara försiktiga när vi gör det. Det är lätt att hamna i en oändlig loop av funktionsanrop, precis som vi hamnade i en oändlig loop av upprepningar med "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"while"}]},{"type":"text","value":"-loopar om vi utelämnade lämpliga brytvillkor. Så om man försöker anropa en "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"hej"}]},{"type":"text","value":"-funktion med följande definition"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"hej"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Hejsan,\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n hej"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"skulle skapa ett nytt sort av fel:"}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"RecursionError: maximum recursion depth exceeded"}]}]},{"type":"element","tagName":"h2","properties":{"id":"vad-betyder-rekursion","style":"position:relative;"},"children":[{"type":"text","value":"Vad betyder rekursion?"},{"type":"element","tagName":"a","properties":{"href":"#vad-betyder-rekursion","ariaLabel":"vad betyder rekursion permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Den rekursion som nämns i felet ovan innebär att man definierar något i termer av sig självt. I programmeringssammanhang handlar det oftast om en funktion som anropar sig själv. För att detta ska fungera utan att orsaka oändliga loopar måste de argument som skickas till funktionen ändras varje gång, så att de nästlade funktionsanropen slutar vid något skede. Grundprincipen här är densamma som i "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"while"}]},{"type":"text","value":"-loopar: det måste alltid finnas ett stoppvillkor av något slag, och det villkoret måste utlösas vid någon tidpunkt i exekveringen."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss ta en titt på en enkel funktion som lägger till nollor i en lista så länge det finns färre än 10 objekt i listan. Den här gången använder vi dock inte en loop. Om villkoret ännu inte är uppfyllt anropar funktionen sig själv"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"fyll_lista"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"list"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","triple-quoted-string","string"]},"children":[{"type":"text","value":"\"\"\" Lägger till föremål till listan ifall listans längd är kortare än 10 \"\"\""}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"<"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# anropa funktionen igen"}]},{"type":"text","value":"\n fyll_lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n test "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n fyll_lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"test"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"test"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[1, 2, 3, 4, 0, 0, 0, 0, 0, 0]"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Denna funktionalitet kunde lika väl bli uppnådd genom en vanlig "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"while"}]},{"type":"text","value":"-loop:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"fyll_lista"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"list"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","triple-quoted-string","string"]},"children":[{"type":"text","value":"\"\"\" Lägger till föremål till listan ifall listans längd är kortare än 10 \"\"\""}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"while"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"<"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n test "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n fyll_lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"test"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"test"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Det mer traditionella iterativa tillvägagångssättet ger ett kortare program som förmodligen också är lättare att förstå. Med den rekursiva versionen är det inte lika tydligt att vi under hela processen arbetar med exakt samma lista. Så är det dock och därför fungerar den rekursiva funktionen lika bra."}]},{"type":"element","tagName":"text-box","properties":{"variant":"hint","name":"Iterativ eller rekursiv?"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Inom datavetenskapsteori skiljer man ofta mellan iterativa och rekursiva algoritmer, så det är bäst att bekanta sig med dessa termer redan från början. Iterativa lösningar är sådana som baseras på sekventiell bearbetning av objekt, ofta med hjälp av loopar. Hittills har vi behandlat iterativa metoder ganska exklusivt. Rekursiv, å andra sidan, avser en metod där funktionen anropar sig själv med förändrade parametervärden."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I princip borde det vara möjligt att lösa alla problem med antingen iterativa eller rekursiva metoder. I praktiken är det dock oftast så att den ena eller den andra metoden är klart bättre lämpad för varje problem. Förmågan att avgöra vilken som är bäst kommer till stor del med övning."}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Större tal","tmcname":"osa11-13_tal_till_listan"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"rekursiv funktion"}]},{"type":"text","value":" "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"tal_till_listan(tal: list)"}]},{"type":"text","value":". Funktionen tar en lista med tal som sitt argument och lägger till nya tal i listan tills längden på listan är delbar med fem. Varje tal som läggs till i listan ska vara ett större tal än det sista talet i listan."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen måste anropa sig själv rekursivt."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Fxempel på funktionen i användning:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"tal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"11"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\ntal_till_listan"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[1, 3, 4, 5, 10, 11, 12, 13, 14, 15]"}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"rekursion-och-returvarden","style":"position:relative;"},"children":[{"type":"text","value":"Rekursion och returvärden"},{"type":"element","tagName":"a","properties":{"href":"#rekursion-och-returvarden","ariaLabel":"rekursion och returvarden permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Rekursiva funktioner kan också ha returvärden. I de senaste avsnitten har vi arbetat med fakultettal, så låt oss skriva en rekursiv fakultetfunktion:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"fakultet"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","triple-quoted-string","string"]},"children":[{"type":"text","value":"\"\"\" Funktionen räknar ut fakulteten n! för n>= 0 \"\"\""}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"<"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Fakulteten av 0 och 1 är 1"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# anropa funktionen igen"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*"}]},{"type":"text","value":" fakultet"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Testar"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" i "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"range"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\"Fakulteten av "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"i"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" är "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"fakultet"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"i"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Fakulteten av 1 är 1\nFakulteten av 2 är 2\nFakulteten av 3 är 6\nFakulteten av 4 är 24\nFakulteten av 5 är 120\nFakulteten av 6 är 720"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Om parametern för den rekursiva faktoriella funktionen är 0 eller 1, returnerar funktionen 1, eftersom det är så faktoriell operation definieras. I alla andra fall returnerar funktionen värdet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"n * fakultet(n - 1)"}]},{"type":"text","value":", vilket är värdet av dess parameter n multiplicerat med returvärdet av funktionsanropet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"fakultet(n - 1)"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Det avgörande här är att funktionsdefinitionen innehåller ett stoppvillkor. Om detta uppfylls avslutas rekursionen. I det här fallet är villkoret "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"n < 2"}]},{"type":"text","value":". Vi vet att det kommer att nås så småningom, eftersom det värde som skickas som argument till funktionen minskas med ett på varje nivå i rekursionen."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"http://www.pythontutor.com/visualize.html#mode=edit","target":"_blank","rel":["noopener","noreferrer"]},"children":[{"type":"text","value":"Visualiseringsverktyget"}]},{"type":"text","value":" kan vara till stor hjälp när det gäller att förstå rekursiva program."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Exemplet ovan skulle kanske bli lite tydligare om vi använde oss av hjälpvariabler:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"fakultet"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"<"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n\n forra_talets_fakultet "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" fakultet"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n fakultet_nu "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*"}]},{"type":"text","value":" forra_talets_fakultet\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" fakultet_nu\n\nfakultet"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ta en titt på hur"},{"type":"element","tagName":"a","properties":{"href":"http://www.pythontutor.com/visualize.html#code=def%20kertoma%28n%3A%20int%29%3A%0A%20%20%20%20if%20n%20%3C%202%3A%0A%20%20%20%20%20%20%20%20return%201%0A%0A%20%20%20%20edellisen_luvun_kertoma%20%3D%20kertoma%28n%20-%201%29%0A%20%20%20%20luvun_n_kertoma%20%3D%20n%20*%20edellisen_luvun_kertoma%0A%20%20%20%20return%20luvun_n_kertoma%0A%20%20%20%20%0Akertoma%285%29&cumulative=false&curInstr=5&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=3&rawInputLstJSON=%5B%5D&textReferences=false","target":"_blank","rel":["noopener","noreferrer"]},"children":[{"type":"text","value":"visualiseringsverktyget"}]},{"type":"text","value":" visar hur rekursionen fortskrider."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Visualiseringsverktyget har en liten finess i hur det hanterar anropsstacken, eftersom den verkar \"växa\" nedåt. Vanligtvis avbildas anropsstaplar som just staplar, där de nya anropen placeras överst. I visualiseringsverktyget är det aktiva funktionsanropet det skuggade blocket längst ner, som har sina egna kopior av de variabler som syns."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"När den rekursiva faktorfunktionen anropas byggs anropsstapeln upp tills den gräns som utgörs av "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"n < 2"}]},{"type":"text","value":" nås. Då återkommer det sista funktionsanropet i stacken med ett värde - det är "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":", eftersom "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"n"}]},{"type":"text","value":" nu är mindre än 2. Detta återkomstvärde skickas till det föregående funktionsanropet i stacken, där det används för att beräkna det funktionsanropets återkomstvärde, och så vidare tillbaka ut ur stacken."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Returvärdet för varje funktionsanrop lagras i hjälpvariabeln "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"fakultet_nu"}]},{"type":"text","value":". Gå igenom visualiseringen noggrant tills du förstår vad som händer i varje steg, och var särskilt uppmärksam på det värde som returneras i varje steg."}]},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-wrapper"],"style":"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 920px; margin-bottom: 1rem;"},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"a","properties":{"className":["gatsby-resp-image-link"],"href":"/ohjelmointi-24-sv/static/9d75a2d6b42864178f98c237765dbc86/6976b/11_1_1.png","style":"display: block","target":"_blank","rel":["noopener"]},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-background-image"],"style":"padding-bottom: 43.913043478260875%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAIAAAC9o5sfAAAACXBIWXMAABYlAAAWJQFJUiTwAAABKklEQVQoz42Ry04DMQxF+/+fxgapGwQSQtBKhcx08rJnbMeOUWcKpTuOoiwSnST3ZpcrlYq1lgJLKpeRCwCA/4Odu/cVNQtjHM7ZrG+L26ym3b2tiMg8zze5946I0zSllBaSpv1Xc3dZaKmwAJaYlEVEzuezqt5kMyuljOOIAIhYV4jIepcQecqOJBksVudm3brZVTZhJgor4zDEONUfmLmlyk3c3bzrTE5yl9lUAaCU0loDJJj57zaPaangaiZN6+zcfI10lWvOKaWtBhZjtt59y+LuMaSP18/xVE6HqXxGX+5v1tbMDAFCCMPl7V8hBADo6xkh4ePzcf9yfHh6D4fB9292HPtUvF062wFKRSFAYUorIqKq2/+xaEGKGWIGknYpayZjMTUz+wbqwQrKy5mcywAAAABJRU5ErkJggg=='); background-size: cover; display: block;"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"picture","properties":{},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/9d75a2d6b42864178f98c237765dbc86/a0b58/11_1_1.webp 230w","/ohjelmointi-24-sv/static/9d75a2d6b42864178f98c237765dbc86/bc10c/11_1_1.webp 460w","/ohjelmointi-24-sv/static/9d75a2d6b42864178f98c237765dbc86/966d8/11_1_1.webp 920w","/ohjelmointi-24-sv/static/9d75a2d6b42864178f98c237765dbc86/445df/11_1_1.webp 1380w","/ohjelmointi-24-sv/static/9d75a2d6b42864178f98c237765dbc86/78de1/11_1_1.webp 1840w","/ohjelmointi-24-sv/static/9d75a2d6b42864178f98c237765dbc86/129b4/11_1_1.webp 2172w"],"sizes":"(max-width: 920px) 100vw, 920px","type":"image/webp"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/9d75a2d6b42864178f98c237765dbc86/81c8e/11_1_1.png 230w","/ohjelmointi-24-sv/static/9d75a2d6b42864178f98c237765dbc86/08a84/11_1_1.png 460w","/ohjelmointi-24-sv/static/9d75a2d6b42864178f98c237765dbc86/c0255/11_1_1.png 920w","/ohjelmointi-24-sv/static/9d75a2d6b42864178f98c237765dbc86/b1001/11_1_1.png 1380w","/ohjelmointi-24-sv/static/9d75a2d6b42864178f98c237765dbc86/161ec/11_1_1.png 1840w","/ohjelmointi-24-sv/static/9d75a2d6b42864178f98c237765dbc86/6976b/11_1_1.png 2172w"],"sizes":"(max-width: 920px) 100vw, 920px","type":"image/png"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"img","properties":{"className":["gatsby-resp-image-image"],"src":"/ohjelmointi-24-sv/static/9d75a2d6b42864178f98c237765dbc86/c0255/11_1_1.png","alt":"11 1 1","title":"11 1 1","loading":"lazy","decoding":"async","style":"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"},"children":[]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss ta en titt på ett annat vanligt rekursivt exempel: Fibonacci-talen. I en Fibonacci-sekvens är varje tal summan av de två föregående talen. De två första talen definieras här som 1 och 1, och sekvensen börjar då så här: 1, 1, 2, 3, 5, 8, 13, 21, 34."}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"fibonacci"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","triple-quoted-string","string"]},"children":[{"type":"text","value":"\"\"\" Funktionen returnerar det n:e talet i Fibonaccis talföljd \"\"\""}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"<="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# de första två är ettor"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Alla andra tal blir summan av de två föregående talen"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" fibonacci"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+"}]},{"type":"text","value":" fibonacci"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"n "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Testar att allting fungerar"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" i "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"range"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"11"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\"Fibonaccis "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"i"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":". tal är "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"fibonacci"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"i"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Fibonaccis 1. tal är 1\nFibonaccis 2. tal är 1\nFibonaccis 3. tal är 2\nFibonaccis 4. tal är 3\nFibonaccis 5. tal är 5\nFibonaccis 6. tal är 8\nFibonaccis 7. tal är 13\nFibonaccis 8. tal är 21\nFibonaccis 9. tal är 34\nFibonaccis 10. tal är 55"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Den här gången är stoppvillkoret att parametern är mindre än eller lika med 2, eftersom hela sekvensen definieras från de två första siffrorna och framåt, och vi definierade de två första siffrorna som lika med 1."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Hur fungerar då den här funktionen i praktiken?"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Om funktionen anropas med 1 eller 2 som argument returnerar den 1, vilket dikteras av villkoret "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"n <= 2"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Om argumentet är 3 eller större returnerar funktionen värdet av "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"fibonacci(n - 1) + fibonacci(n - 2)"}]},{"type":"text","value":". Om argumentet är exakt 3 är detta värde lika med "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"fibonacci(2) + fibonacci(1)"}]},{"type":"text","value":", och vi vet redan resultatet av båda dessa från föregående steg. "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"1 + 1"}]},{"type":"text","value":" är lika med 2, som alltså är det tredje talet i Fibonacci-sekvensen."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Om argumentet är 4 är returvärdet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"fibonacci(3) + fibonacci(2)"}]},{"type":"text","value":", som vi nu vet är "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"2 + 1"}]},{"type":"text","value":", vilket är lika med 3."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Om argumentet är 5 är returvärdet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"fibonacci(4) + fibonacci(3)"}]},{"type":"text","value":", vilket vi nu vet är "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"3 + 2"}]},{"type":"text","value":", vilket är lika med 5."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Och så vidare, och så vidare."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Vi kan i varje steg verifiera att funktionen ger rätt resultat, vilket ofta är tillräckligt i grundläggande programmeringsuppgifter. Den formella verifierbarheten av algoritmer är ett ämne för mer avancerade kurser, till exempel Data Structures and Algorithms."}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Rekursiv summa","tmcname":"osa11-14_rekursiv_summa"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en rekursiv funktion med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"summa(tal: int)"}]},{"type":"text","value":", som räknar summan "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"1 + 2 + ... + tal"}]},{"type":"text","value":". Funktionens mall är följande:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"summa"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# ifall talet är 1, finns det inget att tillägga"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" tal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"<="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" tal\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# fyll i resten"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Några exempel:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"resultat "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" summa"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"resultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"summa"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"summa"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"6\n15\n55"}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Balanserade parenteser","tmcname":"osa11-15_balanserade_parenteser"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I uppgiftsbotten finns den färdiga funtkionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"balanserade_parenteser"}]},{"type":"text","value":" som tar en sträng som argument. Funktionen kollar ifall "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"runda"}]},{"type":"text","value":" parenteser inom strängen är balanserade. Med andra ord, för varje öppnande parentes "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":" ska det finnas en stängande parentes "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":", och alla parenteser ska vara i matchande ordning, alltså får parentesparen inte korsas."}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"balanserade_parenteser"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"strang"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"strang"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"True"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"not"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"strang"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'('"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"and"}]},{"type":"text","value":" strang"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"')'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"False"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# ta bort första och sista tecknet"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" balanserade_parenteser"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"strang"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nok "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" balanserade_parenteser"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"(((())))\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# finns en parentes för mycket, alltså False"}]},{"type":"text","value":"\nok "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" balanserade_parenteser"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"()())\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# börjar med en stängande parentes, alltså False igen"}]},{"type":"text","value":"\nok "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" balanserade_parenteser"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\")()\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# är inte giltig, eftersom funktionen bara kan hantera helt inkapslade parenteser"}]},{"type":"text","value":"\nok "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" balanserade_parenteser"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"()(())\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"True\nFalse\nFalse\nFalse"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Utöka funktionen så att den även fungerar med hakparenteser "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"[]"}]},{"type":"text","value":". Funktionen bör också ignorera alla tecken som inte är parenteser "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"()"}]},{"type":"text","value":" eller "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"[]"}]},{"type":"text","value":". De olika typerna av parenteser måste matchas korrekt i tur och ordning."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ett par exempel:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"ok "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" balanserade_parenteser"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"([([])])\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nok "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" balanserade_parenteser"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"(python version [3.7]) använd denna!\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# felaktigt stängande parentes"}]},{"type":"text","value":"\nok "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" balanserade_parenteser"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"(()]\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# felaktiga matchningar av parenteser"}]},{"type":"text","value":"\nok "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" balanserade_parenteser"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"([dåligt)]\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Obs: Funktionen behöver endast hantera helt inkapslade parenteser. Strängen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"(x+1)(y+1)"}]},{"type":"text","value":" ska producera "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"False"}]},{"type":"text","value":", eftersom parenteserna inte är inkapslade inom varandra."}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"True\nTrue\nFalse\nFalse"}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"binar-sokning","style":"position:relative;"},"children":[{"type":"text","value":"Binär sökning"},{"type":"element","tagName":"a","properties":{"href":"#binar-sokning","ariaLabel":"binar sokning permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I en binär sökning har vi en sorterad lista med objekt och vi försöker hitta ett visst objekt i den. Ordningen på objekten kan till exempel vara siffror från minst till störst, eller strängar från alfabetiskt först till sist. Sorteringsmetoden spelar ingen roll, så länge den är känd och relevant för det objekt som vi försöker hitta."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Tanken med en binär sökning är att alltid titta på objektet i mitten av listan. Vi har då tre möjliga scenarier. Om objektet i mitten är"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"det vi letar efter: vi kan returnera en indikation på att vi hittade objektet"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"mindre än det vi letar efter: vi kan göra om sökningen i den större halvan av listan"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"större än den vi letar efter: vi kan göra om sökningen i den mindre halvan av listan."}]},{"type":"text","value":"\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Om listan är tom kan vi fastställa att objektet inte hittades och returnera en indikation på det."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I följande bild kan vi se hur en binär sökning fortskrider när den letar efter talet 24:"}]},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-wrapper"],"style":"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 777px; margin-bottom: 1rem;"},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"a","properties":{"className":["gatsby-resp-image-link"],"href":"/ohjelmointi-24-sv/static/ca600c1fe96166b67e6fe37b5f5dcc89/108f8/11_3_1.png","style":"display: block","target":"_blank","rel":["noopener"]},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-background-image"],"style":"padding-bottom: 43.47826086956522%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAIAAAC9o5sfAAAACXBIWXMAAA7DAAAOwwHHb6hkAAABXklEQVQoz5WQ3UvCUBiH989FdN9dRBAUEhFd1G13EXQREQTdCAYl5AojMQrLKfRBNmSVusCczjn3gbYv5xlzO2/pBgVB4I/Dj/fmOec5LwHjRFGURqMhiiLP86ZpEhgAYwh7FB/7fjj8HDyCHcexLMu2bU3TEELEdCy1dHq7mMgskNeRk+xsKjHxuDGfPlsm86vn1EqSWrvIR8ib/IcAAJ1uV9d1wzACEYIR1bLcYSWNbeuV9iejtp8MlpZaBV6hBZkWlGJLfW7KimUDQK/Xs20bIRTCOzn64K60+ZRZf4/uFu6jD5U96pXrmADgh7LDBOLaKKZphnC8yCaZeqxE79fTx28vJFM9pMu8NhQb+P7vbwOAYRi6rluWFcKu5/Wh72DXcwHwWLsHYubocjK3NZXdnotfUdUmALie//eSQFsQBI7jarVaYE7Ipi0hTUK6avWRO/j/Kc/zMMZBf8Nfq6LsorLTvyMAAAAASUVORK5CYII='); background-size: cover; display: block;"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"picture","properties":{},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/ca600c1fe96166b67e6fe37b5f5dcc89/a0b58/11_3_1.webp 230w","/ohjelmointi-24-sv/static/ca600c1fe96166b67e6fe37b5f5dcc89/bc10c/11_3_1.webp 460w","/ohjelmointi-24-sv/static/ca600c1fe96166b67e6fe37b5f5dcc89/2e4ba/11_3_1.webp 777w"],"sizes":"(max-width: 777px) 100vw, 777px","type":"image/webp"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/ca600c1fe96166b67e6fe37b5f5dcc89/81c8e/11_3_1.png 230w","/ohjelmointi-24-sv/static/ca600c1fe96166b67e6fe37b5f5dcc89/08a84/11_3_1.png 460w","/ohjelmointi-24-sv/static/ca600c1fe96166b67e6fe37b5f5dcc89/108f8/11_3_1.png 777w"],"sizes":"(max-width: 777px) 100vw, 777px","type":"image/png"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"img","properties":{"className":["gatsby-resp-image-image"],"src":"/ohjelmointi-24-sv/static/ca600c1fe96166b67e6fe37b5f5dcc89/108f8/11_3_1.png","alt":"11 3 1","title":"11 3 1","loading":"lazy","decoding":"async","style":"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"},"children":[]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Här är en rekursiv algoritm för en binär sökning:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"binarsokning"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"list"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" foremal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" vanster "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" hoger "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","triple-quoted-string","string"]},"children":[{"type":"text","value":"\"\"\" Funktionen returnerar True ifall föremålet finns i listan, annars False \"\"\""}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Om sökfältet är tomt hittas inget föremål"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" vanster "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">"}]},{"type":"text","value":" hoger"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"False"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Kalkylerar mitten av sökområdet"}]},{"type":"text","value":"\n mitten "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"vanster"},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+"}]},{"type":"text","value":"hoger"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"//"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Ifall föremålet hittas i mitten"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"mitten"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" foremal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"True"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Ifall föremålet är större, sök andra halvan"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"mitten"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"<"}]},{"type":"text","value":" foremal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" binarsokning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" foremal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" mitten"},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" hoger"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Annars måste föremålet vara mindre, sök mindre halvan"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" binarsokning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" foremal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" vanster"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" mitten"},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Testar"}]},{"type":"text","value":"\n lista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"8"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"11"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"13"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"14"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"18"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"binarsokning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"binarsokning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"13"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"binarsokning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"6"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"binarsokning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"15"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"True\nTrue\nFalse\nFalse"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"binar_sokning"}]},{"type":"text","value":" tar fyra argument: mållistan, det objekt som söks samt vänster och höger kant på sökområdet. När funktionen anropas första gången täcker sökområdet hela mållistan. Den vänstra kanten ligger på index "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":" och den högra kanten ligger på index "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"len(lista)-1"}]},{"type":"text","value":". Funktionen beräknar det centrala indexet och kontrollerar den positionen på listan. Antingen har objektet hittats eller så fortsätter sökningen till den mindre eller större halvan av mållistan."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss jämföra detta med en enkel linjär sökning. Vid en linjär sökning är sökområdet från början och framåt, tills antingen objektet hittas eller sökområdet tar slut. Antalet steg som behövs för att täcka hela sökområdet växer linjärt i samma takt som sökområdets storlek. Varje söksteg täcker endast en sökkandidat från början av sökområdet. Låt oss anta att det sökta objektet inte hittas. Om sökområdet är en miljon objekt långt måste vi ta en miljon söksteg för att försäkra oss om att objektet inte finns i sökområdet."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Vid en binär sökning växer däremot antalet steg som behövs logaritmiskt. Låt oss återigen anta att det sökta objektet inte hittas. Sökområdet halveras för varje steg, eftersom vi vet att objektet antingen är mindre eller större än den aktuella sökkandidaten i mitten. 2 gånger 20 (2^20) är redan långt över 1 miljon, så det tar som mest 20 steg att täcka hela sökområdet med en binär sökning. När vi har att göra med sorterade sökområden, vilket ofta är fallet när vi har att göra med datorer och material som ska bearbetas automatiskt, är en binär sökning alltså mycket effektivare än en linjär sökning."}]}]},"html":"

    Efter den här delen

      \n
    • Vet du vad rekursion innebär
    • \n
    • Kommer du att kunna skriva en enkel rekursiv funktion
    • \n

    Som vi har sett många gånger tidigare kan funktioner anropa andra funktioner. Till exempel:

    def hej(namn : str):\n    print(\"Hejsan,\", namn)\n\ndef hej_flera(namn : str, ganger : int):\n    for i in range(ganger):\n        hej(namn)

    En funktion kan också anropa sig själv, men vi som programmerare måste vara försiktiga när vi gör det. Det är lätt att hamna i en oändlig loop av funktionsanrop, precis som vi hamnade i en oändlig loop av upprepningar med while-loopar om vi utelämnade lämpliga brytvillkor. Så om man försöker anropa en hej-funktion med följande definition

    def hej(namn : str):\n    print(\"Hejsan,\", namn)\n    hej(namn)

    skulle skapa ett nytt sort av fel:

    RecursionError: maximum recursion depth exceeded

    Vad betyder rekursion?

    Den rekursion som nämns i felet ovan innebär att man definierar något i termer av sig självt. I programmeringssammanhang handlar det oftast om en funktion som anropar sig själv. För att detta ska fungera utan att orsaka oändliga loopar måste de argument som skickas till funktionen ändras varje gång, så att de nästlade funktionsanropen slutar vid något skede. Grundprincipen här är densamma som i while-loopar: det måste alltid finnas ett stoppvillkor av något slag, och det villkoret måste utlösas vid någon tidpunkt i exekveringen.

    Låt oss ta en titt på en enkel funktion som lägger till nollor i en lista så länge det finns färre än 10 objekt i listan. Den här gången använder vi dock inte en loop. Om villkoret ännu inte är uppfyllt anropar funktionen sig själv

    def fyll_lista(tal: list):\n    \"\"\" Lägger till föremål till listan ifall listans längd är kortare än 10 \"\"\"\n    if len(tal) < 10:\n        tal.append(0)\n        # anropa funktionen igen\n        fyll_lista(tal)\n\n\nif __name__ == \"__main__\":\n    test = [1,2,3,4]\n    fyll_lista(test)\n    print(test)

    [1, 2, 3, 4, 0, 0, 0, 0, 0, 0]

    Denna funktionalitet kunde lika väl bli uppnådd genom en vanlig while-loop:

    \ndef fyll_lista(tal: list):\n    \"\"\" Lägger till föremål till listan ifall listans längd är kortare än 10 \"\"\"\n    while len(tal) < 10:\n        tal.append(0)\n\nif __name__ == \"__main__\":\n    test = [1,2,3,4]\n    fyll_lista(test)\n    print(test)\n

    Det mer traditionella iterativa tillvägagångssättet ger ett kortare program som förmodligen också är lättare att förstå. Med den rekursiva versionen är det inte lika tydligt att vi under hela processen arbetar med exakt samma lista. Så är det dock och därför fungerar den rekursiva funktionen lika bra.

    Inom datavetenskapsteori skiljer man ofta mellan iterativa och rekursiva algoritmer, så det är bäst att bekanta sig med dessa termer redan från början. Iterativa lösningar är sådana som baseras på sekventiell bearbetning av objekt, ofta med hjälp av loopar. Hittills har vi behandlat iterativa metoder ganska exklusivt. Rekursiv, å andra sidan, avser en metod där funktionen anropar sig själv med förändrade parametervärden.

    I princip borde det vara möjligt att lösa alla problem med antingen iterativa eller rekursiva metoder. I praktiken är det dock oftast så att den ena eller den andra metoden är klart bättre lämpad för varje problem. Förmågan att avgöra vilken som är bäst kommer till stor del med övning.

    Skapa en rekursiv funktion tal_till_listan(tal: list). Funktionen tar en lista med tal som sitt argument och lägger till nya tal i listan tills längden på listan är delbar med fem. Varje tal som läggs till i listan ska vara ett större tal än det sista talet i listan.

    Funktionen måste anropa sig själv rekursivt.

    Fxempel på funktionen i användning:

    tal = [1,3,4,5,10,11]\ntal_till_listan(tal)\nprint(tal)

    [1, 3, 4, 5, 10, 11, 12, 13, 14, 15]

    Rekursion och returvärden

    Rekursiva funktioner kan också ha returvärden. I de senaste avsnitten har vi arbetat med fakultettal, så låt oss skriva en rekursiv fakultetfunktion:

    \ndef fakultet(n: int):\n    \"\"\" Funktionen räknar ut fakulteten n! för n>= 0 \"\"\"\n    if n < 2:\n        # Fakulteten av 0 och 1 är 1\n        return 1\n\n    # anropa funktionen igen\n    return n * fakultet(n - 1)\n\nif __name__ == \"__main__\":\n    # Testar\n    for i in range(1, 7):\n        print(f\"Fakulteten av {i} är {fakultet(i)}\")\n

    Fakulteten av 1 är 1\nFakulteten av 2 är 2\nFakulteten av 3 är 6\nFakulteten av 4 är 24\nFakulteten av 5 är 120\nFakulteten av 6 är 720

    Om parametern för den rekursiva faktoriella funktionen är 0 eller 1, returnerar funktionen 1, eftersom det är så faktoriell operation definieras. I alla andra fall returnerar funktionen värdet n * fakultet(n - 1), vilket är värdet av dess parameter n multiplicerat med returvärdet av funktionsanropet fakultet(n - 1).

    Det avgörande här är att funktionsdefinitionen innehåller ett stoppvillkor. Om detta uppfylls avslutas rekursionen. I det här fallet är villkoret n < 2. Vi vet att det kommer att nås så småningom, eftersom det värde som skickas som argument till funktionen minskas med ett på varje nivå i rekursionen.

    Visualiseringsverktyget kan vara till stor hjälp när det gäller att förstå rekursiva program.

    Exemplet ovan skulle kanske bli lite tydligare om vi använde oss av hjälpvariabler:

    def fakultet(n: int):\n    if n < 2:\n        return 1\n\n    forra_talets_fakultet = fakultet(n - 1)\n    fakultet_nu = n * forra_talets_fakultet\n    return fakultet_nu\n\nfakultet(5)

    Ta en titt på hurvisualiseringsverktyget visar hur rekursionen fortskrider.

    Visualiseringsverktyget har en liten finess i hur det hanterar anropsstacken, eftersom den verkar \"växa\" nedåt. Vanligtvis avbildas anropsstaplar som just staplar, där de nya anropen placeras överst. I visualiseringsverktyget är det aktiva funktionsanropet det skuggade blocket längst ner, som har sina egna kopior av de variabler som syns.

    När den rekursiva faktorfunktionen anropas byggs anropsstapeln upp tills den gräns som utgörs av n < 2 nås. Då återkommer det sista funktionsanropet i stacken med ett värde - det är 1, eftersom n nu är mindre än 2. Detta återkomstvärde skickas till det föregående funktionsanropet i stacken, där det används för att beräkna det funktionsanropets återkomstvärde, och så vidare tillbaka ut ur stacken.

    Returvärdet för varje funktionsanrop lagras i hjälpvariabeln fakultet_nu. Gå igenom visualiseringen noggrant tills du förstår vad som händer i varje steg, och var särskilt uppmärksam på det värde som returneras i varje steg.

    \n \n \n \n \n \n \"11\n \n \n

    Låt oss ta en titt på ett annat vanligt rekursivt exempel: Fibonacci-talen. I en Fibonacci-sekvens är varje tal summan av de två föregående talen. De två första talen definieras här som 1 och 1, och sekvensen börjar då så här: 1, 1, 2, 3, 5, 8, 13, 21, 34.

    def fibonacci(n: int):\n    \"\"\" Funktionen returnerar det n:e talet i Fibonaccis talföljd \"\"\"\n\n    if n <= 2:\n        # de första två är ettor\n        return 1\n\n    # Alla andra tal blir summan av de två föregående talen\n    return fibonacci(n - 1) + fibonacci(n - 2)\n\n# Testar att allting fungerar\nif __name__ == \"__main__\":\n    for i in range(1, 11):\n        print(f\"Fibonaccis {i}. tal är {fibonacci(i)}\")

    Fibonaccis 1. tal är 1\nFibonaccis 2. tal är 1\nFibonaccis 3. tal är 2\nFibonaccis 4. tal är 3\nFibonaccis 5. tal är 5\nFibonaccis 6. tal är 8\nFibonaccis 7. tal är 13\nFibonaccis 8. tal är 21\nFibonaccis 9. tal är 34\nFibonaccis 10. tal är 55

    Den här gången är stoppvillkoret att parametern är mindre än eller lika med 2, eftersom hela sekvensen definieras från de två första siffrorna och framåt, och vi definierade de två första siffrorna som lika med 1.

    Hur fungerar då den här funktionen i praktiken?

    Om funktionen anropas med 1 eller 2 som argument returnerar den 1, vilket dikteras av villkoret n <= 2.

    Om argumentet är 3 eller större returnerar funktionen värdet av fibonacci(n - 1) + fibonacci(n - 2). Om argumentet är exakt 3 är detta värde lika med fibonacci(2) + fibonacci(1), och vi vet redan resultatet av båda dessa från föregående steg. 1 + 1 är lika med 2, som alltså är det tredje talet i Fibonacci-sekvensen.

    Om argumentet är 4 är returvärdet fibonacci(3) + fibonacci(2), som vi nu vet är 2 + 1, vilket är lika med 3.

    Om argumentet är 5 är returvärdet fibonacci(4) + fibonacci(3), vilket vi nu vet är 3 + 2, vilket är lika med 5.

    Och så vidare, och så vidare.

    Vi kan i varje steg verifiera att funktionen ger rätt resultat, vilket ofta är tillräckligt i grundläggande programmeringsuppgifter. Den formella verifierbarheten av algoritmer är ett ämne för mer avancerade kurser, till exempel Data Structures and Algorithms.

    Skapa en rekursiv funktion med namnet summa(tal: int), som räknar summan 1 + 2 + ... + tal. Funktionens mall är följande:

    def summa(tal: int):\n    # ifall talet är 1, finns det inget att tillägga\n    if tal <= 1:\n        return tal\n\n    # fyll i resten

    Några exempel:

    resultat = summa(3)\nprint(resultat)\n\nprint(summa(5))\nprint(summa(10))

    6\n15\n55

    I uppgiftsbotten finns den färdiga funtkionen balanserade_parenteser som tar en sträng som argument. Funktionen kollar ifall runda parenteser inom strängen är balanserade. Med andra ord, för varje öppnande parentes ( ska det finnas en stängande parentes ), och alla parenteser ska vara i matchande ordning, alltså får parentesparen inte korsas.

    def balanserade_parenteser(strang: str):\n    if len(strang) == 0:\n        return True\n    if not (strang[0] == '(' and strang[-1] == ')'):\n        return False\n\n    # ta bort första och sista tecknet\n    return balanserade_parenteser(strang[1:-1])\n\nok = balanserade_parenteser(\"(((())))\")\nprint(ok)\n\n# finns en parentes för mycket, alltså False\nok = balanserade_parenteser(\"()())\")\nprint(ok)\n\n# börjar med en stängande parentes, alltså False igen\nok = balanserade_parenteser(\")()\")\nprint(ok)\n\n# är inte giltig, eftersom funktionen bara kan hantera helt inkapslade parenteser\nok = balanserade_parenteser(\"()(())\")\nprint(ok)

    True\nFalse\nFalse\nFalse

    Utöka funktionen så att den även fungerar med hakparenteser []. Funktionen bör också ignorera alla tecken som inte är parenteser () eller []. De olika typerna av parenteser måste matchas korrekt i tur och ordning.

    Ett par exempel:

    ok = balanserade_parenteser(\"([([])])\")\nprint(ok)\n\nok = balanserade_parenteser(\"(python version [3.7]) använd denna!\")\nprint(ok)\n\n# felaktigt stängande parentes\nok = balanserade_parenteser(\"(()]\")\nprint(ok)\n\n\n# felaktiga matchningar av parenteser\nok = balanserade_parenteser(\"([dåligt)]\")\nprint(ok)

    Obs: Funktionen behöver endast hantera helt inkapslade parenteser. Strängen (x+1)(y+1) ska producera False, eftersom parenteserna inte är inkapslade inom varandra.

    True\nTrue\nFalse\nFalse

    Binär sökning

    I en binär sökning har vi en sorterad lista med objekt och vi försöker hitta ett visst objekt i den. Ordningen på objekten kan till exempel vara siffror från minst till störst, eller strängar från alfabetiskt först till sist. Sorteringsmetoden spelar ingen roll, så länge den är känd och relevant för det objekt som vi försöker hitta.

    Tanken med en binär sökning är att alltid titta på objektet i mitten av listan. Vi har då tre möjliga scenarier. Om objektet i mitten är

      \n
    • det vi letar efter: vi kan returnera en indikation på att vi hittade objektet
    • \n
    • mindre än det vi letar efter: vi kan göra om sökningen i den större halvan av listan
    • \n
    • större än den vi letar efter: vi kan göra om sökningen i den mindre halvan av listan.
    • \n

    Om listan är tom kan vi fastställa att objektet inte hittades och returnera en indikation på det.

    I följande bild kan vi se hur en binär sökning fortskrider när den letar efter talet 24:

    \n \n

    Efter den här delen

      \n
    • Vet du vad rekursion innebär
    • \n
    • Kommer du att kunna skriva en enkel rekursiv funktion
    • \n

    Som vi har sett många gånger tidigare kan funktioner anropa andra funktioner. Till exempel:

    def hej(namn : str):\n    print(\"Hejsan,\", namn)\n\ndef hej_flera(namn : str, ganger : int):\n    for i in range(ganger):\n        hej(namn)

    En funktion kan också anropa sig själv, men vi som programmerare måste vara försiktiga när vi gör det. Det är lätt att hamna i en oändlig loop av funktionsanrop, precis som vi hamnade i en oändlig loop av upprepningar med while-loopar om vi utelämnade lämpliga brytvillkor. Så om man försöker anropa en hej-funktion med följande definition

    def hej(namn : str):\n    print(\"Hejsan,\", namn)\n    hej(namn)

    skulle skapa ett nytt sort av fel:

    RecursionError: maximum recursion depth exceeded

    Vad betyder rekursion?

    Den rekursion som nämns i felet ovan innebär att man definierar något i termer av sig självt. I programmeringssammanhang handlar det oftast om en funktion som anropar sig själv. För att detta ska fungera utan att orsaka oändliga loopar måste de argument som skickas till funktionen ändras varje gång, så att de nästlade funktionsanropen slutar vid något skede. Grundprincipen här är densamma som i while-loopar: det måste alltid finnas ett stoppvillkor av något slag, och det villkoret måste utlösas vid någon tidpunkt i exekveringen.

    Låt oss ta en titt på en enkel funktion som lägger till nollor i en lista så länge det finns färre än 10 objekt i listan. Den här gången använder vi dock inte en loop. Om villkoret ännu inte är uppfyllt anropar funktionen sig själv

    def fyll_lista(tal: list):\n    \"\"\" Lägger till föremål till listan ifall listans längd är kortare än 10 \"\"\"\n    if len(tal) < 10:\n        tal.append(0)\n        # anropa funktionen igen\n        fyll_lista(tal)\n\n\nif __name__ == \"__main__\":\n    test = [1,2,3,4]\n    fyll_lista(test)\n    print(test)

    [1, 2, 3, 4, 0, 0, 0, 0, 0, 0]

    Denna funktionalitet kunde lika väl bli uppnådd genom en vanlig while-loop:

    \ndef fyll_lista(tal: list):\n    \"\"\" Lägger till föremål till listan ifall listans längd är kortare än 10 \"\"\"\n    while len(tal) < 10:\n        tal.append(0)\n\nif __name__ == \"__main__\":\n    test = [1,2,3,4]\n    fyll_lista(test)\n    print(test)\n

    Det mer traditionella iterativa tillvägagångssättet ger ett kortare program som förmodligen också är lättare att förstå. Med den rekursiva versionen är det inte lika tydligt att vi under hela processen arbetar med exakt samma lista. Så är det dock och därför fungerar den rekursiva funktionen lika bra.

    Inom datavetenskapsteori skiljer man ofta mellan iterativa och rekursiva algoritmer, så det är bäst att bekanta sig med dessa termer redan från början. Iterativa lösningar är sådana som baseras på sekventiell bearbetning av objekt, ofta med hjälp av loopar. Hittills har vi behandlat iterativa metoder ganska exklusivt. Rekursiv, å andra sidan, avser en metod där funktionen anropar sig själv med förändrade parametervärden.

    I princip borde det vara möjligt att lösa alla problem med antingen iterativa eller rekursiva metoder. I praktiken är det dock oftast så att den ena eller den andra metoden är klart bättre lämpad för varje problem. Förmågan att avgöra vilken som är bäst kommer till stor del med övning.

    Skapa en rekursiv funktion tal_till_listan(tal: list). Funktionen tar en lista med tal som sitt argument och lägger till nya tal i listan tills längden på listan är delbar med fem. Varje tal som läggs till i listan ska vara ett större tal än det sista talet i listan.

    Funktionen måste anropa sig själv rekursivt.

    Fxempel på funktionen i användning:

    tal = [1,3,4,5,10,11]\ntal_till_listan(tal)\nprint(tal)

    [1, 3, 4, 5, 10, 11, 12, 13, 14, 15]

    Rekursion och returvärden

    Rekursiva funktioner kan också ha returvärden. I de senaste avsnitten har vi arbetat med fakultettal, så låt oss skriva en rekursiv fakultetfunktion:

    \ndef fakultet(n: int):\n    \"\"\" Funktionen räknar ut fakulteten n! för n>= 0 \"\"\"\n    if n < 2:\n        # Fakulteten av 0 och 1 är 1\n        return 1\n\n    # anropa funktionen igen\n    return n * fakultet(n - 1)\n\nif __name__ == \"__main__\":\n    # Testar\n    for i in range(1, 7):\n        print(f\"Fakulteten av {i} är {fakultet(i)}\")\n

    Fakulteten av 1 är 1\nFakulteten av 2 är 2\nFakulteten av 3 är 6\nFakulteten av 4 är 24\nFakulteten av 5 är 120\nFakulteten av 6 är 720

    Om parametern för den rekursiva faktoriella funktionen är 0 eller 1, returnerar funktionen 1, eftersom det är så faktoriell operation definieras. I alla andra fall returnerar funktionen värdet n * fakultet(n - 1), vilket är värdet av dess parameter n multiplicerat med returvärdet av funktionsanropet fakultet(n - 1).

    Det avgörande här är att funktionsdefinitionen innehåller ett stoppvillkor. Om detta uppfylls avslutas rekursionen. I det här fallet är villkoret n < 2. Vi vet att det kommer att nås så småningom, eftersom det värde som skickas som argument till funktionen minskas med ett på varje nivå i rekursionen.

    Visualiseringsverktyget kan vara till stor hjälp när det gäller att förstå rekursiva program.

    Exemplet ovan skulle kanske bli lite tydligare om vi använde oss av hjälpvariabler:

    def fakultet(n: int):\n    if n < 2:\n        return 1\n\n    forra_talets_fakultet = fakultet(n - 1)\n    fakultet_nu = n * forra_talets_fakultet\n    return fakultet_nu\n\nfakultet(5)

    Ta en titt på hurvisualiseringsverktyget visar hur rekursionen fortskrider.

    Visualiseringsverktyget har en liten finess i hur det hanterar anropsstacken, eftersom den verkar \"växa\" nedåt. Vanligtvis avbildas anropsstaplar som just staplar, där de nya anropen placeras överst. I visualiseringsverktyget är det aktiva funktionsanropet det skuggade blocket längst ner, som har sina egna kopior av de variabler som syns.

    När den rekursiva faktorfunktionen anropas byggs anropsstapeln upp tills den gräns som utgörs av n < 2 nås. Då återkommer det sista funktionsanropet i stacken med ett värde - det är 1, eftersom n nu är mindre än 2. Detta återkomstvärde skickas till det föregående funktionsanropet i stacken, där det används för att beräkna det funktionsanropets återkomstvärde, och så vidare tillbaka ut ur stacken.

    Returvärdet för varje funktionsanrop lagras i hjälpvariabeln fakultet_nu. Gå igenom visualiseringen noggrant tills du förstår vad som händer i varje steg, och var särskilt uppmärksam på det värde som returneras i varje steg.

    \n \n \n \n \n \n \"11\n \n \n

    Låt oss ta en titt på ett annat vanligt rekursivt exempel: Fibonacci-talen. I en Fibonacci-sekvens är varje tal summan av de två föregående talen. De två första talen definieras här som 1 och 1, och sekvensen börjar då så här: 1, 1, 2, 3, 5, 8, 13, 21, 34.

    def fibonacci(n: int):\n    \"\"\" Funktionen returnerar det n:e talet i Fibonaccis talföljd \"\"\"\n\n    if n <= 2:\n        # de första två är ettor\n        return 1\n\n    # Alla andra tal blir summan av de två föregående talen\n    return fibonacci(n - 1) + fibonacci(n - 2)\n\n# Testar att allting fungerar\nif __name__ == \"__main__\":\n    for i in range(1, 11):\n        print(f\"Fibonaccis {i}. tal är {fibonacci(i)}\")

    Fibonaccis 1. tal är 1\nFibonaccis 2. tal är 1\nFibonaccis 3. tal är 2\nFibonaccis 4. tal är 3\nFibonaccis 5. tal är 5\nFibonaccis 6. tal är 8\nFibonaccis 7. tal är 13\nFibonaccis 8. tal är 21\nFibonaccis 9. tal är 34\nFibonaccis 10. tal är 55

    Den här gången är stoppvillkoret att parametern är mindre än eller lika med 2, eftersom hela sekvensen definieras från de två första siffrorna och framåt, och vi definierade de två första siffrorna som lika med 1.

    Hur fungerar då den här funktionen i praktiken?

    Om funktionen anropas med 1 eller 2 som argument returnerar den 1, vilket dikteras av villkoret n <= 2.

    Om argumentet är 3 eller större returnerar funktionen värdet av fibonacci(n - 1) + fibonacci(n - 2). Om argumentet är exakt 3 är detta värde lika med fibonacci(2) + fibonacci(1), och vi vet redan resultatet av båda dessa från föregående steg. 1 + 1 är lika med 2, som alltså är det tredje talet i Fibonacci-sekvensen.

    Om argumentet är 4 är returvärdet fibonacci(3) + fibonacci(2), som vi nu vet är 2 + 1, vilket är lika med 3.

    Om argumentet är 5 är returvärdet fibonacci(4) + fibonacci(3), vilket vi nu vet är 3 + 2, vilket är lika med 5.

    Och så vidare, och så vidare.

    Vi kan i varje steg verifiera att funktionen ger rätt resultat, vilket ofta är tillräckligt i grundläggande programmeringsuppgifter. Den formella verifierbarheten av algoritmer är ett ämne för mer avancerade kurser, till exempel Data Structures and Algorithms.

    Skapa en rekursiv funktion med namnet summa(tal: int), som räknar summan 1 + 2 + ... + tal. Funktionens mall är följande:

    def summa(tal: int):\n    # ifall talet är 1, finns det inget att tillägga\n    if tal <= 1:\n        return tal\n\n    # fyll i resten

    Några exempel:

    resultat = summa(3)\nprint(resultat)\n\nprint(summa(5))\nprint(summa(10))

    6\n15\n55

    I uppgiftsbotten finns den färdiga funtkionen balanserade_parenteser som tar en sträng som argument. Funktionen kollar ifall runda parenteser inom strängen är balanserade. Med andra ord, för varje öppnande parentes ( ska det finnas en stängande parentes ), och alla parenteser ska vara i matchande ordning, alltså får parentesparen inte korsas.

    def balanserade_parenteser(strang: str):\n    if len(strang) == 0:\n        return True\n    if not (strang[0] == '(' and strang[-1] == ')'):\n        return False\n\n    # ta bort första och sista tecknet\n    return balanserade_parenteser(strang[1:-1])\n\nok = balanserade_parenteser(\"(((())))\")\nprint(ok)\n\n# finns en parentes för mycket, alltså False\nok = balanserade_parenteser(\"()())\")\nprint(ok)\n\n# börjar med en stängande parentes, alltså False igen\nok = balanserade_parenteser(\")()\")\nprint(ok)\n\n# är inte giltig, eftersom funktionen bara kan hantera helt inkapslade parenteser\nok = balanserade_parenteser(\"()(())\")\nprint(ok)

    True\nFalse\nFalse\nFalse

    Utöka funktionen så att den även fungerar med hakparenteser []. Funktionen bör också ignorera alla tecken som inte är parenteser () eller []. De olika typerna av parenteser måste matchas korrekt i tur och ordning.

    Ett par exempel:

    ok = balanserade_parenteser(\"([([])])\")\nprint(ok)\n\nok = balanserade_parenteser(\"(python version [3.7]) använd denna!\")\nprint(ok)\n\n# felaktigt stängande parentes\nok = balanserade_parenteser(\"(()]\")\nprint(ok)\n\n\n# felaktiga matchningar av parenteser\nok = balanserade_parenteser(\"([dåligt)]\")\nprint(ok)

    Obs: Funktionen behöver endast hantera helt inkapslade parenteser. Strängen (x+1)(y+1) ska producera False, eftersom parenteserna inte är inkapslade inom varandra.

    True\nTrue\nFalse\nFalse

    Binär sökning

    I en binär sökning har vi en sorterad lista med objekt och vi försöker hitta ett visst objekt i den. Ordningen på objekten kan till exempel vara siffror från minst till störst, eller strängar från alfabetiskt först till sist. Sorteringsmetoden spelar ingen roll, så länge den är känd och relevant för det objekt som vi försöker hitta.

    Tanken med en binär sökning är att alltid titta på objektet i mitten av listan. Vi har då tre möjliga scenarier. Om objektet i mitten är

      \n
    • det vi letar efter: vi kan returnera en indikation på att vi hittade objektet
    • \n
    • mindre än det vi letar efter: vi kan göra om sökningen i den större halvan av listan
    • \n
    • större än den vi letar efter: vi kan göra om sökningen i den mindre halvan av listan.
    • \n

    Om listan är tom kan vi fastställa att objektet inte hittades och returnera en indikation på det.

    I följande bild kan vi se hur en binär sökning fortskrider när den letar efter talet 24:

    \n \n "}]},{"type":"text","value":" rot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" sok_nod"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hoger_barn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" sok_nod"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vanster_barn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Chefer och underordnade","tmcname":"osa11-17_chefer_och_underordnade"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Arbetare"}]},{"type":"text","value":" modellerar en arbetare på ett företag:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Arbetare"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"underordnade "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"tillsatt_underordnad"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" arbetare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'Arbetare'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"underordnade"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"arbetare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa funktionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"rakna_underordnade(arbetare: Arbetare)"}]},{"type":"text","value":", som rekursivt räknar mängden underordnade som en arbetare har."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Exempel på funktionen i användning:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n a1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Arbetare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Sussi\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n a2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Arbetare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Erik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n a3 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Arbetare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Matte\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n a4 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Arbetare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Emilia\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n a5 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Arbetare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Anton\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n a6 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Arbetare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Kjell\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_underordnad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a4"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_underordnad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a6"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n a4"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_underordnad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n a4"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_underordnad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a3"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n a4"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_underordnad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a5"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rakna_underordnade"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rakna_underordnade"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a4"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rakna_underordnade"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a5"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"5\n3\n0"}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"besok-till-tiden-innan-rekursion","style":"position:relative;"},"children":[{"type":"text","value":"Besök till tiden innan rekursion"},{"type":"element","tagName":"a","properties":{"href":"#besok-till-tiden-innan-rekursion","ariaLabel":"besok till tiden innan rekursion permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss avsluta denna del av materialet med en lite större övning som koncentrerar sig på objektorienterade programmeringsprinciper. Vi rekommenderar inte att du använder rekursion i denna serie av uppgifter, men tekniker för list comprehension kommer att vara användbara."}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Uppgiftsbok","tmcname":"osa11-18_uppgiftsbok"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I den här övningen kommer du skriva två olika klasser, vilka i sin tur kommer att vara ryggraden för övningen som följer denna, i vilken du kommer att skapa en interaktiv applikation."}]},{"type":"element","tagName":"h2","properties":{"id":"uppgift","style":"position:relative;"},"children":[{"type":"text","value":"Uppgift"},{"type":"element","tagName":"a","properties":{"href":"#uppgift","ariaLabel":"uppgift permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Förverkliga klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Uppgift"}]},{"type":"text","value":", som modellerar en uppgift i ett mjukvaruföretags lista av uppgifter. Uppgifterna har"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"en beskrivning"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"en beräkning av mängden timmar uppgiften tar"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"namnet på programmeraren som har fått uppgiften"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"ett fält som håller koll på ifall uppgiften är gjord"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"en unik id"}]},{"type":"text","value":"\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Klassen fungerar enligt följande:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"a1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Uppgift"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda hello world\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Erik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"id"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"beskrivning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"programmerare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"arbetsmangd"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"ar_fardig"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\na1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"markera_fardig"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"ar_fardig"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\na2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Uppgift"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda webbutik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Anton\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\na3 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Uppgift"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda mobilapp för räknande av arbetsmängd\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Erik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"25"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a3"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"1 koda hello world Erik 3\n1: koda hello world (3 timmar), programmerare Erik INTE FÄRDIG\nFalse\n1: koda hello world (3 timmar), programmerare Erik FÄRDIG\nTrue\n2: koda webbutik (10 timmar), programmerare Anton INTE FÄRDIG\n3: koda mobilapp för räknande av arbetsmängd (25 timmar), programmerare Erik INTE FÄRDIG"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Klarifikationer:"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"uppgiftens läge (färdig eller inte färdig) kan kollas med funktionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"ar_fardig(self)"}]},{"type":"text","value":", som returnerar ett booleskt värde"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"uppgiften är inte färdig när den skapas"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"uppgiften markeras som färdig genom att anropa på metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"markera_fardig(self)"}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"uppgifternas id är ett löpande nummer som börjar med 1. Id av första uppgiften är 1, andra uppgiften 2 osv."}]},{"type":"text","value":"\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Tips:"}]},{"type":"text","value":" id kan implementeras med en "},{"type":"element","tagName":"a","properties":{"href":"/ohjelmointi-24-sv/osa-9/5-staattiset-piirteet#luokkamuuttujat"},"children":[{"type":"text","value":"klassvariabel"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"h2","properties":{"id":"uppgiftsbok","style":"position:relative;"},"children":[{"type":"text","value":"Uppgiftsbok"},{"type":"element","tagName":"a","properties":{"href":"#uppgiftsbok","ariaLabel":"uppgiftsbok permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa nu en klass med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Uppgiftsbok"}]},{"type":"text","value":", som samlar ihop alla uppgifter som delegerats av mjukvaruföretaget. Uppgifterna ska modelleras med klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Uppgift"}]},{"type":"text","value":" som du just gjorde."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Basversionen av Uppgiftsboken används enligt följande:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"bestallningar "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Uppgiftsbok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda webbutik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Anton\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda mobilapp för räknande av arbetsmängd\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Erik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"25"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda app för övande av matematik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Anton\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"100"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" bestallning "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" bestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"alla_bestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" programmerare "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" bestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"kodare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"programmerare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"1: koda webbutik (10 timmar), programmerare Anton INTE FÄRDIG\n2: koda mobilapp för räknande av arbetsmängd (25 timmar), programmerare Erik INTE FÄRDIG\n3: koda app för övande av matematik (100 timmar), programmerare Anton INTE FÄRDIG"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Anton\nErik"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I detta skede borde din "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Uppgiftsbok"}]},{"type":"text","value":" erbjuda tre metoder:"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"tillsatt_bestallning(self, beskrivning, programmerare, arbetsmangd)"}]},{"type":"text","value":", som lägger till en ny uppgift till Uppgiftsboken. En Uppgiftsbok förvarar uppgifterna internt som "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Uppgift"}]},{"type":"text","value":"-objekt. OBS: metoden ska ta exakt de argument som nämns eller så fungerar inte de automatiserade testerna korrekt."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"alla_bestallningar(self)"}]},{"type":"text","value":" returnerar en lista på alla uppgifter som lagras i en Uppgiftsbok"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"kodare(self)"}]},{"type":"text","value":" returnerar en lista på namnen av alla kodare som har uppgifter lagrade i Uppgiftsboken. Listan ska innehålla varje programmerare endast en gång."}]},{"type":"text","value":"\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Tips:"}]},{"type":"text","value":" En enkel metod för att göra sig av med multipler är att ursprungligen hantera listan som en "},{"type":"element","tagName":"a","properties":{"href":"https://docs.python.org/3.8/library/stdtypes.html#set","target":"_blank","rel":["noopener","noreferrer"]},"children":[{"type":"text","value":"mängd"}]},{"type":"text","value":" (eng: set). En mängd är en samling av saker där varje unikt föremål endast förekommer en gång. En "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"set"}]},{"type":"text","value":" kan sedan konverteras tillbaks till en lista, och vi kan då vara säkra på att varje föremål nu är unikt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"lista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"6"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\nlista2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"list"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"set"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[1, 1, 3, 6, 4, 1, 3]\n[1, 3, 4, 6]"}]}]},{"type":"element","tagName":"h2","properties":{"id":"nagra-fler-funktioner-for-uppgiftsboken","style":"position:relative;"},"children":[{"type":"text","value":"Några fler funktioner för Uppgiftsboken"},{"type":"element","tagName":"a","properties":{"href":"#nagra-fler-funktioner-for-uppgiftsboken","ariaLabel":"nagra fler funktioner for uppgiftsboken permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa tre till metoder till din "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Uppgiftsbok"}]},{"type":"text","value":"-klass."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"markera_fardig(self, id: int)"}]},{"type":"text","value":" får som argument uppgiftens id och markerar den relevanta uppgiften som färdig:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"bestallningar "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Uppgiftsbok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda webbutik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Anton\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda mobilapp för räknande av arbetsmängd\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Erik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"25"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda app för övande av matematik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Anton\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"100"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"markera_fardig"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"markera_fardig"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" bestallning "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" bestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"alla_bestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"1: koda webbutik (10 timmar), programmerare Anton FÄRDIG\n2: koda mobilapp för räknande av arbetsmängd (25 timmar), programmerare Erik FÄRDIG\n3: koda app för övande av matematik (100 timmar), programmerare Anton INTE FÄRDIG"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ifall det inte finns någon uppgift med det givna id:t, ska metoden åstadkomma ett "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"ValueError"}]},{"type":"text","value":"-undantag. Ifall du behöver en påminnelse om att åstadkomma undantag kan du kolla in "},{"type":"element","tagName":"a","properties":{"href":"/ohjelmointi-24-sv/osa-6/3-virheet#poikkeusten-tuottaminen"},"children":[{"type":"text","value":"modul 6"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Metoderna "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"fardiga_bestallningar(self)"}]},{"type":"text","value":" och "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"ofardiga_bestallningar(self)"}]},{"type":"text","value":" fungerar som förväntat: båda returnerar en lista innehållande de relevanta uppgifterna från Uppgiftsboken."}]},{"type":"element","tagName":"h2","properties":{"id":"projektets-sista-detaljer","style":"position:relative;"},"children":[{"type":"text","value":"Projektets sista detaljer"},{"type":"element","tagName":"a","properties":{"href":"#projektets-sista-detaljer","ariaLabel":"projektets sista detaljer permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Vi skapar en sista metod "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"programmerarens_status(self, programmerare: str)"}]},{"type":"text","value":" till "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Uppgiftsbok"}]},{"type":"text","value":"-klassen, vilken returnar en "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"tupel"}]},{"type":"text","value":". Tupeln ska innehålla antalet färdiga och ofärdiga uppgifter en programmerare har tilldelats samt den uppskattade mängden timmar i båda kategorierna."}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"bestallningar "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Uppgiftsbok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda webbutik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Anton\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda mobilapp för räknande av arbetsmängd\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Anton\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"25"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda app för övande av matematik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Anton\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"100"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda nya facebook\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Erik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1000"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"markera_fardig"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"markera_fardig"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nstatus "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" bestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"programmerarens_status"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Anton\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"status"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"(2, 1, 35, 100)"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Det första föremålet i tupeln är antalet "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"färdiga"}]},{"type":"text","value":" uppgifter, medan det andra föremålet är antalet "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"ofärdiga"}]},{"type":"text","value":" uppgifter. Det tredje och fjärde föremålet är summan av uppskattningarna av arbetsmängden för de färdiga respektive ofärdiga uppgifterna."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ifall det inte finns någon programmerare med det angivna namnet, ska metoden åstadkomma ett "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"ValueError"}]},{"type":"text","value":"-undantag."}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Uppgiftsboksapplikation","tmcname":"osa11-19_uppgiftsboksapplikation"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I den här övningen ska du skapa en interaktiv applikation för att administrera de uppgifter som beställts från ett programvaruföretag. Implementeringen är helt upp till dig, men du kan använda byggstenarna från föregående övning i din applikation. Exemplen i "},{"type":"element","tagName":"a","properties":{"href":"/ohjelmointi-24-sv/osa-10/4-lisaa-esimerkkeja"},"children":[{"type":"text","value":"det sista avsnittet av modul 10"}]},{"type":"text","value":" kan också vara till hjälp."}]},{"type":"element","tagName":"h2","properties":{"id":"utan-felhantering","style":"position:relative;"},"children":[{"type":"text","value":"Utan felhantering"},{"type":"element","tagName":"a","properties":{"href":"#utan-felhantering","ariaLabel":"utan felhantering permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Applikationen ska fungera "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"exakt"}]},{"type":"text","value":" enligt följande:"}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktioner:\n0 avsluta\n1 tillsätt beställning\n2 lista färdiga\n3 lista ofärdiga\n4 markera uppgift färdig\n5 programmerare\n6 programmerarens status"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\nbeskrivning: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"koda nya facebook"}]},{"type":"text","value":"\nprogrammerare och uppskattad arbetsmängd: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"jonas 1000"}]},{"type":"text","value":"\ntillsatt!"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\nbeskrivning: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"koda mobilapp för räknande av arbetsmängd"}]},{"type":"text","value":"\nprogrammerare och uppskattad arbetsmängd: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"erik 25"}]},{"type":"text","value":"\ntillsatt!"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\nbeskrivning: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"program för att öva musikteori"}]},{"type":"text","value":"\nprogrammerare och uppskattad arbetsmängd: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"nina 12"}]},{"type":"text","value":"\ntillsatt!"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\nbeskrivning: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"koda nya twitter"}]},{"type":"text","value":"\nprogrammerare och uppskattad arbetsmängd: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"jonas 55"}]},{"type":"text","value":"\ntillsatt!"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"2"}]},{"type":"text","value":"\ninga färdiga uppgifter"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"3"}]},{"type":"text","value":"\n1: koda nya facebook (1000 timmar), programmerare jonas INTE FÄRDIG\n2: koda mobilapp för räknande av arbetsmängd (25 timmar), programmerare erik INTE FÄRDIG\n3: ohjelma musiikin teorian harjoitteluun (12 timmar), programmerare nina INTE FÄRDIG\n4: koda nya twitter (55 timmar), programmerare jonas INTE FÄRDIG"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"4"}]},{"type":"text","value":"\nid: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"2"}]},{"type":"text","value":"\nmarkerad som färdig"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"4"}]},{"type":"text","value":"\nid: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"4"}]},{"type":"text","value":"\nmarkerad som färdig"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"2"}]},{"type":"text","value":"\n2: koda mobilapp för räknande av arbetsmängd (25 timmar), programmerare erik FÄRDIG\n4: koda nya twitter (55 timmar), programmerare jonas FÄRDIG"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"3"}]},{"type":"text","value":"\n1: koda nya facebook (1000 timmar), programmerare jonas INTE FÄRDIG\n3: program för att öva musikteori (12 timmar), programmerare nina INTE FÄRDIG"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"5"}]},{"type":"text","value":"\njonas\nerik\nnina"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"6"}]},{"type":"text","value":"\nprogrammerare: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"jonas"}]},{"type":"text","value":"\nuppgifter: färdiga 2 ofärdiga 1, timmar: gjorda 55 ogjorda 1000"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Den första övningspoängen ges för en fungerande applikation när alla användarinmatningar är felfria."}]},{"type":"element","tagName":"h2","properties":{"id":"hantering-av-inamtningsfel","style":"position:relative;"},"children":[{"type":"text","value":"Hantering av inamtningsfel"},{"type":"element","tagName":"a","properties":{"href":"#hantering-av-inamtningsfel","ariaLabel":"hantering av inamtningsfel permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"För att få den andra övningspoängen för denna övning förväntas din applikation återhämta sig från felaktig användarinmatning. All inmatning som inte följer det angivna formatet ska ge ett felmeddelande "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"felaktig inmatning"}]},{"type":"text","value":" och resultera i ännu en upprepning av loopen med begäran om en ny instruktion:"}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\nbeskrivning: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"koda mobilapp för räknande av arbetsmängd"}]},{"type":"text","value":"\nprogrammerare och uppskattad arbetsmängd: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"erik xxx"}]},{"type":"text","value":"\nfelaktig inmatning"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\nbeskrivning: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"koda mobilapp för räknande av arbetsmängd"}]},{"type":"text","value":"\nprogrammerare och uppskattad arbetsmängd: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"erik"}]},{"type":"text","value":"\nfelaktig inmatning"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"4"}]},{"type":"text","value":"\nid: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"1000000"}]},{"type":"text","value":"\nfelaktig inmatning"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"4"}]},{"type":"text","value":"\nid: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"XXXX"}]},{"type":"text","value":"\nfelaktig inmatning"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"6"}]},{"type":"text","value":"\nprogrammerare: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"okändprogrammerare"}]},{"type":"text","value":"\nfelaktig inmatning"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Svara slutligen på en snabb enkät:"}]},{"type":"element","tagName":"div","properties":{},"children":[{"type":"element","tagName":"quiz","properties":{"id":"4acb2792-f51e-55f0-b482-addf1977c630"},"children":[]}]}]},"html":"

    Efter den här delen

      \n
    • Kommer du att känna till binära träd och några rekursiva algoritmer som används för att bearbeta dem
    • \n

    De verkliga fördelarna med rekursion blir uppenbara när vi stöter på problem där iterativa lösningar är svåra att skriva. Låt oss ta en titt på binära träd, till exempel. Ett binärt träd är en förgrenad struktur där vi har noder och vid varje nod förgrenar sig strukturen, som mest, i två underordnade grenar med egna noder. Ett binärt träd skulle då kunna se ut så här (datavetenskap betraktas ofta som en gren av naturvetenskapen, men vår förståelse av träd är lite upp och ner, som du kommer att märka):

    \n
    \n \n \n \n \n \"11\n \n \n

    Binära träd bör åtminstone teoretiskt sett vara lätta att hantera rekursivt: om vi vill utföra någon operation på varje nod i trädet behöver vår algoritm helt enkelt

      \n
    1. Behandla den aktuella noden
    2. \n
    3. Anropa sig själv på barnnoden till vänster
    4. \n
    5. Anropa sig själv på barnnoden till höger
    6. \n
    \n \n \n \n \n \n \"11\n \n \n

    Som du kan se på bilden ovan är både de vänstra och högra \"underträden\" fullfjädrade binära träd i sig, och den enda nod som lämnas utanför de rekursiva anropen är den överordnade noden, som bearbetas i steg 1 innan funktionen anropas rekursivt. På så sätt kan vi vara säkra på att varje nod har besökts exakt en gång när funktionen är klar.

    En iterativ version av en binär trädtraversering skulle vara mycket mer komplicerad, eftersom vi på något sätt skulle behöva hålla reda på alla noder som vi redan har besökt. Samma principer gäller för alla beräkningsbara trädstrukturer, inte bara binära.

    Ett binärt träd är också lätt att modellera i Python-kod. Vi behöver bara skriva en klassdefinition för en enda nod. Den har ett värdeattribut och attribut för de vänstra och högra underordnade noderna:

    \nclass Nod:\n    \"\"\" Klassen representerar en enkel nod i ett binärt träd \"\"\"\n    def __init__(self, varde, vanster_barn:'Nod' = None, hoger_barn:'Nod' = None):\n        self.varde = varde\n        self.vanster_barn = vanster_barn\n        self.hoger_barn = hoger_barn

    Låt oss anta att vi vill modellera följande träd:

    \n \n \n \n \n \n \"11\n \n \n

    Vi kunde uppnå detta med följande kod:

    if __name__ == \"__main__\":\n    trad = Nod(2)\n\n    trad.vanster_barn = Nod(3)\n    trad.vanster_barn.vanster_barn = Nod(5)\n    trad.vanster_barn.hoger_barn = Nod(8)\n\n    trad.hoger_barn = Nod(4)\n    trad.hoger_barn.hoger_barn = Nod(11)\n

    Algoritmer för rekursiva binära träd

    Låt oss först ta en titt på en algoritm som skriver ut alla noder i ett binärt träd en efter en. I de följande exemplen kommer vi att arbeta med det binära träd som definieras ovan.

    Argumentet till utskriftsfunktionen är rotnoden i det binära trädet. Detta är noden högst upp i vår illustration ovan. Alla andra noder är barn till den här noden:

    \ndef skriv_ut_noder(rot: Nod):\n    print(rot.varde)\n\n    if rot.vanster_barn is not None:\n        skriv_ut_noder(rot.vanster_barn)\n\n    if rot.hoger_barn is not None:\n        skriv_ut_noder(rot.hoger_barn)\n

    Funktionen skriver ut värdet på den nod som skickas som argument och anropar sedan sig själv på de vänstra och högra underordnade noderna, förutsatt att noderna är definierade. Det här är en mycket enkel algoritm, men den går på ett effektivt och tillförlitligt sätt igenom alla noder i trädet, oavsett trädets storlek. Avgörande är att ingen nod besöks två gånger. Varje värde skrivs bara ut en gång.

    Om vi skickar rotnoden trad i det binära trädet som illustreras ovan som ett argument till funktionen, skriver den ut

    2\n3\n5\n8\n4\n11

    Som du kan se av ordningen på noderna i utskriften rör sig algoritmen först längs trädets \"vänstra ben\" ner till botten, och därifrån går den igenom de andra noderna i ordning.

    På samma sätt kan vi skriva en algoritm för att beräkna summan av alla de värden som finns lagrade i trädets noder:

    \ndef nodernas_summa(rot: Nod):\n    summa = rot.varde\n\n    if rot.vanster_barn is not None:\n        summa += nodernas_summa(rot.vanster_barn)\n\n    if rot.hoger_barn is not None:\n        summa += nodernas_summa(rot.hoger_barn)\n\n    return summa\n

    Variabeln summa initieras till att vara lika med värdet för den aktuella noden. Värdet i variabeln ökas sedan genom rekursiva anrop till nodens summor i det vänstra och högra underordnade trädet (först kontrolleras naturligtvis att de finns). Detta resultat returneras sedan.

    Skapa funktionen storsta_nod(rot: Nod), som tar rotnoden av ett binärt träd som argument.

    Funktionen returnerar värdet på den nod som har det största värdet i trädet. Trädet ska genomkorsas rekursivt.

    Tips: funktionen nodernas_summa i exemplet ovan kan vara användbart.

    Exempel på hur funktionen ska fungera:

    \nif __name__ == \"__main__\":\n    trad = Nod(2)\n\n    trad.vanster_barn = Nod(3)\n    trad.vanster_barn.vanster_barn = Nod(5)\n    trad.vanster_barn.hoger_barn = Nod(8)\n\n    trad.hoger_barn = Nod(4)\n    trad.hoger_barn.hoger_barn = Nod(11)\n\n    print(storsta_nod(trad))\n

    11

    Sorterat binärt träd

    Ett binärt träd är särskilt användbart när noderna är sorterade på ett visst sätt. Det gör att det går snabbt och effektivt att hitta noder i trädet.

    Låt oss ta en titt på ett träd som är sorterat på följande sätt: det vänstra barnet till varje nod är mindre än själva noden och det högra barnet är på motsvarande sätt större.

    \n \n \n \n \n \n \"11\n \n \n

    Nu kan vi skriva en rekursiv algoritm för att söka efter noder. Idén är mycket lik den binära sökningen från föregående avsnitt: om den aktuella noden är den nod vi letar efter, returnera True. Annars fortsätter vi rekursivt med antingen det vänstra eller det högra underordnade trädet. Om noden inte är definierad returneras False.

    \ndef sok_nod(rot: Nod, varde):\n    if rot is None:\n        return False\n\n    if varde == rot.varde:\n        return True\n\n    if varde > rot.varde:\n        return sok_nod(rot.hoger_barn, varde)\n\n    return sok_nod(rot.vanster_barn, varde)\n

    Klassen Arbetare modellerar en arbetare på ett företag:

    class Arbetare:\n    def __init__(self, namn: str):\n        self.namn = namn\n        self.underordnade = []\n\n    def tillsatt_underordnad(self, arbetare: 'Arbetare'):\n        self.underordnade.append(arbetare)

    Skapa funktionen rakna_underordnade(arbetare: Arbetare), som rekursivt räknar mängden underordnade som en arbetare har.

    Exempel på funktionen i användning:

    if __name__ == \"__main__\":\n    a1 = Arbetare(\"Sussi\")\n    a2 = Arbetare(\"Erik\")\n    a3 = Arbetare(\"Matte\")\n    a4 = Arbetare(\"Emilia\")\n    a5 = Arbetare(\"Anton\")\n    a6 = Arbetare(\"Kjell\")\n    a1.tillsatt_underordnad(a4)\n    a1.tillsatt_underordnad(a6)\n    a4.tillsatt_underordnad(a2)\n    a4.tillsatt_underordnad(a3)\n    a4.tillsatt_underordnad(a5)\n    print(rakna_underordnade(a1))\n    print(rakna_underordnade(a4))\n    print(rakna_underordnade(a5))

    5\n3\n0

    Besök till tiden innan rekursion

    Låt oss avsluta denna del av materialet med en lite större övning som koncentrerar sig på objektorienterade programmeringsprinciper. Vi rekommenderar inte att du använder rekursion i denna serie av uppgifter, men tekniker för list comprehension kommer att vara användbara.

    I den här övningen kommer du skriva två olika klasser, vilka i sin tur kommer att vara ryggraden för övningen som följer denna, i vilken du kommer att skapa en interaktiv applikation.

    Uppgift

    Förverkliga klassen Uppgift, som modellerar en uppgift i ett mjukvaruföretags lista av uppgifter. Uppgifterna har

      \n
    • en beskrivning
    • \n
    • en beräkning av mängden timmar uppgiften tar
    • \n
    • namnet på programmeraren som har fått uppgiften
    • \n
    • ett fält som håller koll på ifall uppgiften är gjord
    • \n
    • en unik id
    • \n

    Klassen fungerar enligt följande:

    a1 = Uppgift(\"koda hello world\", \"Erik\", 3)\nprint(a1.id, a1.beskrivning, a1.programmerare, a1.arbetsmangd)\nprint(a1)\nprint(a1.ar_fardig())\na1.markera_fardig()\nprint(a1)\nprint(a1.ar_fardig())\na2 = Uppgift(\"koda webbutik\", \"Anton\", 10)\na3 = Uppgift(\"koda mobilapp för räknande av arbetsmängd\", \"Erik\", 25)\nprint(a2)\nprint(a3)

    1 koda hello world Erik 3\n1: koda hello world (3 timmar), programmerare Erik INTE FÄRDIG\nFalse\n1: koda hello world (3 timmar), programmerare Erik FÄRDIG\nTrue\n2: koda webbutik (10 timmar), programmerare Anton INTE FÄRDIG\n3: koda mobilapp för räknande av arbetsmängd (25 timmar), programmerare Erik INTE FÄRDIG

    Klarifikationer:

      \n
    • uppgiftens läge (färdig eller inte färdig) kan kollas med funktionen ar_fardig(self), som returnerar ett booleskt värde
    • \n
    • uppgiften är inte färdig när den skapas
    • \n
    • uppgiften markeras som färdig genom att anropa på metoden markera_fardig(self)
    • \n
    • uppgifternas id är ett löpande nummer som börjar med 1. Id av första uppgiften är 1, andra uppgiften 2 osv.
    • \n

    Tips: id kan implementeras med en klassvariabel.

    Uppgiftsbok

    Skapa nu en klass med namnet Uppgiftsbok, som samlar ihop alla uppgifter som delegerats av mjukvaruföretaget. Uppgifterna ska modelleras med klassen Uppgift som du just gjorde.

    Basversionen av Uppgiftsboken används enligt följande:

    bestallningar = Uppgiftsbok()\nbestallningar.tillsatt_bestallning(\"koda webbutik\", \"Anton\", 10)\nbestallningar.tillsatt_bestallning(\"koda mobilapp för räknande av arbetsmängd\", \"Erik\", 25)\nbestallningar.tillsatt_bestallning(\"koda app för övande av matematik\", \"Anton\", 100)\n\nfor bestallning in bestallningar.alla_bestallningar():\n    print(bestallning)\n\nprint()\n\nfor programmerare in bestallningar.kodare():\n    print(programmerare)

    1: koda webbutik (10 timmar), programmerare Anton INTE FÄRDIG\n2: koda mobilapp för räknande av arbetsmängd (25 timmar), programmerare Erik INTE FÄRDIG\n3: koda app för övande av matematik (100 timmar), programmerare Anton INTE FÄRDIG

    Anton\nErik

    I detta skede borde din Uppgiftsbok erbjuda tre metoder:

      \n
    • tillsatt_bestallning(self, beskrivning, programmerare, arbetsmangd), som lägger till en ny uppgift till Uppgiftsboken. En Uppgiftsbok förvarar uppgifterna internt som Uppgift-objekt. OBS: metoden ska ta exakt de argument som nämns eller så fungerar inte de automatiserade testerna korrekt.
    • \n
    • alla_bestallningar(self) returnerar en lista på alla uppgifter som lagras i en Uppgiftsbok
    • \n
    • kodare(self) returnerar en lista på namnen av alla kodare som har uppgifter lagrade i Uppgiftsboken. Listan ska innehålla varje programmerare endast en gång.
    • \n

    Tips: En enkel metod för att göra sig av med multipler är att ursprungligen hantera listan som en mängd (eng: set). En mängd är en samling av saker där varje unikt föremål endast förekommer en gång. En set kan sedan konverteras tillbaks till en lista, och vi kan då vara säkra på att varje föremål nu är unikt:

    lista = [1,1,3,6,4,1,3]\nlista2 = list(set(lista))\nprint(lista)\nprint(lista2)

    [1, 1, 3, 6, 4, 1, 3]\n[1, 3, 4, 6]

    Några fler funktioner för Uppgiftsboken

    Skapa tre till metoder till din Uppgiftsbok-klass.

    Metoden markera_fardig(self, id: int) får som argument uppgiftens id och markerar den relevanta uppgiften som färdig:

    bestallningar = Uppgiftsbok()\nbestallningar.tillsatt_bestallning(\"koda webbutik\", \"Anton\", 10)\nbestallningar.tillsatt_bestallning(\"koda mobilapp för räknande av arbetsmängd\", \"Erik\", 25)\nbestallningar.tillsatt_bestallning(\"koda app för övande av matematik\", \"Anton\", 100)\n\nbestallningar.markera_fardig(1)\nbestallningar.markera_fardig(2)\n\nfor bestallning in bestallningar.alla_bestallningar():\n    print(bestallning)

    1: koda webbutik (10 timmar), programmerare Anton FÄRDIG\n2: koda mobilapp för räknande av arbetsmängd (25 timmar), programmerare Erik FÄRDIG\n3: koda app för övande av matematik (100 timmar), programmerare Anton INTE FÄRDIG

    Ifall det inte finns någon uppgift med det givna id:t, ska metoden åstadkomma ett ValueError-undantag. Ifall du behöver en påminnelse om att åstadkomma undantag kan du kolla in modul 6.

    Metoderna fardiga_bestallningar(self) och ofardiga_bestallningar(self) fungerar som förväntat: båda returnerar en lista innehållande de relevanta uppgifterna från Uppgiftsboken.

    Projektets sista detaljer

    Vi skapar en sista metod programmerarens_status(self, programmerare: str) till Uppgiftsbok-klassen, vilken returnar en tupel. Tupeln ska innehålla antalet färdiga och ofärdiga uppgifter en programmerare har tilldelats samt den uppskattade mängden timmar i båda kategorierna.

    bestallningar = Uppgiftsbok()\nbestallningar.tillsatt_bestallning(\"koda webbutik\", \"Anton\", 10)\nbestallningar.tillsatt_bestallning(\"koda mobilapp för räknande av arbetsmängd\", \"Anton\", 25)\nbestallningar.tillsatt_bestallning(\"koda app för övande av matematik\", \"Anton\", 100)\nbestallningar.tillsatt_bestallning(\"koda nya facebook\", \"Erik\", 1000)\n\nbestallningar.markera_fardig(1)\nbestallningar.markera_fardig(2)\n\nstatus = bestallningar.programmerarens_status(\"Anton\")\nprint(status)

    (2, 1, 35, 100)

    Det första föremålet i tupeln är antalet färdiga uppgifter, medan det andra föremålet är antalet ofärdiga uppgifter. Det tredje och fjärde föremålet är summan av uppskattningarna av arbetsmängden för de färdiga respektive ofärdiga uppgifterna.

    Ifall det inte finns någon programmerare med det angivna namnet, ska metoden åstadkomma ett ValueError-undantag.

    I den här övningen ska du skapa en interaktiv applikation för att administrera de uppgifter som beställts från ett programvaruföretag. Implementeringen är helt upp till dig, men du kan använda byggstenarna från föregående övning i din applikation. Exemplen i det sista avsnittet av modul 10 kan också vara till hjälp.

    Utan felhantering

    Applikationen ska fungera exakt enligt följande:

    instruktioner:\n0 avsluta\n1 tillsätt beställning\n2 lista färdiga\n3 lista ofärdiga\n4 markera uppgift färdig\n5 programmerare\n6 programmerarens status

    instruktion: 1\nbeskrivning: koda nya facebook\nprogrammerare och uppskattad arbetsmängd: jonas 1000\ntillsatt!

    instruktion: 1\nbeskrivning: koda mobilapp för räknande av arbetsmängd\nprogrammerare och uppskattad arbetsmängd: erik 25\ntillsatt!

    instruktion: 1\nbeskrivning: program för att öva musikteori\nprogrammerare och uppskattad arbetsmängd: nina 12\ntillsatt!

    instruktion: 1\nbeskrivning: koda nya twitter\nprogrammerare och uppskattad arbetsmängd: jonas 55\ntillsatt!

    instruktion: 2\ninga färdiga uppgifter

    instruktion: 3\n1: koda nya facebook (1000 timmar), programmerare jonas INTE FÄRDIG\n2: koda mobilapp för räknande av arbetsmängd (25 timmar), programmerare erik INTE FÄRDIG\n3: ohjelma musiikin teorian harjoitteluun (12 timmar), programmerare nina INTE FÄRDIG\n4: koda nya twitter (55 timmar), programmerare jonas INTE FÄRDIG

    instruktion: 4\nid: 2\nmarkerad som färdig

    instruktion: 4\nid: 4\nmarkerad som färdig

    instruktion: 2\n2: koda mobilapp för räknande av arbetsmängd (25 timmar), programmerare erik FÄRDIG\n4: koda nya twitter (55 timmar), programmerare jonas FÄRDIG

    instruktion: 3\n1: koda nya facebook (1000 timmar), programmerare jonas INTE FÄRDIG\n3: program för att öva musikteori (12 timmar), programmerare nina INTE FÄRDIG

    instruktion: 5\njonas\nerik\nnina

    instruktion: 6\nprogrammerare: jonas\nuppgifter: färdiga 2 ofärdiga 1, timmar: gjorda 55 ogjorda 1000

    Den första övningspoängen ges för en fungerande applikation när alla användarinmatningar är felfria.

    Hantering av inamtningsfel

    För att få den andra övningspoängen för denna övning förväntas din applikation återhämta sig från felaktig användarinmatning. All inmatning som inte följer det angivna formatet ska ge ett felmeddelande felaktig inmatning och resultera i ännu en upprepning av loopen med begäran om en ny instruktion:

    instruktion: 1\nbeskrivning: koda mobilapp för räknande av arbetsmängd\nprogrammerare och uppskattad arbetsmängd: erik xxx\nfelaktig inmatning

    instruktion: 1\nbeskrivning: koda mobilapp för räknande av arbetsmängd\nprogrammerare och uppskattad arbetsmängd: erik\nfelaktig inmatning

    instruktion: 4\nid: 1000000\nfelaktig inmatning

    instruktion: 4\nid: XXXX\nfelaktig inmatning

    instruktion: 6\nprogrammerare: okändprogrammerare\nfelaktig inmatning

    Svara slutligen på en snabb enkät:

    ","frontmatter":{"path":"/osa-11/4-lisaa-esimerkkeja","title":"Fler exempel på rekursion"},"fileAbsolutePath":"/home/runner/work/ohjelmointi-24-sv/ohjelmointi-24-sv/data/osa-11/4-fler-exempel-pa-rekursion.md"},"allPages":{"edges":[{"node":{"id":"b5e8ae41-d492-55f7-88a7-1c7292333ab1","frontmatter":{"path":"/arvostelu-ja-kokeet","title":"Arvostelu ja kokeet"}}},{"node":{"id":"af4df6be-211d-5ba1-acea-9edbefa06c49","frontmatter":{"path":"/frontmatter-guide","title":"Frontmatter-guide"}}},{"node":{"id":"56769133-4836-5fbb-a857-8fb0c6803e6d","frontmatter":{"path":"/","title":"Tietoa kurssista"}}},{"node":{"id":"e86762f0-c2a9-5598-aba3-2b8d7db7807c","frontmatter":{"path":"/kaikki-tehtavat","title":"Kaikki tehtävät"}}},{"node":{"id":"5d065309-85e8-5823-9527-ec1c3cf38d4d","frontmatter":{"path":"/tuki","title":"Tukea tehtäviin"}}},{"node":{"id":"ac195ee0-ad04-5cc9-9643-963f93d29ad2","frontmatter":{"path":"/usein-kysytyt-kysymykset","title":"Usein kysytyt kysymykset"}}},{"node":{"id":"51a165d7-8ce5-5d53-9c15-5321b6adef8c","frontmatter":{"path":"/verkkotentti","title":"Verkkotentti 4.6."}}},{"node":{"id":"4d9cf293-01e9-5e6c-a88f-599560e33c9a","frontmatter":{"path":"/verkkotentti-ohja","title":"Ohjelmoinnin jatkokurssin verkkotentti 16.12."}}},{"node":{"id":"279e1cca-fb0b-5d3f-b527-be05243d138d","frontmatter":{"path":"/verkkotentti-ohpe","title":"Ohjelmoinnin perusteiden verkkotentti 09.03."}}},{"node":{"id":"347bdde4-ba21-5f22-8a88-0287dfe29a45","frontmatter":{"path":"/virheilmoitukset","title":"Yleiset virheilmoitukset"}}},{"node":{"id":"3bf12e3a-1542-57f4-812d-dd32cebc99e2","frontmatter":{"path":"/sanasto","title":"Sanasto"}}},{"node":{"id":"9910673b-d62d-5d8d-a756-5267160d891f","frontmatter":{"path":"/osa-1/1-introduktion","title":"Introduktion"}}},{"node":{"id":"0b17a28e-f939-57cc-aa5b-4db407cdf34a","frontmatter":{"path":"/osa-1/2-info-fran-anvandaren","title":"Information från användaren"}}},{"node":{"id":"b95794f2-f3b3-597c-a4ec-6f023b584f81","frontmatter":{"path":"/osa-1/3-mer-om-variabler","title":"Mer om variabler"}}},{"node":{"id":"02cd0849-e7a5-5fd1-bf66-35f0197d3e75","frontmatter":{"path":"/osa-1/4-rakneoperationer","title":"Räkneoperationer"}}},{"node":{"id":"42690a69-3997-5b84-b999-15d9c3212884","frontmatter":{"path":"/osa-1/5-villkorssatser","title":"If-satser"}}},{"node":{"id":"96a0ec65-c0a3-5150-95c5-48c260f88162","frontmatter":{"path":"/osa-1","title":"Modul 1"}}},{"node":{"id":"e7a4d0c8-b8c1-53fa-ab51-9cc06fd417a3","frontmatter":{"path":"/osa-10/1-klasshierarkier","title":"Klasshierarkier"}}},{"node":{"id":"5f6d4b8b-7d05-5c79-9f2f-9e30b397167b","frontmatter":{"path":"/osa-10/2-atkamstmodifierare","title":"Åtkomstmodifierare"}}},{"node":{"id":"bb896c90-aabc-5a9d-8d4b-50839da286db","frontmatter":{"path":"/osa-10/3-objektorienterade-programmeringstekniker","title":"Objektorienterade programmeringstekniker"}}},{"node":{"id":"a2dca4f1-d64d-5e77-a3ca-8b2a208e9afa","frontmatter":{"path":"/osa-10/4-storre-applikation","title":"Att utveckla en större applikation"}}},{"node":{"id":"8c9cf5a7-f02e-5ccf-ab8f-f078c3ccecb6","frontmatter":{"path":"/osa-10","title":"Modul 10"}}},{"node":{"id":"f6688d26-5502-5c17-a8ee-db66f650f1f1","frontmatter":{"path":"/osa-11/1-list-comprehension","title":"List comprehension"}}},{"node":{"id":"1eac8489-72f2-5d53-904b-c960e2622018","frontmatter":{"path":"/osa-11/2-mer-om-comprehensions","title":"Mer om comprehensions"}}},{"node":{"id":"09630fca-7768-53f3-8aca-6e5ac638fc68","frontmatter":{"path":"/osa-11/3-rekursion","title":"Rekursion"}}},{"node":{"id":"70f6008e-a762-574c-a92a-c5c585d9677e","frontmatter":{"path":"/osa-11/4-lisaa-esimerkkeja","title":"Fler exempel på rekursion"}}},{"node":{"id":"eb8ed7d7-c39d-52db-949d-f75649498c67","frontmatter":{"path":"/osa-11","title":"Modul 11"}}},{"node":{"id":"9bba31dc-e14c-5400-a25b-7339107e9ba7","frontmatter":{"path":"/osa-12/1-funktioner-som-argument","title":"Funktioner som argument"}}},{"node":{"id":"5b9e4584-7234-5216-a118-d2a1bc617e13","frontmatter":{"path":"/osa-12/2-generatorer","title":"Generatorer"}}},{"node":{"id":"1d27636e-74f4-5c30-a1d8-08a303684945","frontmatter":{"path":"/osa-12/3-funktionell-programmering","title":"Funktionell programmering"}}},{"node":{"id":"6785750f-f145-5b88-81e9-b52e36ba53c6","frontmatter":{"path":"/osa-12/4-reguljara-uttryck","title":"Reguljära uttryck"}}},{"node":{"id":"d21df33a-4bf4-5ee3-9e2a-431d57561f09","frontmatter":{"path":"/osa-12","title":"Modul 12"}}},{"node":{"id":"14e3c129-50ec-581f-8679-8132248d41c1","frontmatter":{"path":"/osa-13/1-pygame","title":"Pygame"}}},{"node":{"id":"01bc3b9b-4f80-5561-8b56-3a7f09082263","frontmatter":{"path":"/osa-13/2-animation","title":"Animation"}}},{"node":{"id":"dd68786f-e2fc-5957-b47a-52b74c5199ef","frontmatter":{"path":"/osa-13/3-handelser","title":"Händelser"}}},{"node":{"id":"4a1aaa41-d6f7-51cd-8b89-95842cb9e02d","frontmatter":{"path":"/osa-13/4-fler-pygame-tekniker","title":"Fler pygame-tekniker"}}},{"node":{"id":"cdcf0ce1-e881-5ca6-8fa9-d0d343ec4e15","frontmatter":{"path":"/osa-13","title":"Modul 13"}}},{"node":{"id":"0ab28435-7654-5a8e-88d6-daa17d78103b","frontmatter":{"path":"/osa-14/1-spelprojekt","title":"Spelprojekt"}}},{"node":{"id":"b7a0628c-e4ba-583e-a52a-dd0ad78028d8","frontmatter":{"path":"/osa-14/2-robot-och-ladar","title":"Robot och lådor"}}},{"node":{"id":"6ccdbdff-7539-5a23-b23c-2ad48a99386f","frontmatter":{"path":"/osa-14/3-fardigstallande-av-spelet","title":"Färdigställande av spelet"}}},{"node":{"id":"1b505c9f-9b1b-58bd-8df7-553fef49cc8d","frontmatter":{"path":"/osa-14/4-ditt-eget-sepl","title":"Ditt eget spel"}}},{"node":{"id":"55c54859-8c7f-5fd9-8a8d-2c54ee677577","frontmatter":{"path":"/osa-14","title":"Modul 14"}}},{"node":{"id":"b5c346d1-d175-5824-98bb-4a4c3b45204d","frontmatter":{"path":"/osa-2/1-terminologi","title":"Programmeringsterminologi"}}},{"node":{"id":"db7188b0-0253-5c30-b8d2-0e115e235fb3","frontmatter":{"path":"/osa-2/2-else-elif","title":"Mera om if-satser"}}},{"node":{"id":"49d15928-f8b9-5883-9f29-86c307f6929e","frontmatter":{"path":"/osa-2/3-kombinera-villkor","title":"Kombinera villkor"}}},{"node":{"id":"93f1f9c8-6b27-5892-8bd4-7d1d008bf07a","frontmatter":{"path":"/osa-2/4-loopar","title":"Enkla loopar"}}},{"node":{"id":"5523b5b8-61f8-506d-bfe0-c6cc774390ce","frontmatter":{"path":"/osa-2","title":"Modul 2"}}},{"node":{"id":"02012307-c2a6-5cf2-9105-c10933c14b37","frontmatter":{"path":"/osa-3/1-loopar-med-villkor","title":"Loopar med villkor"}}},{"node":{"id":"efb889f4-4a19-515e-a0f6-4297d76a2757","frontmatter":{"path":"/osa-3/2-behandla-strangar","title":"Behandla strängar"}}},{"node":{"id":"a602077d-bbae-5eb7-a354-cc44b29ae96a","frontmatter":{"path":"/osa-3/3-mer-om-loopar","title":"Mera om loopar"}}},{"node":{"id":"6d878692-b9c7-57e6-ae58-044e5a6bef6f","frontmatter":{"path":"/osa-3/4-definiera-funktioner","title":"Definiera funktioner"}}},{"node":{"id":"682b5a18-73c5-56e2-8374-237baccbab40","frontmatter":{"path":"/osa-3","title":"Modul 3"}}},{"node":{"id":"3de95518-6b44-54db-9bcd-0c90a41d2fd5","frontmatter":{"path":"/osa-4/1-vscode","title":"Editorn Visual Studio Code, Pythontolken och det inbyggda debuggningsverktyget"}}},{"node":{"id":"7de9921c-7f94-58fe-84b9-7676dddb3b94","frontmatter":{"path":"/osa-4/2-mer-om-funktioner","title":"Mer om funktioner"}}},{"node":{"id":"29e29c69-360c-5f5c-8f34-5aef22eb327f","frontmatter":{"path":"/osa-4/3-listor","title":"Listor"}}},{"node":{"id":"bfe57880-0cbb-54e4-be9c-8fa180eafe6b","frontmatter":{"path":"/osa-4/4-iteration","title":"Iteration"}}},{"node":{"id":"2eab46f0-5373-5cbe-b2a0-1d071854a053","frontmatter":{"path":"/osa-4/5-utskrift","title":"Formatera utskrift"}}},{"node":{"id":"a5974fee-f2eb-5b89-88a5-6dd3754baaad","frontmatter":{"path":"/osa-4/6-strangar-listor","title":"Mera strängar och listor"}}},{"node":{"id":"e125c469-ee19-505e-9a41-83da6143ecd8","frontmatter":{"path":"/osa-4","title":"Modul 4"}}},{"node":{"id":"2558444a-be1d-5bc6-95ab-e091da2443fc","frontmatter":{"path":"/osa-5/1-mer-om-listor","title":"Mer om listor"}}},{"node":{"id":"b452d9be-0569-56c2-ba89-a040d4cb40dc","frontmatter":{"path":"/osa-5/2-referenser","title":"Referenser"}}},{"node":{"id":"ebe4ca3f-e657-5907-bfcc-ae84d9947aff","frontmatter":{"path":"/osa-5/3-lexikon","title":"Lexikon"}}},{"node":{"id":"f1dd5d66-ac87-5e53-92a0-0b7e3ece6ed8","frontmatter":{"path":"/osa-5/4-tuple","title":"Tuple"}}},{"node":{"id":"161c0109-5c00-5bed-b7af-90dc7ddf5713","frontmatter":{"path":"/osa-5","title":"Modul 5"}}},{"node":{"id":"e6cfa6e1-e99b-50e0-bc6a-3c0f153420e8","frontmatter":{"path":"/osa-6/1-lasa-filer","title":"Läsa filer"}}},{"node":{"id":"ce8d90a4-ca7c-5797-abc1-3fe0094bfa4b","frontmatter":{"path":"/osa-6/2-skriva-filer","title":"Skriva filer"}}},{"node":{"id":"519d5330-277a-59ba-be50-c2f63080df94","frontmatter":{"path":"/osa-6/3-fel","title":"Förbered dig på fel"}}},{"node":{"id":"82393756-3ef8-5d07-a8da-fed818ca43f0","frontmatter":{"path":"/osa-6/4-lokala-globala-variabler","title":"Lokala och globala variabler"}}},{"node":{"id":"007d85ae-a118-5b10-8a7e-18302b15eba8","frontmatter":{"path":"/osa-6","title":"Modul 6"}}},{"node":{"id":"bbb2346d-b1ee-551d-89c1-516f119b0eed","frontmatter":{"path":"/osa-7/1-moduler","title":"Moduler"}}},{"node":{"id":"ecb9af64-49f9-5e28-a544-3934e95233cf","frontmatter":{"path":"/osa-7/2-slumpmassighet","title":"Slumpmässighet"}}},{"node":{"id":"ebe469ef-c486-523a-9621-5dc4040c5cd8","frontmatter":{"path":"/osa-7/3-tid-datum","title":"Tid och datum"}}},{"node":{"id":"b9cf2d99-08f6-5de5-8425-c9b483241567","frontmatter":{"path":"/osa-7/4-behandla-data","title":"Behandla data"}}},{"node":{"id":"27075b37-8a6a-5554-9079-465a36d2da2d","frontmatter":{"path":"/osa-7/5-egna-moduler","title":"Skapa dina egna moduler"}}},{"node":{"id":"69492225-4d69-59ea-b33d-5301d35cf4ed","frontmatter":{"path":"/osa-7/6-funktionaliteter-python","title":"Flera funktionaliteter i Python"}}},{"node":{"id":"70ae841a-e6e9-5252-afae-6329fb67bcad","frontmatter":{"path":"/osa-7","title":"Modul 7"}}},{"node":{"id":"4afc4486-3cfe-53d1-b4c0-6db26484acfa","frontmatter":{"path":"/osa-8/1-objekt-och-metoder","title":"Objekt och metoder"}}},{"node":{"id":"6be37772-e94b-5b36-8a02-fffa7eef9feb","frontmatter":{"path":"/osa-8/2-klasser-och-objekt","title":"Klasser och objekt"}}},{"node":{"id":"8b6aec39-f8b9-525c-9f25-d8e73389fa42","frontmatter":{"path":"/osa-8/3-egna-klasser","title":"Egna klasser"}}},{"node":{"id":"85db460a-77c6-5087-8e97-a3c772186fd9","frontmatter":{"path":"/osa-8/4-metoder-i-egna-klasser","title":"Metoder i egna klasser"}}},{"node":{"id":"0e59dee0-5dd9-5827-83b9-a55e7d585c31","frontmatter":{"path":"/osa-8/5-fler-exempel","title":"Fler exempel"}}},{"node":{"id":"64715d0c-54f1-5aa7-a566-d2c5be6523ea","frontmatter":{"path":"/osa-8","title":"Modul 8"}}},{"node":{"id":"f7457509-a9a6-5420-8d03-ff1c61df8dc4","frontmatter":{"path":"/osa-9/1-objekt-och-referenser","title":"Objekt och referenser"}}},{"node":{"id":"16689ce4-b6aa-5bc4-9a30-44820994d6ea","frontmatter":{"path":"/osa-9/2-objekt-som-attribut","title":"Objekt som attribut "}}},{"node":{"id":"07985959-e85a-5f45-8923-babacb943c04","frontmatter":{"path":"/osa-9/3-inkapsling","title":"Inkapsling"}}},{"node":{"id":"83108600-9a37-5fd1-9a2b-13492879a9d6","frontmatter":{"path":"/osa-9/4-metodernas-rackvidd","title":"Metodernas räckvidd"}}},{"node":{"id":"a553cdc9-d6ac-5a14-ab43-d44811b407a2","frontmatter":{"path":"/osa-9/5-klassattribut","title":"Klassattribut"}}},{"node":{"id":"f7d7c9f1-6b54-5268-a308-995d49dd913d","frontmatter":{"path":"/osa-9/6-fler-exempel-med-klasser","title":"Fler exempel med klasser"}}},{"node":{"id":"c1fef3f7-8ca3-5780-9dec-19bd672b4627","frontmatter":{"path":"/osa-9","title":"Modul 9"}}}]}},"pageContext":{}}, + "result": {"data":{"page":{"htmlAst":{"type":"element","tagName":"div","properties":{},"children":[{"type":"element","tagName":"text-box","properties":{"variant":"learningObjectives","name":"Inlärningsmål"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Efter den här delen"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Kommer du att känna till binära träd och några rekursiva algoritmer som används för att bearbeta dem"}]},{"type":"text","value":"\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"De verkliga fördelarna med rekursion blir uppenbara när vi stöter på problem där iterativa lösningar är svåra att skriva. Låt oss ta en titt på binära träd, till exempel. Ett binärt träd är en förgrenad struktur där vi har noder och vid varje nod förgrenar sig strukturen, som mest, i två underordnade grenar med egna noder. Ett binärt träd skulle då kunna se ut så här (datavetenskap betraktas ofta som en gren av naturvetenskapen, men vår förståelse av träd är lite upp och ner, som du kommer att märka):"}]},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-wrapper"],"style":"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 307px; margin-bottom: 1rem;"},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"a","properties":{"className":["gatsby-resp-image-link"],"href":"/ohjelmointi-24-sv/static/42ada93f7fad74a8205a13a46dc4de57/4651d/11_4_1.png","style":"display: block","target":"_blank","rel":["noopener"]},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-background-image"],"style":"padding-bottom: 78.69565217391303%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAAAsTAAALEwEAmpwYAAABsElEQVQ4y3WU54rDQAyE/f5PlUD+JIT03ntvpHcdn0C+9Z5PYFxWO5rRaB2IF9/vV++fz0fa7bZ0u13pdDryer3CdcuJi8AHs+Tr9apgAHHn3c35DzRwF7nDjHg8HpJOp6XX60k2m5XNZhMy53L3uOCBL9WiXq/L7XYL35E9n89j2xMBdCvsdjsZDodSLBb12RhZjEYjLTQYDMJ1n0hgH5CICSQ2m82QnVvwcrlIo9GQ9XqtuX5fI4DP51Oq1arKqlQqcr/f/ySfz2ft6Ww2k1KppCR8o0JAAABarVZSq9UiJrjSDoeDFiWHZz8nMMfoC5IskH08Hv9tvhnnylbJzBjMuKyaycec7XYbC0qP2VMul2W/3/8yHI/HcjqddCwslsulOkrPYOqfIGI6ncpkMtFcJiMEZAPOsWiBjFwup98xIO6EULBQKChL1IRjgzy3d7BCZr/fD110Gb7fbzUFtynMflhikjJ0mwx1zMlkMhHn/PPNyCDZgsngG2uBm9xqtfQZdq7DlgMI7DDEcm0iMAaWkaNHhUQioQlxhx8gfhSpVEpPi8VisZBkMin5fF5+ALPgzivet7o7AAAAAElFTkSuQmCC'); background-size: cover; display: block;"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"picture","properties":{},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/42ada93f7fad74a8205a13a46dc4de57/a0b58/11_4_1.webp 230w","/ohjelmointi-24-sv/static/42ada93f7fad74a8205a13a46dc4de57/b1a97/11_4_1.webp 307w"],"sizes":"(max-width: 307px) 100vw, 307px","type":"image/webp"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/42ada93f7fad74a8205a13a46dc4de57/81c8e/11_4_1.png 230w","/ohjelmointi-24-sv/static/42ada93f7fad74a8205a13a46dc4de57/4651d/11_4_1.png 307w"],"sizes":"(max-width: 307px) 100vw, 307px","type":"image/png"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"img","properties":{"className":["gatsby-resp-image-image"],"src":"/ohjelmointi-24-sv/static/42ada93f7fad74a8205a13a46dc4de57/4651d/11_4_1.png","alt":"11 4 1","title":"11 4 1","loading":"lazy","decoding":"async","style":"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"},"children":[]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Binära träd bör åtminstone teoretiskt sett vara lätta att hantera rekursivt: om vi vill utföra någon operation på varje nod i trädet behöver vår algoritm helt enkelt"}]},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Behandla den aktuella noden"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Anropa sig själv på barnnoden till vänster"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Anropa sig själv på barnnoden till höger"}]},{"type":"text","value":"\n"}]},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-wrapper"],"style":"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 362px; margin-bottom: 1rem;"},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"a","properties":{"className":["gatsby-resp-image-link"],"href":"/ohjelmointi-24-sv/static/32e25a73b5e04b72265ba7ccd2d765b1/10600/11_4_2.png","style":"display: block","target":"_blank","rel":["noopener"]},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-background-image"],"style":"padding-bottom: 77.82608695652173%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAB1klEQVQ4y4VU2Y7aQBD0/39V9mFhEwcJCZv79oUPbpsbKqrONhp7l6Sl1sjDTHVVTQnr8Xig2iyu0+kUnU4HURQ99/7XFiqlgJfLBYPBAIfDQVYT8F9lfceOtd/v0W63MZ/P0e/35dsc+pLharXCdrvFZrPBbrdDkiQIwxDNZhPr9Vr22JROCxaLBcw71baOx2OJFRm5rovlcvlko8O4P5lM4HneS+klwCzLhMVwOBQGJiCbv/m+j16vh9vt9r1kmq4Vx7GAjUYjkV1lmOe57FO+3jNTIQzP5zPYlEi5WpSmoMrQLMqvggogDaYMRiMIAtnkgNlsJmw5iN4SkDJ1gCpRy56SyYJAXJURpRGQ5vM3fpuAPEc/6SWtYN3v978MT6cT0jSVy3pBJXGPAdeImHYQUB/JzGfpla/XqxxwHOcZG5VIUA5utVolkG63K02bvsRGQ83JDLUWwTiAFxktfTz6z7NkrEOswohNURQYj8fSOojeEFxzyMtkqo9Xza2VxLGwIjtO5D+LH/jI0hRRFCL7fGUOIDBflizJmOfDMIDn+YiTWPatosjRaDRQr9XhOC7aroNfto2PWl3WvDiU8tfvdfH29kN8Ztfe3/HbbuCnbWOf5/gDQCDEjSWuT0cAAAAASUVORK5CYII='); background-size: cover; display: block;"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"picture","properties":{},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/32e25a73b5e04b72265ba7ccd2d765b1/a0b58/11_4_2.webp 230w","/ohjelmointi-24-sv/static/32e25a73b5e04b72265ba7ccd2d765b1/c2de8/11_4_2.webp 362w"],"sizes":"(max-width: 362px) 100vw, 362px","type":"image/webp"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/32e25a73b5e04b72265ba7ccd2d765b1/81c8e/11_4_2.png 230w","/ohjelmointi-24-sv/static/32e25a73b5e04b72265ba7ccd2d765b1/10600/11_4_2.png 362w"],"sizes":"(max-width: 362px) 100vw, 362px","type":"image/png"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"img","properties":{"className":["gatsby-resp-image-image"],"src":"/ohjelmointi-24-sv/static/32e25a73b5e04b72265ba7ccd2d765b1/10600/11_4_2.png","alt":"11 4 2","title":"11 4 2","loading":"lazy","decoding":"async","style":"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"},"children":[]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Som du kan se på bilden ovan är både de vänstra och högra \"underträden\" fullfjädrade binära träd i sig, och den enda nod som lämnas utanför de rekursiva anropen är den överordnade noden, som bearbetas i steg 1 innan funktionen anropas rekursivt. På så sätt kan vi vara säkra på att varje nod har besökts exakt en gång när funktionen är klar."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"En iterativ version av en binär trädtraversering skulle vara mycket mer komplicerad, eftersom vi på något sätt skulle behöva hålla reda på alla noder som vi redan har besökt. Samma principer gäller för alla beräkningsbara trädstrukturer, inte bara binära."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ett binärt träd är också lätt att modellera i Python-kod. Vi behöver bara skriva en klassdefinition för en enda nod. Den har ett värdeattribut och attribut för de vänstra och högra underordnade noderna:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Nod"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","triple-quoted-string","string"]},"children":[{"type":"text","value":"\"\"\" Klassen representerar en enkel nod i ett binärt träd \"\"\""}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" vanster_barn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'Nod'"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"None"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" hoger_barn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'Nod'"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"None"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"varde "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" varde\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vanster_barn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" vanster_barn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hoger_barn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" hoger_barn"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss anta att vi vill modellera följande träd:"}]},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-wrapper"],"style":"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 267px; margin-bottom: 1rem;"},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"a","properties":{"className":["gatsby-resp-image-link"],"href":"/ohjelmointi-24-sv/static/2d27ece550ee70e685bb54be04c9ea65/19e8f/11_4_3.png","style":"display: block","target":"_blank","rel":["noopener"]},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-background-image"],"style":"padding-bottom: 68.26086956521739%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAOCAYAAAAvxDzwAAAACXBIWXMAAAsTAAALEwEAmpwYAAABfUlEQVQ4y4VTWcuDQAzc///sDyr0wRdrRVuqvbx6aA96gtArHxPIsm4t34LEI5lMZqKijvP5fDjebjfyPI+v+Xyuv8n3rqO6wKQgjmO63+/0er0oyzI6nU7/giqTkcT3+80xz3MKw5CKomCWAO7KN8GV2U3u5Xk0GvGo6/WakiTRY0tTu1YD2l1wAFBVVevdZrPhJr80/xoZAIvFgobDIaVpyu8wJtiIDMfjkXzf57zZbEZN03QzPJ/PbILE7Xb7ZYBoGEURy1DXNU0mk1aeBtzv9+wkOoIpDLF1lVzIAaZwHc1bDGWU5/NJ/X6fx0CEXqbjJiDAwAxMB4NByyS9h8vlkhOlcDwe0+PxaIGaTEAApyxLWq1WOk/hAXpMp9NWwfV6pV6vx3+L7aS9Ea7rskk8MoSFq9BPktEJI2FsMDX/EHt8EIJM0BwSKDDY7XZ6TYQdlvhwOLDb0szUU1yHQaiHBI7jkEIx2NhrEgQBXS4XXmQA/2IIIriwJTDoD1qJNDsmtBRAAAAAAElFTkSuQmCC'); background-size: cover; display: block;"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"picture","properties":{},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/2d27ece550ee70e685bb54be04c9ea65/a0b58/11_4_3.webp 230w","/ohjelmointi-24-sv/static/2d27ece550ee70e685bb54be04c9ea65/9156e/11_4_3.webp 267w"],"sizes":"(max-width: 267px) 100vw, 267px","type":"image/webp"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/2d27ece550ee70e685bb54be04c9ea65/81c8e/11_4_3.png 230w","/ohjelmointi-24-sv/static/2d27ece550ee70e685bb54be04c9ea65/19e8f/11_4_3.png 267w"],"sizes":"(max-width: 267px) 100vw, 267px","type":"image/png"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"img","properties":{"className":["gatsby-resp-image-image"],"src":"/ohjelmointi-24-sv/static/2d27ece550ee70e685bb54be04c9ea65/19e8f/11_4_3.png","alt":"11 4 3","title":"11 4 3","loading":"lazy","decoding":"async","style":"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"},"children":[]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Vi kunde uppnå detta med följande kod:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n trad "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Nod"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n trad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vanster_barn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Nod"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n trad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vanster_barn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vanster_barn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Nod"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n trad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vanster_barn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hoger_barn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Nod"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"8"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n trad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hoger_barn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Nod"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n trad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hoger_barn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hoger_barn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Nod"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"11"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"algoritmer-for-rekursiva-binara-trad","style":"position:relative;"},"children":[{"type":"text","value":"Algoritmer för rekursiva binära träd"},{"type":"element","tagName":"a","properties":{"href":"#algoritmer-for-rekursiva-binara-trad","ariaLabel":"algoritmer for rekursiva binara trad permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss först ta en titt på en algoritm som skriver ut alla noder i ett binärt träd en efter en. I de följande exemplen kommer vi att arbeta med det binära träd som definieras ovan."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Argumentet till utskriftsfunktionen är rotnoden i det binära trädet. Detta är noden högst upp i vår illustration ovan. Alla andra noder är barn till den här noden:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"skriv_ut_noder"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" Nod"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" rot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vanster_barn "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"is"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"not"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"None"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n skriv_ut_noder"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vanster_barn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" rot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hoger_barn "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"is"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"not"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"None"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n skriv_ut_noder"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hoger_barn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen skriver ut värdet på den nod som skickas som argument och anropar sedan sig själv på de vänstra och högra underordnade noderna, förutsatt att noderna är definierade. Det här är en mycket enkel algoritm, men den går på ett effektivt och tillförlitligt sätt igenom alla noder i trädet, oavsett trädets storlek. Avgörande är att ingen nod besöks två gånger. Varje värde skrivs bara ut en gång."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Om vi skickar rotnoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"trad"}]},{"type":"text","value":" i det binära trädet som illustreras ovan som ett argument till funktionen, skriver den ut"}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"2\n3\n5\n8\n4\n11"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Som du kan se av ordningen på noderna i utskriften rör sig algoritmen först längs trädets \"vänstra ben\" ner till botten, och därifrån går den igenom de andra noderna i ordning."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"På samma sätt kan vi skriva en algoritm för att beräkna summan av alla de värden som finns lagrade i trädets noder:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"nodernas_summa"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" Nod"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n summa "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" rot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"varde\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" rot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vanster_barn "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"is"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"not"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"None"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n summa "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+="}]},{"type":"text","value":" nodernas_summa"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vanster_barn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" rot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hoger_barn "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"is"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"not"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"None"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n summa "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+="}]},{"type":"text","value":" nodernas_summa"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hoger_barn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" summa\n"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Variabeln "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"summa"}]},{"type":"text","value":" initieras till att vara lika med värdet för den aktuella noden. Värdet i variabeln ökas sedan genom rekursiva anrop till nodens summor i det vänstra och högra underordnade trädet (först kontrolleras naturligtvis att de finns). Detta resultat returneras sedan."}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Största noden","tmcname":"osa11-16_storsta_nod"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa funktionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"storsta_nod(rot: Nod)"}]},{"type":"text","value":", som tar rotnoden av ett binärt träd som argument."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen returnerar värdet på den nod som har det största värdet i trädet. Trädet ska genomkorsas rekursivt."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Tips: funktionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"nodernas_summa"}]},{"type":"text","value":" i exemplet ovan kan vara användbart."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Exempel på hur funktionen ska fungera:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n trad "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Nod"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n trad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vanster_barn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Nod"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n trad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vanster_barn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vanster_barn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Nod"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n trad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vanster_barn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hoger_barn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Nod"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"8"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n trad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hoger_barn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Nod"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n trad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hoger_barn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hoger_barn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Nod"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"11"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"storsta_nod"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"trad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"11"}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"sorterat-binart-trad","style":"position:relative;"},"children":[{"type":"text","value":"Sorterat binärt träd"},{"type":"element","tagName":"a","properties":{"href":"#sorterat-binart-trad","ariaLabel":"sorterat binart trad permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ett binärt träd är särskilt användbart när noderna är sorterade på ett visst sätt. Det gör att det går snabbt och effektivt att hitta noder i trädet."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss ta en titt på ett träd som är sorterat på följande sätt: det vänstra barnet till varje nod är mindre än själva noden och det högra barnet är på motsvarande sätt större."}]},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-wrapper"],"style":"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 307px; margin-bottom: 1rem;"},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"a","properties":{"className":["gatsby-resp-image-link"],"href":"/ohjelmointi-24-sv/static/42ada93f7fad74a8205a13a46dc4de57/4651d/11_4_1.png","style":"display: block","target":"_blank","rel":["noopener"]},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-background-image"],"style":"padding-bottom: 78.69565217391303%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAAAsTAAALEwEAmpwYAAABsElEQVQ4y3WU54rDQAyE/f5PlUD+JIT03ntvpHcdn0C+9Z5PYFxWO5rRaB2IF9/vV++fz0fa7bZ0u13pdDryer3CdcuJi8AHs+Tr9apgAHHn3c35DzRwF7nDjHg8HpJOp6XX60k2m5XNZhMy53L3uOCBL9WiXq/L7XYL35E9n89j2xMBdCvsdjsZDodSLBb12RhZjEYjLTQYDMJ1n0hgH5CICSQ2m82QnVvwcrlIo9GQ9XqtuX5fI4DP51Oq1arKqlQqcr/f/ySfz2ft6Ww2k1KppCR8o0JAAABarVZSq9UiJrjSDoeDFiWHZz8nMMfoC5IskH08Hv9tvhnnylbJzBjMuKyaycec7XYbC0qP2VMul2W/3/8yHI/HcjqddCwslsulOkrPYOqfIGI6ncpkMtFcJiMEZAPOsWiBjFwup98xIO6EULBQKChL1IRjgzy3d7BCZr/fD110Gb7fbzUFtynMflhikjJ0mwx1zMlkMhHn/PPNyCDZgsngG2uBm9xqtfQZdq7DlgMI7DDEcm0iMAaWkaNHhUQioQlxhx8gfhSpVEpPi8VisZBkMin5fF5+ALPgzivet7o7AAAAAElFTkSuQmCC'); background-size: cover; display: block;"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"picture","properties":{},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/42ada93f7fad74a8205a13a46dc4de57/a0b58/11_4_1.webp 230w","/ohjelmointi-24-sv/static/42ada93f7fad74a8205a13a46dc4de57/b1a97/11_4_1.webp 307w"],"sizes":"(max-width: 307px) 100vw, 307px","type":"image/webp"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/42ada93f7fad74a8205a13a46dc4de57/81c8e/11_4_1.png 230w","/ohjelmointi-24-sv/static/42ada93f7fad74a8205a13a46dc4de57/4651d/11_4_1.png 307w"],"sizes":"(max-width: 307px) 100vw, 307px","type":"image/png"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"img","properties":{"className":["gatsby-resp-image-image"],"src":"/ohjelmointi-24-sv/static/42ada93f7fad74a8205a13a46dc4de57/4651d/11_4_1.png","alt":"11 4 1","title":"11 4 1","loading":"lazy","decoding":"async","style":"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"},"children":[]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Nu kan vi skriva en rekursiv algoritm för att söka efter noder. Idén är mycket lik den binära sökningen från föregående avsnitt: om den aktuella noden är den nod vi letar efter, returnera "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"True"}]},{"type":"text","value":". Annars fortsätter vi rekursivt med antingen det vänstra eller det högra underordnade trädet. Om noden inte är definierad returneras "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"False"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"sok_nod"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" Nod"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" rot "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"is"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"None"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"False"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" varde "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" rot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"True"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" varde "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">"}]},{"type":"text","value":" rot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" sok_nod"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hoger_barn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" sok_nod"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rot"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vanster_barn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Chefer och underordnade","tmcname":"osa11-17_chefer_och_underordnade"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Arbetare"}]},{"type":"text","value":" modellerar en arbetare på ett företag:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Arbetare"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"underordnade "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"tillsatt_underordnad"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" arbetare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'Arbetare'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"underordnade"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"arbetare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa funktionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"rakna_underordnade(arbetare: Arbetare)"}]},{"type":"text","value":", som rekursivt räknar mängden underordnade som en arbetare har."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Exempel på funktionen i användning:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n a1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Arbetare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Sussi\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n a2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Arbetare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Erik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n a3 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Arbetare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Matte\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n a4 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Arbetare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Emilia\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n a5 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Arbetare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Anton\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n a6 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Arbetare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Kjell\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_underordnad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a4"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_underordnad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a6"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n a4"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_underordnad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n a4"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_underordnad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a3"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n a4"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_underordnad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a5"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rakna_underordnade"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rakna_underordnade"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a4"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"rakna_underordnade"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a5"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"5\n3\n0"}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"besok-till-tiden-innan-rekursion","style":"position:relative;"},"children":[{"type":"text","value":"Besök till tiden innan rekursion"},{"type":"element","tagName":"a","properties":{"href":"#besok-till-tiden-innan-rekursion","ariaLabel":"besok till tiden innan rekursion permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss avsluta denna del av materialet med en lite större övning som koncentrerar sig på objektorienterade programmeringsprinciper. Vi rekommenderar inte att du använder rekursion i denna serie av uppgifter, men tekniker för list comprehension kommer att vara användbara."}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Uppgiftsbok","tmcname":"osa11-18_uppgiftsbok"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I den här övningen kommer du skriva två olika klasser, vilka i sin tur kommer att vara ryggraden för övningen som följer denna, i vilken du kommer att skapa en interaktiv applikation."}]},{"type":"element","tagName":"h2","properties":{"id":"uppgift","style":"position:relative;"},"children":[{"type":"text","value":"Uppgift"},{"type":"element","tagName":"a","properties":{"href":"#uppgift","ariaLabel":"uppgift permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Förverkliga klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Uppgift"}]},{"type":"text","value":", som modellerar en uppgift i ett mjukvaruföretags lista av uppgifter. Uppgifterna har"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"en beskrivning"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"en beräkning av mängden timmar uppgiften tar"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"namnet på programmeraren som har fått uppgiften"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"ett fält som håller koll på ifall uppgiften är gjord"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"en unik id"}]},{"type":"text","value":"\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Klassen fungerar enligt följande:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"a1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Uppgift"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda hello world\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Erik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"id"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"beskrivning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"programmerare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"arbetsmangd"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"ar_fardig"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\na1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"markera_fardig"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"ar_fardig"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\na2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Uppgift"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda webbutik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Anton\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\na3 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Uppgift"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda mobilapp för räknande av arbetsmängd\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Erik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"25"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"a3"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"1 koda hello world Erik 3\n1: koda hello world (3 timmar), programmerare Erik INTE FÄRDIG\nFalse\n1: koda hello world (3 timmar), programmerare Erik FÄRDIG\nTrue\n2: koda webbutik (10 timmar), programmerare Anton INTE FÄRDIG\n3: koda mobilapp för räknande av arbetsmängd (25 timmar), programmerare Erik INTE FÄRDIG"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Klarifikationer:"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"uppgiftens läge (färdig eller inte färdig) kan kollas med funktionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"ar_fardig(self)"}]},{"type":"text","value":", som returnerar ett booleskt värde"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"uppgiften är inte färdig när den skapas"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"uppgiften markeras som färdig genom att anropa på metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"markera_fardig(self)"}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"uppgifternas id är ett löpande nummer som börjar med 1. Id av första uppgiften är 1, andra uppgiften 2 osv."}]},{"type":"text","value":"\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Tips:"}]},{"type":"text","value":" id kan implementeras med en "},{"type":"element","tagName":"a","properties":{"href":"/ohjelmointi-24-sv/osa-9/5-staattiset-piirteet#luokkamuuttujat"},"children":[{"type":"text","value":"klassvariabel"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"h2","properties":{"id":"uppgiftsbok","style":"position:relative;"},"children":[{"type":"text","value":"Uppgiftsbok"},{"type":"element","tagName":"a","properties":{"href":"#uppgiftsbok","ariaLabel":"uppgiftsbok permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa nu en klass med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Uppgiftsbok"}]},{"type":"text","value":", som samlar ihop alla uppgifter som delegerats av mjukvaruföretaget. Uppgifterna ska modelleras med klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Uppgift"}]},{"type":"text","value":" som du just gjorde."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Basversionen av Uppgiftsboken används enligt följande:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"bestallningar "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Uppgiftsbok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda webbutik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Anton\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda mobilapp för räknande av arbetsmängd\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Erik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"25"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda app för övande av matematik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Anton\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"100"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" bestallning "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" bestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"alla_bestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" programmerare "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" bestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"kodare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"programmerare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"1: koda webbutik (10 timmar), programmerare Anton INTE FÄRDIG\n2: koda mobilapp för räknande av arbetsmängd (25 timmar), programmerare Erik INTE FÄRDIG\n3: koda app för övande av matematik (100 timmar), programmerare Anton INTE FÄRDIG"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Anton\nErik"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I detta skede borde din "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Uppgiftsbok"}]},{"type":"text","value":" erbjuda tre metoder:"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"tillsatt_bestallning(self, beskrivning, programmerare, arbetsmangd)"}]},{"type":"text","value":", som lägger till en ny uppgift till Uppgiftsboken. En Uppgiftsbok förvarar uppgifterna internt som "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Uppgift"}]},{"type":"text","value":"-objekt. OBS: metoden ska ta exakt de argument som nämns eller så fungerar inte de automatiserade testerna korrekt."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"alla_bestallningar(self)"}]},{"type":"text","value":" returnerar en lista på alla uppgifter som lagras i en Uppgiftsbok"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"kodare(self)"}]},{"type":"text","value":" returnerar en lista på namnen av alla kodare som har uppgifter lagrade i Uppgiftsboken. Listan ska innehålla varje programmerare endast en gång."}]},{"type":"text","value":"\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Tips:"}]},{"type":"text","value":" En enkel metod för att göra sig av med multipler är att ursprungligen hantera listan som en "},{"type":"element","tagName":"a","properties":{"href":"https://docs.python.org/3.8/library/stdtypes.html#set","target":"_blank","rel":["noopener","noreferrer"]},"children":[{"type":"text","value":"mängd"}]},{"type":"text","value":" (eng: set). En mängd är en samling av saker där varje unikt föremål endast förekommer en gång. En "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"set"}]},{"type":"text","value":" kan sedan konverteras tillbaks till en lista, och vi kan då vara säkra på att varje föremål nu är unikt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"lista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"6"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\nlista2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"list"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"set"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[1, 1, 3, 6, 4, 1, 3]\n[1, 3, 4, 6]"}]}]},{"type":"element","tagName":"h2","properties":{"id":"nagra-fler-funktioner-for-uppgiftsboken","style":"position:relative;"},"children":[{"type":"text","value":"Några fler funktioner för Uppgiftsboken"},{"type":"element","tagName":"a","properties":{"href":"#nagra-fler-funktioner-for-uppgiftsboken","ariaLabel":"nagra fler funktioner for uppgiftsboken permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa tre till metoder till din "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Uppgiftsbok"}]},{"type":"text","value":"-klass."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"markera_fardig(self, id: int)"}]},{"type":"text","value":" får som argument uppgiftens id och markerar den relevanta uppgiften som färdig:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"bestallningar "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Uppgiftsbok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda webbutik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Anton\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda mobilapp för räknande av arbetsmängd\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Erik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"25"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda app för övande av matematik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Anton\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"100"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"markera_fardig"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"markera_fardig"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" bestallning "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" bestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"alla_bestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"1: koda webbutik (10 timmar), programmerare Anton FÄRDIG\n2: koda mobilapp för räknande av arbetsmängd (25 timmar), programmerare Erik FÄRDIG\n3: koda app för övande av matematik (100 timmar), programmerare Anton INTE FÄRDIG"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ifall det inte finns någon uppgift med det givna id:t, ska metoden åstadkomma ett "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"ValueError"}]},{"type":"text","value":"-undantag. Ifall du behöver en påminnelse om att åstadkomma undantag kan du kolla in "},{"type":"element","tagName":"a","properties":{"href":"/ohjelmointi-24-sv/osa-6/3-virheet#poikkeusten-tuottaminen"},"children":[{"type":"text","value":"modul 6"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Metoderna "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"fardiga_bestallningar(self)"}]},{"type":"text","value":" och "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"ofardiga_bestallningar(self)"}]},{"type":"text","value":" fungerar som förväntat: båda returnerar en lista innehållande de relevanta uppgifterna från Uppgiftsboken."}]},{"type":"element","tagName":"h2","properties":{"id":"projektets-sista-detaljer","style":"position:relative;"},"children":[{"type":"text","value":"Projektets sista detaljer"},{"type":"element","tagName":"a","properties":{"href":"#projektets-sista-detaljer","ariaLabel":"projektets sista detaljer permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Vi skapar en sista metod "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"programmerarens_status(self, programmerare: str)"}]},{"type":"text","value":" till "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Uppgiftsbok"}]},{"type":"text","value":"-klassen, vilken returnar en "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"tupel"}]},{"type":"text","value":". Tupeln ska innehålla antalet färdiga och ofärdiga uppgifter en programmerare har tilldelats samt den uppskattade mängden timmar i båda kategorierna."}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"bestallningar "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Uppgiftsbok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda webbutik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Anton\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda mobilapp för räknande av arbetsmängd\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Anton\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"25"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda app för övande av matematik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Anton\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"100"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_bestallning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"koda nya facebook\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Erik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1000"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"markera_fardig"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nbestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"markera_fardig"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nstatus "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" bestallningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"programmerarens_status"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Anton\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"status"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"(2, 1, 35, 100)"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Det första föremålet i tupeln är antalet "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"färdiga"}]},{"type":"text","value":" uppgifter, medan det andra föremålet är antalet "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"ofärdiga"}]},{"type":"text","value":" uppgifter. Det tredje och fjärde föremålet är summan av uppskattningarna av arbetsmängden för de färdiga respektive ofärdiga uppgifterna."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ifall det inte finns någon programmerare med det angivna namnet, ska metoden åstadkomma ett "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"ValueError"}]},{"type":"text","value":"-undantag."}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Uppgiftsboksapplikation","tmcname":"osa11-19_uppgiftsboksapplikation"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I den här övningen ska du skapa en interaktiv applikation för att administrera de uppgifter som beställts från ett programvaruföretag. Implementeringen är helt upp till dig, men du kan använda byggstenarna från föregående övning i din applikation. Exemplen i "},{"type":"element","tagName":"a","properties":{"href":"/ohjelmointi-24-sv/osa-10/4-lisaa-esimerkkeja"},"children":[{"type":"text","value":"det sista avsnittet av modul 10"}]},{"type":"text","value":" kan också vara till hjälp."}]},{"type":"element","tagName":"h2","properties":{"id":"utan-felhantering","style":"position:relative;"},"children":[{"type":"text","value":"Utan felhantering"},{"type":"element","tagName":"a","properties":{"href":"#utan-felhantering","ariaLabel":"utan felhantering permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Applikationen ska fungera "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"exakt"}]},{"type":"text","value":" enligt följande:"}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktioner:\n0 avsluta\n1 tillsätt beställning\n2 lista färdiga\n3 lista ofärdiga\n4 markera uppgift färdig\n5 programmerare\n6 programmerarens status"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\nbeskrivning: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"koda nya facebook"}]},{"type":"text","value":"\nprogrammerare och uppskattad arbetsmängd: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"jonas 1000"}]},{"type":"text","value":"\ntillsatt!"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\nbeskrivning: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"koda mobilapp för räknande av arbetsmängd"}]},{"type":"text","value":"\nprogrammerare och uppskattad arbetsmängd: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"erik 25"}]},{"type":"text","value":"\ntillsatt!"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\nbeskrivning: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"program för att öva musikteori"}]},{"type":"text","value":"\nprogrammerare och uppskattad arbetsmängd: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"nina 12"}]},{"type":"text","value":"\ntillsatt!"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\nbeskrivning: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"koda nya twitter"}]},{"type":"text","value":"\nprogrammerare och uppskattad arbetsmängd: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"jonas 55"}]},{"type":"text","value":"\ntillsatt!"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"2"}]},{"type":"text","value":"\ninga färdiga uppgifter"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"3"}]},{"type":"text","value":"\n1: koda nya facebook (1000 timmar), programmerare jonas INTE FÄRDIG\n2: koda mobilapp för räknande av arbetsmängd (25 timmar), programmerare erik INTE FÄRDIG\n3: ohjelma musiikin teorian harjoitteluun (12 timmar), programmerare nina INTE FÄRDIG\n4: koda nya twitter (55 timmar), programmerare jonas INTE FÄRDIG"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"4"}]},{"type":"text","value":"\nid: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"2"}]},{"type":"text","value":"\nmarkerad som färdig"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"4"}]},{"type":"text","value":"\nid: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"4"}]},{"type":"text","value":"\nmarkerad som färdig"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"2"}]},{"type":"text","value":"\n2: koda mobilapp för räknande av arbetsmängd (25 timmar), programmerare erik FÄRDIG\n4: koda nya twitter (55 timmar), programmerare jonas FÄRDIG"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"3"}]},{"type":"text","value":"\n1: koda nya facebook (1000 timmar), programmerare jonas INTE FÄRDIG\n3: program för att öva musikteori (12 timmar), programmerare nina INTE FÄRDIG"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"5"}]},{"type":"text","value":"\njonas\nerik\nnina"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"6"}]},{"type":"text","value":"\nprogrammerare: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"jonas"}]},{"type":"text","value":"\nuppgifter: färdiga 2 ofärdiga 1, timmar: gjorda 55 ogjorda 1000"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Den första övningspoängen ges för en fungerande applikation när alla användarinmatningar är felfria."}]},{"type":"element","tagName":"h2","properties":{"id":"hantering-av-inamtningsfel","style":"position:relative;"},"children":[{"type":"text","value":"Hantering av inamtningsfel"},{"type":"element","tagName":"a","properties":{"href":"#hantering-av-inamtningsfel","ariaLabel":"hantering av inamtningsfel permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"För att få den andra övningspoängen för denna övning förväntas din applikation återhämta sig från felaktig användarinmatning. All inmatning som inte följer det angivna formatet ska ge ett felmeddelande "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"felaktig inmatning"}]},{"type":"text","value":" och resultera i ännu en upprepning av loopen med begäran om en ny instruktion:"}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\nbeskrivning: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"koda mobilapp för räknande av arbetsmängd"}]},{"type":"text","value":"\nprogrammerare och uppskattad arbetsmängd: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"erik xxx"}]},{"type":"text","value":"\nfelaktig inmatning"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\nbeskrivning: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"koda mobilapp för räknande av arbetsmängd"}]},{"type":"text","value":"\nprogrammerare och uppskattad arbetsmängd: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"erik"}]},{"type":"text","value":"\nfelaktig inmatning"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"4"}]},{"type":"text","value":"\nid: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"1000000"}]},{"type":"text","value":"\nfelaktig inmatning"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"4"}]},{"type":"text","value":"\nid: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"XXXX"}]},{"type":"text","value":"\nfelaktig inmatning"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"instruktion: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"6"}]},{"type":"text","value":"\nprogrammerare: "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"okändprogrammerare"}]},{"type":"text","value":"\nfelaktig inmatning"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Svara slutligen på en snabb enkät:"}]},{"type":"element","tagName":"div","properties":{},"children":[{"type":"element","tagName":"quiz","properties":{"id":"4acb2792-f51e-55f0-b482-addf1977c630"},"children":[]}]}]},"html":"

    Efter den här delen

      \n
    • Kommer du att känna till binära träd och några rekursiva algoritmer som används för att bearbeta dem
    • \n

    De verkliga fördelarna med rekursion blir uppenbara när vi stöter på problem där iterativa lösningar är svåra att skriva. Låt oss ta en titt på binära träd, till exempel. Ett binärt träd är en förgrenad struktur där vi har noder och vid varje nod förgrenar sig strukturen, som mest, i två underordnade grenar med egna noder. Ett binärt träd skulle då kunna se ut så här (datavetenskap betraktas ofta som en gren av naturvetenskapen, men vår förståelse av träd är lite upp och ner, som du kommer att märka):

    \n \n \n \n \n \n \"11\n \n \n

    Binära träd bör åtminstone teoretiskt sett vara lätta att hantera rekursivt: om vi vill utföra någon operation på varje nod i trädet behöver vår algoritm helt enkelt

      \n
    1. Behandla den aktuella noden
    2. \n
    3. Anropa sig själv på barnnoden till vänster
    4. \n
    5. Anropa sig själv på barnnoden till höger
    6. \n
    \n \n = None, hoger_barn:'Nod' = None):\n self.varde = varde\n self.vanster_barn = vanster_barn\n self.hoger_barn = hoger_barn

    Låt oss anta att vi vill modellera följande träd:

    \n \n \n \n \n \n \"11\n \n \n

    Vi kunde uppnå detta med följande kod:

    if __name__ == \"__main__\":\n    trad = Nod(2)\n\n    trad.vanster_barn = Nod(3)\n    trad.vanster_barn.vanster_barn = Nod(5)\n    trad.vanster_barn.hoger_barn = Nod(8)\n\n    trad.hoger_barn = Nod(4)\n    trad.hoger_barn.hoger_barn = Nod(11)\n

    Algoritmer för rekursiva binära träd

    Låt oss först ta en titt på en algoritm som skriver ut alla noder i ett binärt träd en efter en. I de följande exemplen kommer vi att arbeta med det binära träd som definieras ovan.

    Argumentet till utskriftsfunktionen är rotnoden i det binära trädet. Detta är noden högst upp i vår illustration ovan. Alla andra noder är barn till den här noden:

    \ndef skriv_ut_noder(rot: Nod):\n    print(rot.varde)\n\n    if rot.vanster_barn is not None:\n        skriv_ut_noder(rot.vanster_barn)\n\n    if rot.hoger_barn is not None:\n        skriv_ut_noder(rot.hoger_barn)\n

    Funktionen skriver ut värdet på den nod som skickas som argument och anropar sedan sig själv på de vänstra och högra underordnade noderna, förutsatt att noderna är definierade. Det här är en mycket enkel algoritm, men den går på ett effektivt och tillförlitligt sätt igenom alla noder i trädet, oavsett trädets storlek. Avgörande är att ingen nod besöks två gånger. Varje värde skrivs bara ut en gång.

    Om vi skickar rotnoden trad i det binära trädet som illustreras ovan som ett argument till funktionen, skriver den ut

    2\n3\n5\n8\n4\n11

    Som du kan se av ordningen på noderna i utskriften rör sig algoritmen först längs trädets \"vänstra ben\" ner till botten, och därifrån går den igenom de andra noderna i ordning.

    På samma sätt kan vi skriva en algoritm för att beräkna summan av alla de värden som finns lagrade i trädets noder:

    \ndef nodernas_summa(rot: Nod):\n    summa = rot.varde\n\n    if rot.vanster_barn is not None:\n        summa += nodernas_summa(rot.vanster_barn)\n\n    if rot.hoger_barn is not None:\n        summa += nodernas_summa(rot.hoger_barn)\n\n    return summa\n

    Variabeln summa initieras till att vara lika med värdet för den aktuella noden. Värdet i variabeln ökas sedan genom rekursiva anrop till nodens summor i det vänstra och högra underordnade trädet (först kontrolleras naturligtvis att de finns). Detta resultat returneras sedan.

    Skapa funktionen storsta_nod(rot: Nod), som tar rotnoden av ett binärt träd som argument.

    Funktionen returnerar värdet på den nod som har det största värdet i trädet. Trädet ska genomkorsas rekursivt.

    Tips: funktionen nodernas_summa i exemplet ovan kan vara användbart.

    Exempel på hur funktionen ska fungera:

    \nif __name__ == \"__main__\":\n    trad = Nod(2)\n\n    trad.vanster_barn = Nod(3)\n    trad.vanster_barn.vanster_barn = Nod(5)\n    trad.vanster_barn.hoger_barn = Nod(8)\n\n    trad.hoger_barn = Nod(4)\n    trad.hoger_barn.hoger_barn = Nod(11)\n\n    print(storsta_nod(trad))\n

    11

    Sorterat binärt träd

    Ett binärt träd är särskilt användbart när noderna är sorterade på ett visst sätt. Det gör att det går snabbt och effektivt att hitta noder i trädet.

    Låt oss ta en titt på ett träd som är sorterat på följande sätt: det vänstra barnet till varje nod är mindre än själva noden och det högra barnet är på motsvarande sätt större.

    \n \n \n \n \n \n \"11\n \n \n

    Nu kan vi skriva en rekursiv algoritm för att söka efter noder. Idén är mycket lik den binära sökningen från föregående avsnitt: om den aktuella noden är den nod vi letar efter, returnera True. Annars fortsätter vi rekursivt med antingen det vänstra eller det högra underordnade trädet. Om noden inte är definierad returneras False.

    \ndef sok_nod(rot: Nod, varde):\n    if rot is None:\n        return False\n\n    if varde == rot.varde:\n        return True\n\n    if varde > rot.varde:\n        return sok_nod(rot.hoger_barn, varde)\n\n    return sok_nod(rot.vanster_barn, varde)\n

    Klassen Arbetare modellerar en arbetare på ett företag:

    class Arbetare:\n    def __init__(self, namn: str):\n        self.namn = namn\n        self.underordnade = []\n\n    def tillsatt_underordnad(self, arbetare: 'Arbetare'):\n        self.underordnade.append(arbetare)

    Skapa funktionen rakna_underordnade(arbetare: Arbetare), som rekursivt räknar mängden underordnade som en arbetare har.

    Exempel på funktionen i användning:

    if __name__ == \"__main__\":\n    a1 = Arbetare(\"Sussi\")\n    a2 = Arbetare(\"Erik\")\n    a3 = Arbetare(\"Matte\")\n    a4 = Arbetare(\"Emilia\")\n    a5 = Arbetare(\"Anton\")\n    a6 = Arbetare(\"Kjell\")\n    a1.tillsatt_underordnad(a4)\n    a1.tillsatt_underordnad(a6)\n    a4.tillsatt_underordnad(a2)\n    a4.tillsatt_underordnad(a3)\n    a4.tillsatt_underordnad(a5)\n    print(rakna_underordnade(a1))\n    print(rakna_underordnade(a4))\n    print(rakna_underordnade(a5))

    5\n3\n0

    Besök till tiden innan rekursion

    Låt oss avsluta denna del av materialet med en lite större övning som koncentrerar sig på objektorienterade programmeringsprinciper. Vi rekommenderar inte att du använder rekursion i denna serie av uppgifter, men tekniker för list comprehension kommer att vara användbara.

    I den här övningen kommer du skriva två olika klasser, vilka i sin tur kommer att vara ryggraden för övningen som följer denna, i vilken du kommer att skapa en interaktiv applikation.

    Uppgift

    Förverkliga klassen Uppgift, som modellerar en uppgift i ett mjukvaruföretags lista av uppgifter. Uppgifterna har

      \n
    • en beskrivning
    • \n
    • en beräkning av mängden timmar uppgiften tar
    • \n
    • namnet på programmeraren som har fått uppgiften
    • \n
    • ett fält som håller koll på ifall uppgiften är gjord
    • \n
    • en unik id
    • \n

    Klassen fungerar enligt följande:

    a1 = Uppgift(\"koda hello world\", \"Erik\", 3)\nprint(a1.id, a1.beskrivning, a1.programmerare, a1.arbetsmangd)\nprint(a1)\nprint(a1.ar_fardig())\na1.markera_fardig()\nprint(a1)\nprint(a1.ar_fardig())\na2 = Uppgift(\"koda webbutik\", \"Anton\", 10)\na3 = Uppgift(\"koda mobilapp för räknande av arbetsmängd\", \"Erik\", 25)\nprint(a2)\nprint(a3)

    1 koda hello world Erik 3\n1: koda hello world (3 timmar), programmerare Erik INTE FÄRDIG\nFalse\n1: koda hello world (3 timmar), programmerare Erik FÄRDIG\nTrue\n2: koda webbutik (10 timmar), programmerare Anton INTE FÄRDIG\n3: koda mobilapp för räknande av arbetsmängd (25 timmar), programmerare Erik INTE FÄRDIG

    Klarifikationer:

      \n
    • uppgiftens läge (färdig eller inte färdig) kan kollas med funktionen ar_fardig(self), som returnerar ett booleskt värde
    • \n
    • uppgiften är inte färdig när den skapas
    • \n
    • uppgiften markeras som färdig genom att anropa på metoden markera_fardig(self)
    • \n
    • uppgifternas id är ett löpande nummer som börjar med 1. Id av första uppgiften är 1, andra uppgiften 2 osv.
    • \n

    Tips: id kan implementeras med en klassvariabel.

    Uppgiftsbok

    Skapa nu en klass med namnet Uppgiftsbok, som samlar ihop alla uppgifter som delegerats av mjukvaruföretaget. Uppgifterna ska modelleras med klassen Uppgift som du just gjorde.

    Basversionen av Uppgiftsboken används enligt följande:

    bestallningar = Uppgiftsbok()\nbestallningar.tillsatt_bestallning(\"koda webbutik\", \"Anton\", 10)\nbestallningar.tillsatt_bestallning(\"koda mobilapp för räknande av arbetsmängd\", \"Erik\", 25)\nbestallningar.tillsatt_bestallning(\"koda app för övande av matematik\", \"Anton\", 100)\n\nfor bestallning in bestallningar.alla_bestallningar():\n    print(bestallning)\n\nprint()\n\nfor programmerare in bestallningar.kodare():\n    print(programmerare)

    1: koda webbutik (10 timmar), programmerare Anton INTE FÄRDIG\n2: koda mobilapp för räknande av arbetsmängd (25 timmar), programmerare Erik INTE FÄRDIG\n3: koda app för övande av matematik (100 timmar), programmerare Anton INTE FÄRDIG

    Anton\nErik

    I detta skede borde din Uppgiftsbok erbjuda tre metoder:

      \n
    • tillsatt_bestallning(self, beskrivning, programmerare, arbetsmangd), som lägger till en ny uppgift till Uppgiftsboken. En Uppgiftsbok förvarar uppgifterna internt som Uppgift-objekt. OBS: metoden ska ta exakt de argument som nämns eller så fungerar inte de automatiserade testerna korrekt.
    • \n
    • alla_bestallningar(self) returnerar en lista på alla uppgifter som lagras i en Uppgiftsbok
    • \n
    • kodare(self) returnerar en lista på namnen av alla kodare som har uppgifter lagrade i Uppgiftsboken. Listan ska innehålla varje programmerare endast en gång.
    • \n

    Tips: En enkel metod för att göra sig av med multipler är att ursprungligen hantera listan som en mängd (eng: set). En mängd är en samling av saker där varje unikt föremål endast förekommer en gång. En set kan sedan konverteras tillbaks till en lista, och vi kan då vara säkra på att varje föremål nu är unikt:

    lista = [1,1,3,6,4,1,3]\nlista2 = list(set(lista))\nprint(lista)\nprint(lista2)

    [1, 1, 3, 6, 4, 1, 3]\n[1, 3, 4, 6]

    Några fler funktioner för Uppgiftsboken

    Skapa tre till metoder till din Uppgiftsbok-klass.

    Metoden markera_fardig(self, id: int) får som argument uppgiftens id och markerar den relevanta uppgiften som färdig:

    bestallningar = Uppgiftsbok()\nbestallningar.tillsatt_bestallning(\"koda webbutik\", \"Anton\", 10)\nbestallningar.tillsatt_bestallning(\"koda mobilapp för räknande av arbetsmängd\", \"Erik\", 25)\nbestallningar.tillsatt_bestallning(\"koda app för övande av matematik\", \"Anton\", 100)\n\nbestallningar.markera_fardig(1)\nbestallningar.markera_fardig(2)\n\nfor bestallning in bestallningar.alla_bestallningar():\n    print(bestallning)

    1: koda webbutik (10 timmar), programmerare Anton FÄRDIG\n2: koda mobilapp för räknande av arbetsmängd (25 timmar), programmerare Erik FÄRDIG\n3: koda app för övande av matematik (100 timmar), programmerare Anton INTE FÄRDIG

    Ifall det inte finns någon uppgift med det givna id:t, ska metoden åstadkomma ett ValueError-undantag. Ifall du behöver en påminnelse om att åstadkomma undantag kan du kolla in modul 6.

    Metoderna fardiga_bestallningar(self) och ofardiga_bestallningar(self) fungerar som förväntat: båda returnerar en lista innehållande de relevanta uppgifterna från Uppgiftsboken.

    Projektets sista detaljer

    Vi skapar en sista metod programmerarens_status(self, programmerare: str) till Uppgiftsbok-klassen, vilken returnar en tupel. Tupeln ska innehålla antalet färdiga och ofärdiga uppgifter en programmerare har tilldelats samt den uppskattade mängden timmar i båda kategorierna.

    bestallningar = Uppgiftsbok()\nbestallningar.tillsatt_bestallning(\"koda webbutik\", \"Anton\", 10)\nbestallningar.tillsatt_bestallning(\"koda mobilapp för räknande av arbetsmängd\", \"Anton\", 25)\nbestallningar.tillsatt_bestallning(\"koda app för övande av matematik\", \"Anton\", 100)\nbestallningar.tillsatt_bestallning(\"koda nya facebook\", \"Erik\", 1000)\n\nbestallningar.markera_fardig(1)\nbestallningar.markera_fardig(2)\n\nstatus = bestallningar.programmerarens_status(\"Anton\")\nprint(status)

    (2, 1, 35, 100)

    Det första föremålet i tupeln är antalet färdiga uppgifter, medan det andra föremålet är antalet ofärdiga uppgifter. Det tredje och fjärde föremålet är summan av uppskattningarna av arbetsmängden för de färdiga respektive ofärdiga uppgifterna.

    Ifall det inte finns någon programmerare med det angivna namnet, ska metoden åstadkomma ett ValueError-undantag.

    I den här övningen ska du skapa en interaktiv applikation för att administrera de uppgifter som beställts från ett programvaruföretag. Implementeringen är helt upp till dig, men du kan använda byggstenarna från föregående övning i din applikation. Exemplen i det sista avsnittet av modul 10 kan också vara till hjälp.

    Utan felhantering

    Applikationen ska fungera exakt enligt följande:

    instruktioner:\n0 avsluta\n1 tillsätt beställning\n2 lista färdiga\n3 lista ofärdiga\n4 markera uppgift färdig\n5 programmerare\n6 programmerarens status

    instruktion: 1\nbeskrivning: koda nya facebook\nprogrammerare och uppskattad arbetsmängd: jonas 1000\ntillsatt!

    instruktion: 1\nbeskrivning: koda mobilapp för räknande av arbetsmängd\nprogrammerare och uppskattad arbetsmängd: erik 25\ntillsatt!

    instruktion: 1\nbeskrivning: program för att öva musikteori\nprogrammerare och uppskattad arbetsmängd: nina 12\ntillsatt!

    instruktion: 1\nbeskrivning: koda nya twitter\nprogrammerare och uppskattad arbetsmängd: jonas 55\ntillsatt!

    instruktion: 2\ninga färdiga uppgifter

    instruktion: 3\n1: koda nya facebook (1000 timmar), programmerare jonas INTE FÄRDIG\n2: koda mobilapp för räknande av arbetsmängd (25 timmar), programmerare erik INTE FÄRDIG\n3: ohjelma musiikin teorian harjoitteluun (12 timmar), programmerare nina INTE FÄRDIG\n4: koda nya twitter (55 timmar), programmerare jonas INTE FÄRDIG

    instruktion: 4\nid: 2\nmarkerad som färdig

    instruktion: 4\nid: 4\nmarkerad som färdig

    instruktion: 2\n2: koda mobilapp för räknande av arbetsmängd (25 timmar), programmerare erik FÄRDIG\n4: koda nya twitter (55 timmar), programmerare jonas FÄRDIG

    instruktion: 3\n1: koda nya facebook (1000 timmar), programmerare jonas INTE FÄRDIG\n3: program för att öva musikteori (12 timmar), programmerare nina INTE FÄRDIG

    instruktion: 5\njonas\nerik\nnina

    instruktion: 6\nprogrammerare: jonas\nuppgifter: färdiga 2 ofärdiga 1, timmar: gjorda 55 ogjorda 1000

    Den första övningspoängen ges för en fungerande applikation när alla användarinmatningar är felfria.

    Hantering av inamtningsfel

    För att få den andra övningspoängen för denna övning förväntas din applikation återhämta sig från felaktig användarinmatning. All inmatning som inte följer det angivna formatet ska ge ett felmeddelande felaktig inmatning och resultera i ännu en upprepning av loopen med begäran om en ny instruktion:

    instruktion: 1\nbeskrivning: koda mobilapp för räknande av arbetsmängd\nprogrammerare och uppskattad arbetsmängd: erik xxx\nfelaktig inmatning

    instruktion: 1\nbeskrivning: koda mobilapp för räknande av arbetsmängd\nprogrammerare och uppskattad arbetsmängd: erik\nfelaktig inmatning

    instruktion: 4\nid: 1000000\nfelaktig inmatning

    instruktion: 4\nid: XXXX\nfelaktig inmatning

    instruktion: 6\nprogrammerare: okändprogrammerare\nfelaktig inmatning

    Svara slutligen på en snabb enkät:

    ","frontmatter":{"path":"/osa-11/4-lisaa-esimerkkeja","title":"Fler exempel på rekursion"},"fileAbsolutePath":"/home/runner/work/ohjelmointi-24-sv/ohjelmointi-24-sv/data/osa-11/4-fler-exempel-pa-rekursion.md"},"allPages":{"edges":[{"node":{"id":"b5e8ae41-d492-55f7-88a7-1c7292333ab1","frontmatter":{"path":"/arvostelu-ja-kokeet","title":"Arvostelu ja kokeet"}}},{"node":{"id":"af4df6be-211d-5ba1-acea-9edbefa06c49","frontmatter":{"path":"/frontmatter-guide","title":"Frontmatter-guide"}}},{"node":{"id":"56769133-4836-5fbb-a857-8fb0c6803e6d","frontmatter":{"path":"/","title":"Tietoa kurssista"}}},{"node":{"id":"e86762f0-c2a9-5598-aba3-2b8d7db7807c","frontmatter":{"path":"/kaikki-tehtavat","title":"Kaikki tehtävät"}}},{"node":{"id":"5d065309-85e8-5823-9527-ec1c3cf38d4d","frontmatter":{"path":"/tuki","title":"Tukea tehtäviin"}}},{"node":{"id":"ac195ee0-ad04-5cc9-9643-963f93d29ad2","frontmatter":{"path":"/usein-kysytyt-kysymykset","title":"Usein kysytyt kysymykset"}}},{"node":{"id":"51a165d7-8ce5-5d53-9c15-5321b6adef8c","frontmatter":{"path":"/verkkotentti","title":"Verkkotentti 4.6."}}},{"node":{"id":"4d9cf293-01e9-5e6c-a88f-599560e33c9a","frontmatter":{"path":"/verkkotentti-ohja","title":"Ohjelmoinnin jatkokurssin verkkotentti 16.12."}}},{"node":{"id":"279e1cca-fb0b-5d3f-b527-be05243d138d","frontmatter":{"path":"/verkkotentti-ohpe","title":"Ohjelmoinnin perusteiden verkkotentti 09.03."}}},{"node":{"id":"347bdde4-ba21-5f22-8a88-0287dfe29a45","frontmatter":{"path":"/virheilmoitukset","title":"Yleiset virheilmoitukset"}}},{"node":{"id":"3bf12e3a-1542-57f4-812d-dd32cebc99e2","frontmatter":{"path":"/sanasto","title":"Sanasto"}}},{"node":{"id":"9910673b-d62d-5d8d-a756-5267160d891f","frontmatter":{"path":"/osa-1/1-introduktion","title":"Introduktion"}}},{"node":{"id":"0b17a28e-f939-57cc-aa5b-4db407cdf34a","frontmatter":{"path":"/osa-1/2-info-fran-anvandaren","title":"Information från användaren"}}},{"node":{"id":"b95794f2-f3b3-597c-a4ec-6f023b584f81","frontmatter":{"path":"/osa-1/3-mer-om-variabler","title":"Mer om variabler"}}},{"node":{"id":"02cd0849-e7a5-5fd1-bf66-35f0197d3e75","frontmatter":{"path":"/osa-1/4-rakneoperationer","title":"Räkneoperationer"}}},{"node":{"id":"42690a69-3997-5b84-b999-15d9c3212884","frontmatter":{"path":"/osa-1/5-villkorssatser","title":"If-satser"}}},{"node":{"id":"96a0ec65-c0a3-5150-95c5-48c260f88162","frontmatter":{"path":"/osa-1","title":"Modul 1"}}},{"node":{"id":"e7a4d0c8-b8c1-53fa-ab51-9cc06fd417a3","frontmatter":{"path":"/osa-10/1-klasshierarkier","title":"Klasshierarkier"}}},{"node":{"id":"5f6d4b8b-7d05-5c79-9f2f-9e30b397167b","frontmatter":{"path":"/osa-10/2-atkamstmodifierare","title":"Åtkomstmodifierare"}}},{"node":{"id":"bb896c90-aabc-5a9d-8d4b-50839da286db","frontmatter":{"path":"/osa-10/3-objektorienterade-programmeringstekniker","title":"Objektorienterade programmeringstekniker"}}},{"node":{"id":"a2dca4f1-d64d-5e77-a3ca-8b2a208e9afa","frontmatter":{"path":"/osa-10/4-storre-applikation","title":"Att utveckla en större applikation"}}},{"node":{"id":"8c9cf5a7-f02e-5ccf-ab8f-f078c3ccecb6","frontmatter":{"path":"/osa-10","title":"Modul 10"}}},{"node":{"id":"f6688d26-5502-5c17-a8ee-db66f650f1f1","frontmatter":{"path":"/osa-11/1-list-comprehension","title":"List comprehension"}}},{"node":{"id":"1eac8489-72f2-5d53-904b-c960e2622018","frontmatter":{"path":"/osa-11/2-mer-om-comprehensions","title":"Mer om comprehensions"}}},{"node":{"id":"09630fca-7768-53f3-8aca-6e5ac638fc68","frontmatter":{"path":"/osa-11/3-rekursion","title":"Rekursion"}}},{"node":{"id":"70f6008e-a762-574c-a92a-c5c585d9677e","frontmatter":{"path":"/osa-11/4-lisaa-esimerkkeja","title":"Fler exempel på rekursion"}}},{"node":{"id":"eb8ed7d7-c39d-52db-949d-f75649498c67","frontmatter":{"path":"/osa-11","title":"Modul 11"}}},{"node":{"id":"9bba31dc-e14c-5400-a25b-7339107e9ba7","frontmatter":{"path":"/osa-12/1-funktioner-som-argument","title":"Funktioner som argument"}}},{"node":{"id":"5b9e4584-7234-5216-a118-d2a1bc617e13","frontmatter":{"path":"/osa-12/2-generatorer","title":"Generatorer"}}},{"node":{"id":"1d27636e-74f4-5c30-a1d8-08a303684945","frontmatter":{"path":"/osa-12/3-funktionell-programmering","title":"Funktionell programmering"}}},{"node":{"id":"6785750f-f145-5b88-81e9-b52e36ba53c6","frontmatter":{"path":"/osa-12/4-reguljara-uttryck","title":"Reguljära uttryck"}}},{"node":{"id":"d21df33a-4bf4-5ee3-9e2a-431d57561f09","frontmatter":{"path":"/osa-12","title":"Modul 12"}}},{"node":{"id":"14e3c129-50ec-581f-8679-8132248d41c1","frontmatter":{"path":"/osa-13/1-pygame","title":"Pygame"}}},{"node":{"id":"01bc3b9b-4f80-5561-8b56-3a7f09082263","frontmatter":{"path":"/osa-13/2-animation","title":"Animation"}}},{"node":{"id":"dd68786f-e2fc-5957-b47a-52b74c5199ef","frontmatter":{"path":"/osa-13/3-handelser","title":"Händelser"}}},{"node":{"id":"4a1aaa41-d6f7-51cd-8b89-95842cb9e02d","frontmatter":{"path":"/osa-13/4-fler-pygame-tekniker","title":"Fler pygame-tekniker"}}},{"node":{"id":"cdcf0ce1-e881-5ca6-8fa9-d0d343ec4e15","frontmatter":{"path":"/osa-13","title":"Modul 13"}}},{"node":{"id":"0ab28435-7654-5a8e-88d6-daa17d78103b","frontmatter":{"path":"/osa-14/1-spelprojekt","title":"Spelprojekt"}}},{"node":{"id":"b7a0628c-e4ba-583e-a52a-dd0ad78028d8","frontmatter":{"path":"/osa-14/2-robot-och-ladar","title":"Robot och lådor"}}},{"node":{"id":"6ccdbdff-7539-5a23-b23c-2ad48a99386f","frontmatter":{"path":"/osa-14/3-fardigstallande-av-spelet","title":"Färdigställande av spelet"}}},{"node":{"id":"1b505c9f-9b1b-58bd-8df7-553fef49cc8d","frontmatter":{"path":"/osa-14/4-ditt-eget-sepl","title":"Ditt eget spel"}}},{"node":{"id":"55c54859-8c7f-5fd9-8a8d-2c54ee677577","frontmatter":{"path":"/osa-14","title":"Modul 14"}}},{"node":{"id":"b5c346d1-d175-5824-98bb-4a4c3b45204d","frontmatter":{"path":"/osa-2/1-terminologi","title":"Programmeringsterminologi"}}},{"node":{"id":"db7188b0-0253-5c30-b8d2-0e115e235fb3","frontmatter":{"path":"/osa-2/2-else-elif","title":"Mera om if-satser"}}},{"node":{"id":"49d15928-f8b9-5883-9f29-86c307f6929e","frontmatter":{"path":"/osa-2/3-kombinera-villkor","title":"Kombinera villkor"}}},{"node":{"id":"93f1f9c8-6b27-5892-8bd4-7d1d008bf07a","frontmatter":{"path":"/osa-2/4-loopar","title":"Enkla loopar"}}},{"node":{"id":"5523b5b8-61f8-506d-bfe0-c6cc774390ce","frontmatter":{"path":"/osa-2","title":"Modul 2"}}},{"node":{"id":"02012307-c2a6-5cf2-9105-c10933c14b37","frontmatter":{"path":"/osa-3/1-loopar-med-villkor","title":"Loopar med villkor"}}},{"node":{"id":"efb889f4-4a19-515e-a0f6-4297d76a2757","frontmatter":{"path":"/osa-3/2-behandla-strangar","title":"Behandla strängar"}}},{"node":{"id":"a602077d-bbae-5eb7-a354-cc44b29ae96a","frontmatter":{"path":"/osa-3/3-mer-om-loopar","title":"Mera om loopar"}}},{"node":{"id":"6d878692-b9c7-57e6-ae58-044e5a6bef6f","frontmatter":{"path":"/osa-3/4-definiera-funktioner","title":"Definiera funktioner"}}},{"node":{"id":"682b5a18-73c5-56e2-8374-237baccbab40","frontmatter":{"path":"/osa-3","title":"Modul 3"}}},{"node":{"id":"3de95518-6b44-54db-9bcd-0c90a41d2fd5","frontmatter":{"path":"/osa-4/1-vscode","title":"Editorn Visual Studio Code, Pythontolken och det inbyggda debuggningsverktyget"}}},{"node":{"id":"7de9921c-7f94-58fe-84b9-7676dddb3b94","frontmatter":{"path":"/osa-4/2-mer-om-funktioner","title":"Mer om funktioner"}}},{"node":{"id":"29e29c69-360c-5f5c-8f34-5aef22eb327f","frontmatter":{"path":"/osa-4/3-listor","title":"Listor"}}},{"node":{"id":"bfe57880-0cbb-54e4-be9c-8fa180eafe6b","frontmatter":{"path":"/osa-4/4-iteration","title":"Iteration"}}},{"node":{"id":"2eab46f0-5373-5cbe-b2a0-1d071854a053","frontmatter":{"path":"/osa-4/5-utskrift","title":"Formatera utskrift"}}},{"node":{"id":"a5974fee-f2eb-5b89-88a5-6dd3754baaad","frontmatter":{"path":"/osa-4/6-strangar-listor","title":"Mera strängar och listor"}}},{"node":{"id":"e125c469-ee19-505e-9a41-83da6143ecd8","frontmatter":{"path":"/osa-4","title":"Modul 4"}}},{"node":{"id":"2558444a-be1d-5bc6-95ab-e091da2443fc","frontmatter":{"path":"/osa-5/1-mer-om-listor","title":"Mer om listor"}}},{"node":{"id":"b452d9be-0569-56c2-ba89-a040d4cb40dc","frontmatter":{"path":"/osa-5/2-referenser","title":"Referenser"}}},{"node":{"id":"ebe4ca3f-e657-5907-bfcc-ae84d9947aff","frontmatter":{"path":"/osa-5/3-lexikon","title":"Lexikon"}}},{"node":{"id":"f1dd5d66-ac87-5e53-92a0-0b7e3ece6ed8","frontmatter":{"path":"/osa-5/4-tuple","title":"Tuple"}}},{"node":{"id":"161c0109-5c00-5bed-b7af-90dc7ddf5713","frontmatter":{"path":"/osa-5","title":"Modul 5"}}},{"node":{"id":"e6cfa6e1-e99b-50e0-bc6a-3c0f153420e8","frontmatter":{"path":"/osa-6/1-lasa-filer","title":"Läsa filer"}}},{"node":{"id":"ce8d90a4-ca7c-5797-abc1-3fe0094bfa4b","frontmatter":{"path":"/osa-6/2-skriva-filer","title":"Skriva filer"}}},{"node":{"id":"519d5330-277a-59ba-be50-c2f63080df94","frontmatter":{"path":"/osa-6/3-fel","title":"Förbered dig på fel"}}},{"node":{"id":"82393756-3ef8-5d07-a8da-fed818ca43f0","frontmatter":{"path":"/osa-6/4-lokala-globala-variabler","title":"Lokala och globala variabler"}}},{"node":{"id":"007d85ae-a118-5b10-8a7e-18302b15eba8","frontmatter":{"path":"/osa-6","title":"Modul 6"}}},{"node":{"id":"bbb2346d-b1ee-551d-89c1-516f119b0eed","frontmatter":{"path":"/osa-7/1-moduler","title":"Moduler"}}},{"node":{"id":"ecb9af64-49f9-5e28-a544-3934e95233cf","frontmatter":{"path":"/osa-7/2-slumpmassighet","title":"Slumpmässighet"}}},{"node":{"id":"ebe469ef-c486-523a-9621-5dc4040c5cd8","frontmatter":{"path":"/osa-7/3-tid-datum","title":"Tid och datum"}}},{"node":{"id":"b9cf2d99-08f6-5de5-8425-c9b483241567","frontmatter":{"path":"/osa-7/4-behandla-data","title":"Behandla data"}}},{"node":{"id":"27075b37-8a6a-5554-9079-465a36d2da2d","frontmatter":{"path":"/osa-7/5-egna-moduler","title":"Skapa dina egna moduler"}}},{"node":{"id":"69492225-4d69-59ea-b33d-5301d35cf4ed","frontmatter":{"path":"/osa-7/6-funktionaliteter-python","title":"Flera funktionaliteter i Python"}}},{"node":{"id":"70ae841a-e6e9-5252-afae-6329fb67bcad","frontmatter":{"path":"/osa-7","title":"Modul 7"}}},{"node":{"id":"4afc4486-3cfe-53d1-b4c0-6db26484acfa","frontmatter":{"path":"/osa-8/1-objekt-och-metoder","title":"Objekt och metoder"}}},{"node":{"id":"6be37772-e94b-5b36-8a02-fffa7eef9feb","frontmatter":{"path":"/osa-8/2-klasser-och-objekt","title":"Klasser och objekt"}}},{"node":{"id":"8b6aec39-f8b9-525c-9f25-d8e73389fa42","frontmatter":{"path":"/osa-8/3-egna-klasser","title":"Egna klasser"}}},{"node":{"id":"85db460a-77c6-5087-8e97-a3c772186fd9","frontmatter":{"path":"/osa-8/4-metoder-i-egna-klasser","title":"Metoder i egna klasser"}}},{"node":{"id":"0e59dee0-5dd9-5827-83b9-a55e7d585c31","frontmatter":{"path":"/osa-8/5-fler-exempel","title":"Fler exempel"}}},{"node":{"id":"64715d0c-54f1-5aa7-a566-d2c5be6523ea","frontmatter":{"path":"/osa-8","title":"Modul 8"}}},{"node":{"id":"f7457509-a9a6-5420-8d03-ff1c61df8dc4","frontmatter":{"path":"/osa-9/1-objekt-och-referenser","title":"Objekt och referenser"}}},{"node":{"id":"16689ce4-b6aa-5bc4-9a30-44820994d6ea","frontmatter":{"path":"/osa-9/2-objekt-som-attribut","title":"Objekt som attribut "}}},{"node":{"id":"07985959-e85a-5f45-8923-babacb943c04","frontmatter":{"path":"/osa-9/3-inkapsling","title":"Inkapsling"}}},{"node":{"id":"83108600-9a37-5fd1-9a2b-13492879a9d6","frontmatter":{"path":"/osa-9/4-metodernas-rackvidd","title":"Metodernas räckvidd"}}},{"node":{"id":"a553cdc9-d6ac-5a14-ab43-d44811b407a2","frontmatter":{"path":"/osa-9/5-klassattribut","title":"Klassattribut"}}},{"node":{"id":"f7d7c9f1-6b54-5268-a308-995d49dd913d","frontmatter":{"path":"/osa-9/6-fler-exempel-med-klasser","title":"Fler exempel med klasser"}}},{"node":{"id":"c1fef3f7-8ca3-5780-9dec-19bd672b4627","frontmatter":{"path":"/osa-9","title":"Modul 9"}}}]}},"pageContext":{}}, "staticQueryHashes": ["1357757885","994120085"]} \ No newline at end of file diff --git a/page-data/osa-8/1-objekt-och-metoder/page-data.json b/page-data/osa-8/1-objekt-och-metoder/page-data.json index fa0edcad7..6109fe6eb 100644 --- a/page-data/osa-8/1-objekt-och-metoder/page-data.json +++ b/page-data/osa-8/1-objekt-och-metoder/page-data.json @@ -1,5 +1,5 @@ { "componentChunkName": "component---src-templates-course-content-template-js", "path": "/osa-8/1-objekt-och-metoder", - "result": {"data":{"page":{"htmlAst":{"type":"element","tagName":"div","properties":{},"children":[{"type":"element","tagName":"text-box","properties":{"variant":"learningObjectives","name":"Inlärningsmål"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Efter den här delen"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Kommer du veta vad ett objekt är i programmering"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Kommer du förstå vad som menas med oberoende hos individuella objekt"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Kommer du kunna skapa och komma åt objekt"}]},{"type":"text","value":"\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Detta är första delen av den Avancerade Kursen inom Programmering. Materialet är designat för att bli använt med Visual Studio Code editeraren, liksom den föregående kursen Introduktion till Programming. Ifall du inte använt Visual Studio Code tidigare, så hittar du installeringsinstruktionerna "},{"type":"element","tagName":"a","properties":{"href":"https://www.mooc.fi/fi/installation/vscode","target":"_blank","rel":["noopener","noreferrer"]},"children":[{"type":"text","value":"här"}]},{"type":"text","value":" och en introduktion till programmeringsomgivningen från förra kursen "},{"type":"element","tagName":"a","properties":{"href":"https://programming-24.mooc.fi/part-4/1-vscode","target":"_blank","rel":["noopener","noreferrer"]},"children":[{"type":"text","value":"här"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I introduktion till Programmering kursen så lade vi märke till att det ofta är logiskt att gruppera relaterad data tillsammans i våra program. Ifall vi till exemepl skulle förvara information om en bok skulle det vara logiskt att använda oss av en tupel eller en ordlista för att organisera datan till en enskild datastruktur."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Lösningen kunde se ut så här när man använder en tupel:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Kodningsboken\""}]},{"type":"text","value":"\nförfattare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter Python\""}]},{"type":"text","value":"\nar "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1992"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi sammanställer dessa i en ordlista"}]},{"type":"text","value":"\nbok "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" författare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" ar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi skriver ut bokens namn"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"bok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I ett fall som detta är fördelen med att använda en ordlista att vi kan använda strängar istället för indexar som nycklar. Alltså, kan vi ge deskriptiva namn till sakerna som förvaras datastrukturen:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Kodningsboken\""}]},{"type":"text","value":"\nforfattare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter Python\""}]},{"type":"text","value":"\nar "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1992"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Yhdistetään yhdeksi sanakirjaksi"}]},{"type":"text","value":"\nbok "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"författare\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" forfattare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"år\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" ar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi skriver ut bokens namn"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"bok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I båda fallen så skapar vi ett nytt "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"objekt"}]},{"type":"text","value":". Inom programmering har termen specifikt betydelsen av en oberoende helhet, i detta fall innehållande några bitar av data som på något vis är relaterade. Att vara oberoende betyder att ändringar till ett objekt inte påverkar andra objekt."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ifall vi skulle skapa två strukturellt identiska representationer av böcker, användandes ordlistor och identiska nycklar, skulle ändringar som görs till en av dem inte påverka den andra:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"bok1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Den gamle och Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"författare\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Ernest Pythonson\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"år\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1952"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\nbok2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Sju Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"författare\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Aleksis Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"år\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1894"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"bok1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"bok2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nbok1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Ett nytt namn\""}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"bok1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"bok2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Den gamle och Python\nSju Python\nEtt nytt namn\nSju Python"}]}]},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-wrapper"],"style":"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 341px; margin-bottom: 1rem;"},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"a","properties":{"className":["gatsby-resp-image-link"],"href":"/ohjelmointi-24-sv/static/74b678969e8df323e37bea6c8b4fae79/4c0ad/8_1_1.png","style":"display: block","target":"_blank","rel":["noopener"]},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-background-image"],"style":"padding-bottom: 45.65217391304348%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAAAsTAAALEwEAmpwYAAABRUlEQVQoz41Sa6uCUBD0//+U/oURERpaRollUmnlIx+V9qKay+zlXIg+eBeGg4tnZnfmaGip8/mMNE0RRRHKskQQBNhut0iSBGEYYrPZSJ/V7/ehrVYr+aFpGtR1/YHj8Yjlcon1eo1erwfTNOE4DgaDgYC9breL0WgkhOPxGBrVD4cD7vc7rtfrBy6Xi0wRx7Fcnk6nmM1mmM/nIlhVlYDTsmzbhvaflbkSL3ELnvy+3W4iqISfzyeGwyG01+sF4v1+f4HFSYqiwOl0Qp7nIsCpSMo+T4I9WtM6IQnVhCSl51mWYb/fy7nb7SQwTmxZFjSmRPAi1RVUKL7vC4kyn6HQT13XJSSeTPfxePx6yFCozlCooqBCYiBch/4sFgt5NkyenpGE/il7GFrryiQkmWEYmEwm8ly4muu6f6lzas/z0Ol08AM2IqK5S7nUBQAAAABJRU5ErkJggg=='); background-size: cover; display: block;"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"picture","properties":{},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/74b678969e8df323e37bea6c8b4fae79/a0b58/8_1_1.webp 230w","/ohjelmointi-24-sv/static/74b678969e8df323e37bea6c8b4fae79/5af35/8_1_1.webp 341w"],"sizes":"(max-width: 341px) 100vw, 341px","type":"image/webp"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/74b678969e8df323e37bea6c8b4fae79/81c8e/8_1_1.png 230w","/ohjelmointi-24-sv/static/74b678969e8df323e37bea6c8b4fae79/4c0ad/8_1_1.png 341w"],"sizes":"(max-width: 341px) 100vw, 341px","type":"image/png"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"img","properties":{"className":["gatsby-resp-image-image"],"src":"/ohjelmointi-24-sv/static/74b678969e8df323e37bea6c8b4fae79/4c0ad/8_1_1.png","alt":"8 1 1","title":"8 1 1","loading":"lazy","decoding":"async","style":"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"},"children":[]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"element","tagName":"text-box","properties":{"variant":"info","name":"Python objekt"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Du kanske kommer ihåg från introduktion till programmering kursen att vilket som helst värde i Python internt är behandlat som ett objekt. Detta betyder att värdet lagrat i en variabel är en "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"referens till ett objekt"}]},{"type":"text","value":". Själva datan är lagrad inuti ett objekt i datorns minne. Ifall du ger ett värde till en ny variable med kommandot "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"a = 3"}]},{"type":"text","value":", är värdet som lagras i variabeln "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"inte"}]},{"type":"text","value":" 3, utan en "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"referens till ett objekt som innehåller värdet 3"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"De flesta andra programmeringsspråk (i varje fall de som stöder objekt-orienterad programmering) inkluderar vissa särskilt definierade "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"primitiva datatyper"}]},{"type":"text","value":". Dessa inkluderar ofta åtminstone [integer] nummer, flyttals nummer och boleska sanningsvärden. Primitiver är processerade direkt, vilket betyder att de är lagrade direkt i variabler, inte som referenser. Python har inga sådana primitiver, men att jobba med de grundläggade datatyperna i Python är i praktiken väldigt liknande. Objekt av dessa grundläggande datatyper (såsom nummer, boleska värden och strängar) är "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"oföränderliga"}]},{"type":"text","value":", vilket betyder att de inte kan ändras i minnet. Ifall värdet som lagras i en variabel med en grundläggande datatyp måste ändras så byts hela referensen ut, men själva objektet kvarstår i minnet."}]}]},{"type":"element","tagName":"h2","properties":{"id":"objekt-och-metoder","style":"position:relative;"},"children":[{"type":"text","value":"Objekt och metoder"},{"type":"element","tagName":"a","properties":{"href":"#objekt-och-metoder","ariaLabel":"objekt och metoder permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Datan som lagras i ett objekt kan kommas åt genom olika "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"metoder"}]},{"type":"text","value":". En metod är en funktion som opererar på ett specifikt objekt som den är kopplad till. Sättet att åtskilja mellan metoder och andra funktioner ligger i hur de är kallade: först skriver man namnet på objektet som avses, sedan en punkt och till sist metodens namn, åtföljt av argument ifall sådana finns. Till exempel returnerar metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"values"}]},{"type":"text","value":" alla värden som är lagrade i ett objekt av typen ordlista eller "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"dict"}]},{"type":"text","value":":"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# detta skapar ett objekt av typen ordlista med namnet bok"}]},{"type":"text","value":"\nbok "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Den gamle och Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"författare\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Ernest Pythonson\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"år\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1952"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi skriver ut alla värden"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Metodkallelsen values() skrivs efter namnet på variabeln"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Kom ihåg punktnotation!"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" varde "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" bok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"values"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Den gamel och Python\nErnest Pythonson\n1952"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"På samma sätt opererar en strängmetod på det strängobjekt som den kallas på. Några exempel av strängmetoder är "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"count"}]},{"type":"text","value":" och "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"find"}]},{"type":"text","value":":"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Påhittige Per\""}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Skriv ut mängden P som förekommer"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"count"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"P\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Mängden P som hittas i en annan sträng"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Påhittade Praktiska Prepositioner\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"count"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"P\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Indexen av delsträngen Per"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"find"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Per\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Denna sträng har ingen matchande delsträng"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Helt annan sträng\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"find"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Per\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"2\n3\n10\n-1"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Strängmetoder returnerar värden, men ändrar inte innehållet av en sträng. Liksom nämnt ovan är strängar i Python oföränderliga. Detta gäller däremot inte alla metoder; Pythonlistor är föränderliga, alltså kan listmetoder ändra innehållet av listan som de kallas på:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"lista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi lägger till några element"}]},{"type":"text","value":"\nlista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nlista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi tar bort ett element från början"}]},{"type":"text","value":"\nlista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"pop"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[1, 2, 3, 5, 1]\n[2, 3, 5, 1]"}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Minsta medeltalet","tmcname":"osa08-01_minsta_medeltalet"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa funktionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"minsta_medeltalet(person1: dict, person2: dict, person3: dict)"}]},{"type":"text","value":", som får tre ordlistor som argument."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Varje ordlistsobjekt innehåller värden som refererar till följande nycklar:"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"text","value":": tävlarens namn"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"\"resultat1\""}]},{"type":"text","value":": tävlarens första resultat (heltal mellan 1...10)"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"\"resultat2\""}]},{"type":"text","value":": tävlarens andra resultat (liksom ovan)"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"\"resultat3\""}]},{"type":"text","value":": tävlarens tredje resultat (liksom ovan)"}]},{"type":"text","value":"\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska beräkna genomsnittet av de tre resultaten för varje tävlande och sedan returnera den tävlande vars genomsnittliga resultat var det minsta. Returvärdet bör vara hela ordlistsobjektet som innehåller information om deltagaren."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Du kan anta att endast en tävlare har det minsta medeltalet."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ett exempel på funktionen:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"person1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Ella\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"resultat1\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"resultat2\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"resultat3\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\nperson2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Bella\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"resultat1\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"resultat2\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"resultat3\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"8"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\nperson3 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Stella\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"resultat1\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"resultat2\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"resultat3\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"minsta_medeltalet"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"person1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" person2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" person3"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"{'namn': 'Stella', 'resultat1': 3, 'resultat2': 1, 'resultat3': 1}"}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Radernas summor","tmcname":"osa08-02_radernas_summor "},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I Python är varje värde som lagras i en variabel en referens till ett objekt, så varje värde som lagras i en lista är också en referens till ett objekt. Detta gäller även vid modellering av en matrisdatastruktur: varje värde i listan på högsta nivån är en referens till en annan lista, som i sin tur innehåller referenser till de objekt som representerar elementen i matrisen."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa funktionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"radernas_summor(matris: list)"}]},{"type":"text","value":", som tar en heltalsmatris som argument."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska lägga till ett nytt element på varje rad i matrisen. Detta element innehåller summan av de andra elementen på den raden. Funktionen har inget returvärde. Den bör modifiera matrisen i parametern."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ett exempel på funktionen i användning:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"matris "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\nradernas_summor"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"matris"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"matris"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[[1, 2, 3], [3, 4, 7]]"}]}]}]}]},"html":"

    Efter den här delen

      \n
    • Kommer du veta vad ett objekt är i programmering
    • \n
    • Kommer du förstå vad som menas med oberoende hos individuella objekt
    • \n
    • Kommer du kunna skapa och komma åt objekt
    • \n

    Detta är första delen av den Avancerade Kursen inom Programmering. Materialet är designat för att bli använt med Visual Studio Code editeraren, liksom den föregående kursen Introduktion till Programming. Ifall du inte använt Visual Studio Code tidigare, så hittar du installeringsinstruktionerna här och en introduktion till programmeringsomgivningen från förra kursen här.

    I introduktion till Programmering kursen så lade vi märke till att det ofta är logiskt att gruppera relaterad data tillsammans i våra program. Ifall vi till exemepl skulle förvara information om en bok skulle det vara logiskt att använda oss av en tupel eller en ordlista för att organisera datan till en enskild datastruktur.

    Lösningen kunde se ut så här när man använder en tupel:

    namn = \"Kodningsboken\"\nförfattare = \"Peter Python\"\nar = 1992\n\n# Vi sammanställer dessa i en ordlista\nbok = (namn, författare, ar)\n\n# Vi skriver ut bokens namn\nprint(bok[0])

    I ett fall som detta är fördelen med att använda en ordlista att vi kan använda strängar istället för indexar som nycklar. Alltså, kan vi ge deskriptiva namn till sakerna som förvaras datastrukturen:

    namn = \"Kodningsboken\"\nforfattare = \"Peter Python\"\nar = 1992\n\n# Yhdistetään yhdeksi sanakirjaksi\nbok = {\"namn\": namn, \"författare\": forfattare, \"år\": ar}\n\n# Vi skriver ut bokens namn\nprint(bok[\"namn\"])

    I båda fallen så skapar vi ett nytt objekt. Inom programmering har termen specifikt betydelsen av en oberoende helhet, i detta fall innehållande några bitar av data som på något vis är relaterade. Att vara oberoende betyder att ändringar till ett objekt inte påverkar andra objekt.

    Ifall vi skulle skapa två strukturellt identiska representationer av böcker, användandes ordlistor och identiska nycklar, skulle ändringar som görs till en av dem inte påverka den andra:

    bok1 = {\"namn\": \"Den gamle och Python\", \"författare\": \"Ernest Pythonson\", \"år\": 1952}\nbok2 = {\"namn\": \"Sju Python\", \"författare\": \"Aleksis Python\", \"år\": 1894}\n\nprint(bok1[\"namn\"])\nprint(bok2[\"namn\"])\n\nbok1[\"namn\"] = \"Ett nytt namn\"\n\nprint(bok1[\"namn\"])\nprint(bok2[\"namn\"])

    Den gamle och Python\nSju Python\nEtt nytt namn\nSju Python

    \n \n \n \n \n \n \"8\n \n \n

    Du kanske kommer ihåg från introduktion till programmering kursen att vilket som helst värde i Python internt är behandlat som ett objekt. Detta betyder att värdet lagrat i en variabel är en referens till ett objekt. Själva datan är lagrad inuti ett objekt i datorns minne. Ifall du ger ett värde till en ny variable med kommandot a = 3, är värdet som lagras i variabeln inte 3, utan en referens till ett objekt som innehåller värdet 3.

    De flesta andra programmeringsspråk (i varje fall de som stöder objekt-orienterad programmering) inkluderar vissa särskilt definierade primitiva datatyper. Dessa inkluderar ofta åtminstone [integer] nummer, flyttals nummer och boleska sanningsvärden. Primitiver är processerade direkt, vilket betyder att de är lagrade direkt i variabler, inte som referenser. Python har inga sådana primitiver, men att jobba med de grundläggade datatyperna i Python är i praktiken väldigt liknande. Objekt av dessa grundläggande datatyper (såsom nummer, boleska värden och strängar) är oföränderliga, vilket betyder att de inte kan ändras i minnet. Ifall värdet som lagras i en variabel med en grundläggande datatyp måste ändras så byts hela referensen ut, men själva objektet kvarstår i minnet.

    Objekt och metoder

    Datan som lagras i ett objekt kan kommas åt genom olika metoder. En metod är en funktion som opererar på ett specifikt objekt som den är kopplad till. Sättet att åtskilja mellan metoder och andra funktioner ligger i hur de är kallade: först skriver man namnet på objektet som avses, sedan en punkt och till sist metodens namn, åtföljt av argument ifall sådana finns. Till exempel returnerar metoden values alla värden som är lagrade i ett objekt av typen ordlista eller dict:

    # detta skapar ett objekt av typen ordlista med namnet bok\nbok = {\"namn\": \"Den gamle och Python\", \"författare\": \"Ernest Pythonson\", \"år\": 1952}\n\n# Vi skriver ut alla värden\n# Metodkallelsen values() skrivs efter namnet på variabeln\n# Kom ihåg punktnotation!\nfor varde in bok.values():\n    print(varde)

    Den gamel och Python\nErnest Pythonson\n1952

    På samma sätt opererar en strängmetod på det strängobjekt som den kallas på. Några exempel av strängmetoder är count och find:

    namn = \"Påhittige Per\"\n\n# Skriv ut mängden P som förekommer\nprint(namn.count(\"P\"))\n\n# Mängden P som hittas i en annan sträng\nprint(\"Påhittade Praktiska Prepositioner\".count(\"P\"))\n\n# Indexen av delsträngen Per\nprint(namn.find(\"Per\"))\n\n# Denna sträng har ingen matchande delsträng\nprint(\"Helt annan sträng\".find(\"Per\"))

    2\n3\n10\n-1

    Strängmetoder returnerar värden, men ändrar inte innehållet av en sträng. Liksom nämnt ovan är strängar i Python oföränderliga. Detta gäller däremot inte alla metoder; Pythonlistor är föränderliga, alltså kan listmetoder ändra innehållet av listan som de kallas på:

    lista = [1,2,3]\n\n# Vi lägger till några element\nlista.append(5)\nlista.append(1)\n\nprint(lista)\n\n# Vi tar bort ett element från början\nlista.pop(0)\n\nprint(lista)

    [1, 2, 3, 5, 1]\n[2, 3, 5, 1]

    Skapa funktionen minsta_medeltalet(person1: dict, person2: dict, person3: dict), som får tre ordlistor som argument.

    Varje ordlistsobjekt innehåller värden som refererar till följande nycklar:

      \n
    • \"namn\": tävlarens namn
    • \n
    • \"resultat1\": tävlarens första resultat (heltal mellan 1...10)
    • \n
    • \"resultat2\": tävlarens andra resultat (liksom ovan)
    • \n
    • \"resultat3\": tävlarens tredje resultat (liksom ovan)
    • \n

    Funktionen ska beräkna genomsnittet av de tre resultaten för varje tävlande och sedan returnera den tävlande vars genomsnittliga resultat var det minsta. Returvärdet bör vara hela ordlistsobjektet som innehåller information om deltagaren.

    Du kan anta att endast en tävlare har det minsta medeltalet.

    Ett exempel på funktionen:

    person1 = {\"namn\": \"Ella\", \"resultat1\": 2, \"resultat2\": 3, \"resultat3\": 3}\nperson2 = {\"namn\": \"Bella\", \"resultat1\": 5, \"resultat2\": 1, \"resultat3\": 8}\nperson3 = {\"namn\": \"Stella\", \"resultat1\": 3, \"resultat2\": 1, \"resultat3\": 1}\n\nprint(minsta_medeltalet(person1, person2, person3))

    {'namn': 'Stella', 'resultat1': 3, 'resultat2': 1, 'resultat3': 1}

    I Python är varje värde som lagras i en variabel en referens till ett objekt, så varje värde som lagras i en lista är också en referens till ett objekt. Detta gäller även vid modellering av en matrisdatastruktur: varje värde i listan på högsta nivån är en referens till en annan lista, som i sin tur innehåller referenser till de objekt som representerar elementen i matrisen.

    Skapa funktionen radernas_summor(matris: list), som tar en heltalsmatris som argument.

    Funktionen ska lägga till ett nytt element på varje rad i matrisen. Detta element innehåller summan av de andra elementen på den raden. Funktionen har inget returvärde. Den bör modifiera matrisen i parametern.

    Ett exempel på funktionen i användning:

    matris = [[1, 2], [3, 4]]\nradernas_summor(matris)\nprint(matris)

    [[1, 2, 3], [3, 4, 7]]

    ","frontmatter":{"path":"/osa-8/1-objekt-och-metoder","title":"Objekt och metoder"},"fileAbsolutePath":"/home/runner/work/ohjelmointi-24-sv/ohjelmointi-24-sv/data/osa-8/1-objekt-och-metoder.md"},"allPages":{"edges":[{"node":{"id":"b5e8ae41-d492-55f7-88a7-1c7292333ab1","frontmatter":{"path":"/arvostelu-ja-kokeet","title":"Arvostelu ja kokeet"}}},{"node":{"id":"af4df6be-211d-5ba1-acea-9edbefa06c49","frontmatter":{"path":"/frontmatter-guide","title":"Frontmatter-guide"}}},{"node":{"id":"56769133-4836-5fbb-a857-8fb0c6803e6d","frontmatter":{"path":"/","title":"Tietoa kurssista"}}},{"node":{"id":"e86762f0-c2a9-5598-aba3-2b8d7db7807c","frontmatter":{"path":"/kaikki-tehtavat","title":"Kaikki tehtävät"}}},{"node":{"id":"5d065309-85e8-5823-9527-ec1c3cf38d4d","frontmatter":{"path":"/tuki","title":"Tukea tehtäviin"}}},{"node":{"id":"ac195ee0-ad04-5cc9-9643-963f93d29ad2","frontmatter":{"path":"/usein-kysytyt-kysymykset","title":"Usein kysytyt kysymykset"}}},{"node":{"id":"51a165d7-8ce5-5d53-9c15-5321b6adef8c","frontmatter":{"path":"/verkkotentti","title":"Verkkotentti 4.6."}}},{"node":{"id":"4d9cf293-01e9-5e6c-a88f-599560e33c9a","frontmatter":{"path":"/verkkotentti-ohja","title":"Ohjelmoinnin jatkokurssin verkkotentti 16.12."}}},{"node":{"id":"279e1cca-fb0b-5d3f-b527-be05243d138d","frontmatter":{"path":"/verkkotentti-ohpe","title":"Ohjelmoinnin perusteiden verkkotentti 09.03."}}},{"node":{"id":"347bdde4-ba21-5f22-8a88-0287dfe29a45","frontmatter":{"path":"/virheilmoitukset","title":"Yleiset virheilmoitukset"}}},{"node":{"id":"3bf12e3a-1542-57f4-812d-dd32cebc99e2","frontmatter":{"path":"/sanasto","title":"Sanasto"}}},{"node":{"id":"9910673b-d62d-5d8d-a756-5267160d891f","frontmatter":{"path":"/osa-1/1-introduktion","title":"Introduktion"}}},{"node":{"id":"0b17a28e-f939-57cc-aa5b-4db407cdf34a","frontmatter":{"path":"/osa-1/2-info-fran-anvandaren","title":"Information från användaren"}}},{"node":{"id":"b95794f2-f3b3-597c-a4ec-6f023b584f81","frontmatter":{"path":"/osa-1/3-mer-om-variabler","title":"Mer om variabler"}}},{"node":{"id":"02cd0849-e7a5-5fd1-bf66-35f0197d3e75","frontmatter":{"path":"/osa-1/4-rakneoperationer","title":"Räkneoperationer"}}},{"node":{"id":"42690a69-3997-5b84-b999-15d9c3212884","frontmatter":{"path":"/osa-1/5-villkorssatser","title":"If-satser"}}},{"node":{"id":"96a0ec65-c0a3-5150-95c5-48c260f88162","frontmatter":{"path":"/osa-1","title":"Modul 1"}}},{"node":{"id":"e7a4d0c8-b8c1-53fa-ab51-9cc06fd417a3","frontmatter":{"path":"/osa-10/1-klasshierarkier","title":"Klasshierarkier"}}},{"node":{"id":"5f6d4b8b-7d05-5c79-9f2f-9e30b397167b","frontmatter":{"path":"/osa-10/2-atkamstmodifierare","title":"Åtkomstmodifierare"}}},{"node":{"id":"bb896c90-aabc-5a9d-8d4b-50839da286db","frontmatter":{"path":"/osa-10/3-objektorienterade-programmeringstekniker","title":"Objektorienterade programmeringstekniker"}}},{"node":{"id":"a2dca4f1-d64d-5e77-a3ca-8b2a208e9afa","frontmatter":{"path":"/osa-10/4-storre-applikation","title":"Att utveckla en större applikation"}}},{"node":{"id":"8c9cf5a7-f02e-5ccf-ab8f-f078c3ccecb6","frontmatter":{"path":"/osa-10","title":"Modul 10"}}},{"node":{"id":"f6688d26-5502-5c17-a8ee-db66f650f1f1","frontmatter":{"path":"/osa-11/1-list-comprehension","title":"List comprehension"}}},{"node":{"id":"1eac8489-72f2-5d53-904b-c960e2622018","frontmatter":{"path":"/osa-11/2-mer-om-comprehensions","title":"Mer om comprehensions"}}},{"node":{"id":"09630fca-7768-53f3-8aca-6e5ac638fc68","frontmatter":{"path":"/osa-11/3-rekursion","title":"Rekursion"}}},{"node":{"id":"70f6008e-a762-574c-a92a-c5c585d9677e","frontmatter":{"path":"/osa-11/4-lisaa-esimerkkeja","title":"Fler exempel på rekursion"}}},{"node":{"id":"eb8ed7d7-c39d-52db-949d-f75649498c67","frontmatter":{"path":"/osa-11","title":"Modul 11"}}},{"node":{"id":"9bba31dc-e14c-5400-a25b-7339107e9ba7","frontmatter":{"path":"/osa-12/1-funktioner-som-argument","title":"Funktioner som argument"}}},{"node":{"id":"5b9e4584-7234-5216-a118-d2a1bc617e13","frontmatter":{"path":"/osa-12/2-generatorer","title":"Generatorer"}}},{"node":{"id":"1d27636e-74f4-5c30-a1d8-08a303684945","frontmatter":{"path":"/osa-12/3-funktionell-programmering","title":"Funktionell programmering"}}},{"node":{"id":"6785750f-f145-5b88-81e9-b52e36ba53c6","frontmatter":{"path":"/osa-12/4-reguljara-uttryck","title":"Reguljära uttryck"}}},{"node":{"id":"d21df33a-4bf4-5ee3-9e2a-431d57561f09","frontmatter":{"path":"/osa-12","title":"Modul 12"}}},{"node":{"id":"14e3c129-50ec-581f-8679-8132248d41c1","frontmatter":{"path":"/osa-13/1-pygame","title":"Pygame"}}},{"node":{"id":"01bc3b9b-4f80-5561-8b56-3a7f09082263","frontmatter":{"path":"/osa-13/2-animation","title":"Animation"}}},{"node":{"id":"dd68786f-e2fc-5957-b47a-52b74c5199ef","frontmatter":{"path":"/osa-13/3-handelser","title":"Händelser"}}},{"node":{"id":"4a1aaa41-d6f7-51cd-8b89-95842cb9e02d","frontmatter":{"path":"/osa-13/4-fler-pygame-tekniker","title":"Fler pygame-tekniker"}}},{"node":{"id":"cdcf0ce1-e881-5ca6-8fa9-d0d343ec4e15","frontmatter":{"path":"/osa-13","title":"Modul 13"}}},{"node":{"id":"0ab28435-7654-5a8e-88d6-daa17d78103b","frontmatter":{"path":"/osa-14/1-spelprojekt","title":"Spelprojekt"}}},{"node":{"id":"b7a0628c-e4ba-583e-a52a-dd0ad78028d8","frontmatter":{"path":"/osa-14/2-robot-och-ladar","title":"Robot och lådor"}}},{"node":{"id":"6ccdbdff-7539-5a23-b23c-2ad48a99386f","frontmatter":{"path":"/osa-14/3-fardigstallande-av-spelet","title":"Färdigställande av spelet"}}},{"node":{"id":"1b505c9f-9b1b-58bd-8df7-553fef49cc8d","frontmatter":{"path":"/osa-14/4-ditt-eget-sepl","title":"Ditt eget spel"}}},{"node":{"id":"55c54859-8c7f-5fd9-8a8d-2c54ee677577","frontmatter":{"path":"/osa-14","title":"Modul 14"}}},{"node":{"id":"b5c346d1-d175-5824-98bb-4a4c3b45204d","frontmatter":{"path":"/osa-2/1-terminologi","title":"Programmeringsterminologi"}}},{"node":{"id":"db7188b0-0253-5c30-b8d2-0e115e235fb3","frontmatter":{"path":"/osa-2/2-else-elif","title":"Mera om if-satser"}}},{"node":{"id":"49d15928-f8b9-5883-9f29-86c307f6929e","frontmatter":{"path":"/osa-2/3-kombinera-villkor","title":"Kombinera villkor"}}},{"node":{"id":"93f1f9c8-6b27-5892-8bd4-7d1d008bf07a","frontmatter":{"path":"/osa-2/4-loopar","title":"Enkla loopar"}}},{"node":{"id":"5523b5b8-61f8-506d-bfe0-c6cc774390ce","frontmatter":{"path":"/osa-2","title":"Modul 2"}}},{"node":{"id":"02012307-c2a6-5cf2-9105-c10933c14b37","frontmatter":{"path":"/osa-3/1-loopar-med-villkor","title":"Loopar med villkor"}}},{"node":{"id":"efb889f4-4a19-515e-a0f6-4297d76a2757","frontmatter":{"path":"/osa-3/2-behandla-strangar","title":"Behandla strängar"}}},{"node":{"id":"a602077d-bbae-5eb7-a354-cc44b29ae96a","frontmatter":{"path":"/osa-3/3-mer-om-loopar","title":"Mera om loopar"}}},{"node":{"id":"6d878692-b9c7-57e6-ae58-044e5a6bef6f","frontmatter":{"path":"/osa-3/4-definiera-funktioner","title":"Definiera funktioner"}}},{"node":{"id":"682b5a18-73c5-56e2-8374-237baccbab40","frontmatter":{"path":"/osa-3","title":"Modul 3"}}},{"node":{"id":"3de95518-6b44-54db-9bcd-0c90a41d2fd5","frontmatter":{"path":"/osa-4/1-vscode","title":"Editorn Visual Studio Code, Pythontolken och det inbyggda debuggningsverktyget"}}},{"node":{"id":"7de9921c-7f94-58fe-84b9-7676dddb3b94","frontmatter":{"path":"/osa-4/2-mer-om-funktioner","title":"Mer om funktioner"}}},{"node":{"id":"29e29c69-360c-5f5c-8f34-5aef22eb327f","frontmatter":{"path":"/osa-4/3-listor","title":"Listor"}}},{"node":{"id":"bfe57880-0cbb-54e4-be9c-8fa180eafe6b","frontmatter":{"path":"/osa-4/4-iteration","title":"Iteration"}}},{"node":{"id":"2eab46f0-5373-5cbe-b2a0-1d071854a053","frontmatter":{"path":"/osa-4/5-utskrift","title":"Formatera utskrift"}}},{"node":{"id":"a5974fee-f2eb-5b89-88a5-6dd3754baaad","frontmatter":{"path":"/osa-4/6-strangar-listor","title":"Mera strängar och listor"}}},{"node":{"id":"e125c469-ee19-505e-9a41-83da6143ecd8","frontmatter":{"path":"/osa-4","title":"Modul 4"}}},{"node":{"id":"2558444a-be1d-5bc6-95ab-e091da2443fc","frontmatter":{"path":"/osa-5/1-mer-om-listor","title":"Mer om listor"}}},{"node":{"id":"b452d9be-0569-56c2-ba89-a040d4cb40dc","frontmatter":{"path":"/osa-5/2-referenser","title":"Referenser"}}},{"node":{"id":"ebe4ca3f-e657-5907-bfcc-ae84d9947aff","frontmatter":{"path":"/osa-5/3-lexikon","title":"Lexikon"}}},{"node":{"id":"f1dd5d66-ac87-5e53-92a0-0b7e3ece6ed8","frontmatter":{"path":"/osa-5/4-tuple","title":"Tuple"}}},{"node":{"id":"161c0109-5c00-5bed-b7af-90dc7ddf5713","frontmatter":{"path":"/osa-5","title":"Modul 5"}}},{"node":{"id":"e6cfa6e1-e99b-50e0-bc6a-3c0f153420e8","frontmatter":{"path":"/osa-6/1-lasa-filer","title":"Läsa filer"}}},{"node":{"id":"ce8d90a4-ca7c-5797-abc1-3fe0094bfa4b","frontmatter":{"path":"/osa-6/2-skriva-filer","title":"Skriva filer"}}},{"node":{"id":"519d5330-277a-59ba-be50-c2f63080df94","frontmatter":{"path":"/osa-6/3-fel","title":"Förbered dig på fel"}}},{"node":{"id":"82393756-3ef8-5d07-a8da-fed818ca43f0","frontmatter":{"path":"/osa-6/4-lokala-globala-variabler","title":"Lokala och globala variabler"}}},{"node":{"id":"007d85ae-a118-5b10-8a7e-18302b15eba8","frontmatter":{"path":"/osa-6","title":"Modul 6"}}},{"node":{"id":"bbb2346d-b1ee-551d-89c1-516f119b0eed","frontmatter":{"path":"/osa-7/1-moduler","title":"Moduler"}}},{"node":{"id":"ecb9af64-49f9-5e28-a544-3934e95233cf","frontmatter":{"path":"/osa-7/2-slumpmassighet","title":"Slumpmässighet"}}},{"node":{"id":"ebe469ef-c486-523a-9621-5dc4040c5cd8","frontmatter":{"path":"/osa-7/3-tid-datum","title":"Tid och datum"}}},{"node":{"id":"b9cf2d99-08f6-5de5-8425-c9b483241567","frontmatter":{"path":"/osa-7/4-behandla-data","title":"Behandla data"}}},{"node":{"id":"27075b37-8a6a-5554-9079-465a36d2da2d","frontmatter":{"path":"/osa-7/5-egna-moduler","title":"Skapa dina egna moduler"}}},{"node":{"id":"69492225-4d69-59ea-b33d-5301d35cf4ed","frontmatter":{"path":"/osa-7/6-funktionaliteter-python","title":"Flera funktionaliteter i Python"}}},{"node":{"id":"70ae841a-e6e9-5252-afae-6329fb67bcad","frontmatter":{"path":"/osa-7","title":"Modul 7"}}},{"node":{"id":"4afc4486-3cfe-53d1-b4c0-6db26484acfa","frontmatter":{"path":"/osa-8/1-objekt-och-metoder","title":"Objekt och metoder"}}},{"node":{"id":"6be37772-e94b-5b36-8a02-fffa7eef9feb","frontmatter":{"path":"/osa-8/2-klasser-och-objekt","title":"Klasser och objekt"}}},{"node":{"id":"8b6aec39-f8b9-525c-9f25-d8e73389fa42","frontmatter":{"path":"/osa-8/3-egna-klasser","title":"Egna klasser"}}},{"node":{"id":"85db460a-77c6-5087-8e97-a3c772186fd9","frontmatter":{"path":"/osa-8/4-metoder-i-egna-klasser","title":"Metoder i egna klasser"}}},{"node":{"id":"0e59dee0-5dd9-5827-83b9-a55e7d585c31","frontmatter":{"path":"/osa-8/5-fler-exempel","title":"Fler exempel"}}},{"node":{"id":"64715d0c-54f1-5aa7-a566-d2c5be6523ea","frontmatter":{"path":"/osa-8","title":"Modul 8"}}},{"node":{"id":"f7457509-a9a6-5420-8d03-ff1c61df8dc4","frontmatter":{"path":"/osa-9/1-objekt-och-referenser","title":"Objekt och referenser"}}},{"node":{"id":"16689ce4-b6aa-5bc4-9a30-44820994d6ea","frontmatter":{"path":"/osa-9/2-objekt-som-attribut","title":"Objekt som attribut "}}},{"node":{"id":"07985959-e85a-5f45-8923-babacb943c04","frontmatter":{"path":"/osa-9/3-inkapsling","title":"Inkapsling"}}},{"node":{"id":"83108600-9a37-5fd1-9a2b-13492879a9d6","frontmatter":{"path":"/osa-9/4-metodernas-rackvidd","title":"Metodernas räckvidd"}}},{"node":{"id":"a553cdc9-d6ac-5a14-ab43-d44811b407a2","frontmatter":{"path":"/osa-9/5-klassattribut","title":"Klassattribut"}}},{"node":{"id":"f7d7c9f1-6b54-5268-a308-995d49dd913d","frontmatter":{"path":"/osa-9/6-fler-exempel-med-klasser","title":"Fler exempel med klasser"}}},{"node":{"id":"c1fef3f7-8ca3-5780-9dec-19bd672b4627","frontmatter":{"path":"/osa-9","title":"Modul 9"}}}]}},"pageContext":{}}, + "result": {"data":{"page":{"htmlAst":{"type":"element","tagName":"div","properties":{},"children":[{"type":"element","tagName":"text-box","properties":{"variant":"learningObjectives","name":"Inlärningsmål"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Efter den här delen"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Kommer du veta vad ett objekt är i programmering"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Kommer du förstå vad som menas med oberoende hos individuella objekt"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Kommer du kunna skapa och komma åt objekt"}]},{"type":"text","value":"\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Detta är första delen av den Avancerade Kursen inom Programmering. Materialet är designat för att bli använt med Visual Studio Code editeraren, liksom den föregående kursen Introduktion till Programming. Ifall du inte använt Visual Studio Code tidigare, så hittar du installeringsinstruktionerna "},{"type":"element","tagName":"a","properties":{"href":"https://www.mooc.fi/fi/installation/vscode","target":"_blank","rel":["noopener","noreferrer"]},"children":[{"type":"text","value":"här"}]},{"type":"text","value":" och en introduktion till programmeringsomgivningen från förra kursen "},{"type":"element","tagName":"a","properties":{"href":"https://programming-24.mooc.fi/part-4/1-vscode","target":"_blank","rel":["noopener","noreferrer"]},"children":[{"type":"text","value":"här"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I introduktion till Programmering kursen så lade vi märke till att det ofta är logiskt att gruppera relaterad data tillsammans i våra program. Ifall vi till exemepl skulle förvara information om en bok skulle det vara logiskt att använda oss av en tupel eller en ordlista för att organisera datan till en enskild datastruktur."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Lösningen kunde se ut så här när man använder en tupel:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Kodningsboken\""}]},{"type":"text","value":"\nförfattare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter Python\""}]},{"type":"text","value":"\nar "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1992"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi sammanställer dessa i en ordlista"}]},{"type":"text","value":"\nbok "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" författare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" ar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi skriver ut bokens namn"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"bok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I ett fall som detta är fördelen med att använda en ordlista att vi kan använda strängar istället för indexar som nycklar. Alltså, kan vi ge deskriptiva namn till sakerna som förvaras datastrukturen:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Kodningsboken\""}]},{"type":"text","value":"\nforfattare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter Python\""}]},{"type":"text","value":"\nar "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1992"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Yhdistetään yhdeksi sanakirjaksi"}]},{"type":"text","value":"\nbok "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"författare\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" forfattare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"år\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" ar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi skriver ut bokens namn"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"bok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I båda fallen så skapar vi ett nytt "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"objekt"}]},{"type":"text","value":". Inom programmering har termen specifikt betydelsen av en oberoende helhet, i detta fall innehållande några bitar av data som på något vis är relaterade. Att vara oberoende betyder att ändringar till ett objekt inte påverkar andra objekt."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ifall vi skulle skapa två strukturellt identiska representationer av böcker, användandes ordlistor och identiska nycklar, skulle ändringar som görs till en av dem inte påverka den andra:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"bok1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Den gamle och Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"författare\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Ernest Pythonson\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"år\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1952"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\nbok2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Sju Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"författare\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Aleksis Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"år\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1894"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"bok1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"bok2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nbok1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Ett nytt namn\""}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"bok1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"bok2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Den gamle och Python\nSju Python\nEtt nytt namn\nSju Python"}]}]},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-wrapper"],"style":"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 341px; margin-bottom: 1rem;"},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"a","properties":{"className":["gatsby-resp-image-link"],"href":"/ohjelmointi-24-sv/static/a9810fa9a13874067832dc3cc67de74e/4c0ad/8_1_1.png","style":"display: block","target":"_blank","rel":["noopener"]},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-background-image"],"style":"padding-bottom: 45.65217391304348%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABgUlEQVQoz4WS646iQBCFef9n8QV2sln9MbPKCiITFVERL+gKcgcR8fJNaFezPyaxkpPTle7UOVXVEi8iSRIWiwWr1ZooCplOZ2w3GyxrLthx1ljWjJ3r0Wq1kFbLFX4QcCpLsiwjz/Mn0jRlYo5Ru13e39tYsym2bfP74wOlq6L3NZRulz+dDoZh0m53kAI/4HAoqKqKoig4Ho9PFMUR254zNgwmpkmv/8ntdnsK1gaiKCKOYrhBr6chvWo5y1L8vU+aJsRJIorUwg+UZSm4FlIUBel6vYrkO9RxOBzuLuKYMAzF+YE69zxPIAgClsvla4e1s3uBWLTpuS77vYfv70ni5P7on7im9ZA2jkMYRsJ6vYTHbGquNzydmOiaxo+3n8ymM8zxGK2n0vzVRNc/sefW/QeEIc1mC8l1XbIs53K5iKIPnE6lWMzf7RZn7QioqvrfbHPO5zN5lghD1akS9y9b3u12yLJMX9PoyDK6rjMYDBiNRgyHQ0aGIbj+To1Ggy+AFaTywUP64gAAAABJRU5ErkJggg=='); background-size: cover; display: block;"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"picture","properties":{},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/a9810fa9a13874067832dc3cc67de74e/a0b58/8_1_1.webp 230w","/ohjelmointi-24-sv/static/a9810fa9a13874067832dc3cc67de74e/5af35/8_1_1.webp 341w"],"sizes":"(max-width: 341px) 100vw, 341px","type":"image/webp"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/a9810fa9a13874067832dc3cc67de74e/81c8e/8_1_1.png 230w","/ohjelmointi-24-sv/static/a9810fa9a13874067832dc3cc67de74e/4c0ad/8_1_1.png 341w"],"sizes":"(max-width: 341px) 100vw, 341px","type":"image/png"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"img","properties":{"className":["gatsby-resp-image-image"],"src":"/ohjelmointi-24-sv/static/a9810fa9a13874067832dc3cc67de74e/4c0ad/8_1_1.png","alt":"8 1 1","title":"8 1 1","loading":"lazy","decoding":"async","style":"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"},"children":[]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"element","tagName":"text-box","properties":{"variant":"info","name":"Python objekt"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Du kanske kommer ihåg från introduktion till programmering kursen att vilket som helst värde i Python internt är behandlat som ett objekt. Detta betyder att värdet lagrat i en variabel är en "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"referens till ett objekt"}]},{"type":"text","value":". Själva datan är lagrad inuti ett objekt i datorns minne. Ifall du ger ett värde till en ny variable med kommandot "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"a = 3"}]},{"type":"text","value":", är värdet som lagras i variabeln "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"inte"}]},{"type":"text","value":" 3, utan en "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"referens till ett objekt som innehåller värdet 3"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"De flesta andra programmeringsspråk (i varje fall de som stöder objekt-orienterad programmering) inkluderar vissa särskilt definierade "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"primitiva datatyper"}]},{"type":"text","value":". Dessa inkluderar ofta åtminstone [integer] nummer, flyttals nummer och boleska sanningsvärden. Primitiver är processerade direkt, vilket betyder att de är lagrade direkt i variabler, inte som referenser. Python har inga sådana primitiver, men att jobba med de grundläggade datatyperna i Python är i praktiken väldigt liknande. Objekt av dessa grundläggande datatyper (såsom nummer, boleska värden och strängar) är "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"oföränderliga"}]},{"type":"text","value":", vilket betyder att de inte kan ändras i minnet. Ifall värdet som lagras i en variabel med en grundläggande datatyp måste ändras så byts hela referensen ut, men själva objektet kvarstår i minnet."}]}]},{"type":"element","tagName":"h2","properties":{"id":"objekt-och-metoder","style":"position:relative;"},"children":[{"type":"text","value":"Objekt och metoder"},{"type":"element","tagName":"a","properties":{"href":"#objekt-och-metoder","ariaLabel":"objekt och metoder permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Datan som lagras i ett objekt kan kommas åt genom olika "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"metoder"}]},{"type":"text","value":". En metod är en funktion som opererar på ett specifikt objekt som den är kopplad till. Sättet att åtskilja mellan metoder och andra funktioner ligger i hur de är kallade: först skriver man namnet på objektet som avses, sedan en punkt och till sist metodens namn, åtföljt av argument ifall sådana finns. Till exempel returnerar metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"values"}]},{"type":"text","value":" alla värden som är lagrade i ett objekt av typen ordlista eller "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"dict"}]},{"type":"text","value":":"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# detta skapar ett objekt av typen ordlista med namnet bok"}]},{"type":"text","value":"\nbok "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Den gamle och Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"författare\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Ernest Pythonson\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"år\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1952"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi skriver ut alla värden"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Metodkallelsen values() skrivs efter namnet på variabeln"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Kom ihåg punktnotation!"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" varde "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" bok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"values"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Den gamel och Python\nErnest Pythonson\n1952"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"På samma sätt opererar en strängmetod på det strängobjekt som den kallas på. Några exempel av strängmetoder är "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"count"}]},{"type":"text","value":" och "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"find"}]},{"type":"text","value":":"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Påhittige Per\""}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Skriv ut mängden P som förekommer"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"count"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"P\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Mängden P som hittas i en annan sträng"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Påhittade Praktiska Prepositioner\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"count"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"P\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Indexen av delsträngen Per"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"find"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Per\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Denna sträng har ingen matchande delsträng"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Helt annan sträng\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"find"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Per\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"2\n3\n10\n-1"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Strängmetoder returnerar värden, men ändrar inte innehållet av en sträng. Liksom nämnt ovan är strängar i Python oföränderliga. Detta gäller däremot inte alla metoder; Pythonlistor är föränderliga, alltså kan listmetoder ändra innehållet av listan som de kallas på:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"lista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi lägger till några element"}]},{"type":"text","value":"\nlista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nlista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi tar bort ett element från början"}]},{"type":"text","value":"\nlista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"pop"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[1, 2, 3, 5, 1]\n[2, 3, 5, 1]"}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Minsta medeltalet","tmcname":"osa08-01_minsta_medeltalet"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa funktionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"minsta_medeltalet(person1: dict, person2: dict, person3: dict)"}]},{"type":"text","value":", som får tre ordlistor som argument."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Varje ordlistsobjekt innehåller värden som refererar till följande nycklar:"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"text","value":": tävlarens namn"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"\"resultat1\""}]},{"type":"text","value":": tävlarens första resultat (heltal mellan 1...10)"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"\"resultat2\""}]},{"type":"text","value":": tävlarens andra resultat (liksom ovan)"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"\"resultat3\""}]},{"type":"text","value":": tävlarens tredje resultat (liksom ovan)"}]},{"type":"text","value":"\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska beräkna genomsnittet av de tre resultaten för varje tävlande och sedan returnera den tävlande vars genomsnittliga resultat var det minsta. Returvärdet bör vara hela ordlistsobjektet som innehåller information om deltagaren."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Du kan anta att endast en tävlare har det minsta medeltalet."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ett exempel på funktionen:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"person1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Ella\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"resultat1\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"resultat2\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"resultat3\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\nperson2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Bella\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"resultat1\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"resultat2\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"resultat3\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"8"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\nperson3 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"namn\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Stella\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"resultat1\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"resultat2\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"resultat3\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"minsta_medeltalet"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"person1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" person2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" person3"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"{'namn': 'Stella', 'resultat1': 3, 'resultat2': 1, 'resultat3': 1}"}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Radernas summor","tmcname":"osa08-02_radernas_summor "},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I Python är varje värde som lagras i en variabel en referens till ett objekt, så varje värde som lagras i en lista är också en referens till ett objekt. Detta gäller även vid modellering av en matrisdatastruktur: varje värde i listan på högsta nivån är en referens till en annan lista, som i sin tur innehåller referenser till de objekt som representerar elementen i matrisen."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa funktionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"radernas_summor(matris: list)"}]},{"type":"text","value":", som tar en heltalsmatris som argument."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska lägga till ett nytt element på varje rad i matrisen. Detta element innehåller summan av de andra elementen på den raden. Funktionen har inget returvärde. Den bör modifiera matrisen i parametern."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ett exempel på funktionen i användning:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"matris "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\nradernas_summor"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"matris"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"matris"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[[1, 2, 3], [3, 4, 7]]"}]}]}]}]},"html":"

    Efter den här delen

      \n
    • Kommer du veta vad ett objekt är i programmering
    • \n
    • Kommer du förstå vad som menas med oberoende hos individuella objekt
    • \n
    • Kommer du kunna skapa och komma åt objekt
    • \n

    Detta är första delen av den Avancerade Kursen inom Programmering. Materialet är designat för att bli använt med Visual Studio Code editeraren, liksom den föregående kursen Introduktion till Programming. Ifall du inte använt Visual Studio Code tidigare, så hittar du installeringsinstruktionerna här och en introduktion till programmeringsomgivningen från förra kursen här.

    I introduktion till Programmering kursen så lade vi märke till att det ofta är logiskt att gruppera relaterad data tillsammans i våra program. Ifall vi till exemepl skulle förvara information om en bok skulle det vara logiskt att använda oss av en tupel eller en ordlista för att organisera datan till en enskild datastruktur.

    Lösningen kunde se ut så här när man använder en tupel:

    namn = \"Kodningsboken\"\nförfattare = \"Peter Python\"\nar = 1992\n\n# Vi sammanställer dessa i en ordlista\nbok = (namn, författare, ar)\n\n# Vi skriver ut bokens namn\nprint(bok[0])

    I ett fall som detta är fördelen med att använda en ordlista att vi kan använda strängar istället för indexar som nycklar. Alltså, kan vi ge deskriptiva namn till sakerna som förvaras datastrukturen:

    namn = \"Kodningsboken\"\nforfattare = \"Peter Python\"\nar = 1992\n\n# Yhdistetään yhdeksi sanakirjaksi\nbok = {\"namn\": namn, \"författare\": forfattare, \"år\": ar}\n\n# Vi skriver ut bokens namn\nprint(bok[\"namn\"])

    I båda fallen så skapar vi ett nytt objekt. Inom programmering har termen specifikt betydelsen av en oberoende helhet, i detta fall innehållande några bitar av data som på något vis är relaterade. Att vara oberoende betyder att ändringar till ett objekt inte påverkar andra objekt.

    Ifall vi skulle skapa två strukturellt identiska representationer av böcker, användandes ordlistor och identiska nycklar, skulle ändringar som görs till en av dem inte påverka den andra:

    bok1 = {\"namn\": \"Den gamle och Python\", \"författare\": \"Ernest Pythonson\", \"år\": 1952}\nbok2 = {\"namn\": \"Sju Python\", \"författare\": \"Aleksis Python\", \"år\": 1894}\n\nprint(bok1[\"namn\"])\nprint(bok2[\"namn\"])\n\nbok1[\"namn\"] = \"Ett nytt namn\"\n\nprint(bok1[\"namn\"])\nprint(bok2[\"namn\"])

    Den gamle och Python\nSju Python\nEtt nytt namn\nSju Python

    \n \n \n \n \n \n \"8\n \n \n

    Du kanske kommer ihåg från introduktion till programmering kursen att vilket som helst värde i Python internt är behandlat som ett objekt. Detta betyder att värdet lagrat i en variabel är en referens till ett objekt. Själva datan är lagrad inuti ett objekt i datorns minne. Ifall du ger ett värde till en ny variable med kommandot a = 3, är värdet som lagras i variabeln inte 3, utan en referens till ett objekt som innehåller värdet 3.

    De flesta andra programmeringsspråk (i varje fall de som stöder objekt-orienterad programmering) inkluderar vissa särskilt definierade primitiva datatyper. Dessa inkluderar ofta åtminstone [integer] nummer, flyttals nummer och boleska sanningsvärden. Primitiver är processerade direkt, vilket betyder att de är lagrade direkt i variabler, inte som referenser. Python har inga sådana primitiver, men att jobba med de grundläggade datatyperna i Python är i praktiken väldigt liknande. Objekt av dessa grundläggande datatyper (såsom nummer, boleska värden och strängar) är oföränderliga, vilket betyder att de inte kan ändras i minnet. Ifall värdet som lagras i en variabel med en grundläggande datatyp måste ändras så byts hela referensen ut, men själva objektet kvarstår i minnet.

    Objekt och metoder

    Datan som lagras i ett objekt kan kommas åt genom olika metoder. En metod är en funktion som opererar på ett specifikt objekt som den är kopplad till. Sättet att åtskilja mellan metoder och andra funktioner ligger i hur de är kallade: först skriver man namnet på objektet som avses, sedan en punkt och till sist metodens namn, åtföljt av argument ifall sådana finns. Till exempel returnerar metoden values alla värden som är lagrade i ett objekt av typen ordlista eller dict:

    # detta skapar ett objekt av typen ordlista med namnet bok\nbok = {\"namn\": \"Den gamle och Python\", \"författare\": \"Ernest Pythonson\", \"år\": 1952}\n\n# Vi skriver ut alla värden\n# Metodkallelsen values() skrivs efter namnet på variabeln\n# Kom ihåg punktnotation!\nfor varde in bok.values():\n    print(varde)

    Den gamel och Python\nErnest Pythonson\n1952

    På samma sätt opererar en strängmetod på det strängobjekt som den kallas på. Några exempel av strängmetoder är count och find:

    namn = \"Påhittige Per\"\n\n# Skriv ut mängden P som förekommer\nprint(namn.count(\"P\"))\n\n# Mängden P som hittas i en annan sträng\nprint(\"Påhittade Praktiska Prepositioner\".count(\"P\"))\n\n# Indexen av delsträngen Per\nprint(namn.find(\"Per\"))\n\n# Denna sträng har ingen matchande delsträng\nprint(\"Helt annan sträng\".find(\"Per\"))

    2\n3\n10\n-1

    Strängmetoder returnerar värden, men ändrar inte innehållet av en sträng. Liksom nämnt ovan är strängar i Python oföränderliga. Detta gäller däremot inte alla metoder; Pythonlistor är föränderliga, alltså kan listmetoder ändra innehållet av listan som de kallas på:

    lista = [1,2,3]\n\n# Vi lägger till några element\nlista.append(5)\nlista.append(1)\n\nprint(lista)\n\n# Vi tar bort ett element från början\nlista.pop(0)\n\nprint(lista)

    [1, 2, 3, 5, 1]\n[2, 3, 5, 1]

    Skapa funktionen minsta_medeltalet(person1: dict, person2: dict, person3: dict), som får tre ordlistor som argument.

    Varje ordlistsobjekt innehåller värden som refererar till följande nycklar:

      \n
    • \"namn\": tävlarens namn
    • \n
    • \"resultat1\": tävlarens första resultat (heltal mellan 1...10)
    • \n
    • \"resultat2\": tävlarens andra resultat (liksom ovan)
    • \n
    • \"resultat3\": tävlarens tredje resultat (liksom ovan)
    • \n

    Funktionen ska beräkna genomsnittet av de tre resultaten för varje tävlande och sedan returnera den tävlande vars genomsnittliga resultat var det minsta. Returvärdet bör vara hela ordlistsobjektet som innehåller information om deltagaren.

    Du kan anta att endast en tävlare har det minsta medeltalet.

    Ett exempel på funktionen:

    person1 = {\"namn\": \"Ella\", \"resultat1\": 2, \"resultat2\": 3, \"resultat3\": 3}\nperson2 = {\"namn\": \"Bella\", \"resultat1\": 5, \"resultat2\": 1, \"resultat3\": 8}\nperson3 = {\"namn\": \"Stella\", \"resultat1\": 3, \"resultat2\": 1, \"resultat3\": 1}\n\nprint(minsta_medeltalet(person1, person2, person3))

    {'namn': 'Stella', 'resultat1': 3, 'resultat2': 1, 'resultat3': 1}

    I Python är varje värde som lagras i en variabel en referens till ett objekt, så varje värde som lagras i en lista är också en referens till ett objekt. Detta gäller även vid modellering av en matrisdatastruktur: varje värde i listan på högsta nivån är en referens till en annan lista, som i sin tur innehåller referenser till de objekt som representerar elementen i matrisen.

    Skapa funktionen radernas_summor(matris: list), som tar en heltalsmatris som argument.

    Funktionen ska lägga till ett nytt element på varje rad i matrisen. Detta element innehåller summan av de andra elementen på den raden. Funktionen har inget returvärde. Den bör modifiera matrisen i parametern.

    Ett exempel på funktionen i användning:

    matris = [[1, 2], [3, 4]]\nradernas_summor(matris)\nprint(matris)

    [[1, 2, 3], [3, 4, 7]]

    ","frontmatter":{"path":"/osa-8/1-objekt-och-metoder","title":"Objekt och metoder"},"fileAbsolutePath":"/home/runner/work/ohjelmointi-24-sv/ohjelmointi-24-sv/data/osa-8/1-objekt-och-metoder.md"},"allPages":{"edges":[{"node":{"id":"b5e8ae41-d492-55f7-88a7-1c7292333ab1","frontmatter":{"path":"/arvostelu-ja-kokeet","title":"Arvostelu ja kokeet"}}},{"node":{"id":"af4df6be-211d-5ba1-acea-9edbefa06c49","frontmatter":{"path":"/frontmatter-guide","title":"Frontmatter-guide"}}},{"node":{"id":"56769133-4836-5fbb-a857-8fb0c6803e6d","frontmatter":{"path":"/","title":"Tietoa kurssista"}}},{"node":{"id":"e86762f0-c2a9-5598-aba3-2b8d7db7807c","frontmatter":{"path":"/kaikki-tehtavat","title":"Kaikki tehtävät"}}},{"node":{"id":"5d065309-85e8-5823-9527-ec1c3cf38d4d","frontmatter":{"path":"/tuki","title":"Tukea tehtäviin"}}},{"node":{"id":"ac195ee0-ad04-5cc9-9643-963f93d29ad2","frontmatter":{"path":"/usein-kysytyt-kysymykset","title":"Usein kysytyt kysymykset"}}},{"node":{"id":"51a165d7-8ce5-5d53-9c15-5321b6adef8c","frontmatter":{"path":"/verkkotentti","title":"Verkkotentti 4.6."}}},{"node":{"id":"4d9cf293-01e9-5e6c-a88f-599560e33c9a","frontmatter":{"path":"/verkkotentti-ohja","title":"Ohjelmoinnin jatkokurssin verkkotentti 16.12."}}},{"node":{"id":"279e1cca-fb0b-5d3f-b527-be05243d138d","frontmatter":{"path":"/verkkotentti-ohpe","title":"Ohjelmoinnin perusteiden verkkotentti 09.03."}}},{"node":{"id":"347bdde4-ba21-5f22-8a88-0287dfe29a45","frontmatter":{"path":"/virheilmoitukset","title":"Yleiset virheilmoitukset"}}},{"node":{"id":"3bf12e3a-1542-57f4-812d-dd32cebc99e2","frontmatter":{"path":"/sanasto","title":"Sanasto"}}},{"node":{"id":"9910673b-d62d-5d8d-a756-5267160d891f","frontmatter":{"path":"/osa-1/1-introduktion","title":"Introduktion"}}},{"node":{"id":"0b17a28e-f939-57cc-aa5b-4db407cdf34a","frontmatter":{"path":"/osa-1/2-info-fran-anvandaren","title":"Information från användaren"}}},{"node":{"id":"b95794f2-f3b3-597c-a4ec-6f023b584f81","frontmatter":{"path":"/osa-1/3-mer-om-variabler","title":"Mer om variabler"}}},{"node":{"id":"02cd0849-e7a5-5fd1-bf66-35f0197d3e75","frontmatter":{"path":"/osa-1/4-rakneoperationer","title":"Räkneoperationer"}}},{"node":{"id":"42690a69-3997-5b84-b999-15d9c3212884","frontmatter":{"path":"/osa-1/5-villkorssatser","title":"If-satser"}}},{"node":{"id":"96a0ec65-c0a3-5150-95c5-48c260f88162","frontmatter":{"path":"/osa-1","title":"Modul 1"}}},{"node":{"id":"e7a4d0c8-b8c1-53fa-ab51-9cc06fd417a3","frontmatter":{"path":"/osa-10/1-klasshierarkier","title":"Klasshierarkier"}}},{"node":{"id":"5f6d4b8b-7d05-5c79-9f2f-9e30b397167b","frontmatter":{"path":"/osa-10/2-atkamstmodifierare","title":"Åtkomstmodifierare"}}},{"node":{"id":"bb896c90-aabc-5a9d-8d4b-50839da286db","frontmatter":{"path":"/osa-10/3-objektorienterade-programmeringstekniker","title":"Objektorienterade programmeringstekniker"}}},{"node":{"id":"a2dca4f1-d64d-5e77-a3ca-8b2a208e9afa","frontmatter":{"path":"/osa-10/4-storre-applikation","title":"Att utveckla en större applikation"}}},{"node":{"id":"8c9cf5a7-f02e-5ccf-ab8f-f078c3ccecb6","frontmatter":{"path":"/osa-10","title":"Modul 10"}}},{"node":{"id":"f6688d26-5502-5c17-a8ee-db66f650f1f1","frontmatter":{"path":"/osa-11/1-list-comprehension","title":"List comprehension"}}},{"node":{"id":"1eac8489-72f2-5d53-904b-c960e2622018","frontmatter":{"path":"/osa-11/2-mer-om-comprehensions","title":"Mer om comprehensions"}}},{"node":{"id":"09630fca-7768-53f3-8aca-6e5ac638fc68","frontmatter":{"path":"/osa-11/3-rekursion","title":"Rekursion"}}},{"node":{"id":"70f6008e-a762-574c-a92a-c5c585d9677e","frontmatter":{"path":"/osa-11/4-lisaa-esimerkkeja","title":"Fler exempel på rekursion"}}},{"node":{"id":"eb8ed7d7-c39d-52db-949d-f75649498c67","frontmatter":{"path":"/osa-11","title":"Modul 11"}}},{"node":{"id":"9bba31dc-e14c-5400-a25b-7339107e9ba7","frontmatter":{"path":"/osa-12/1-funktioner-som-argument","title":"Funktioner som argument"}}},{"node":{"id":"5b9e4584-7234-5216-a118-d2a1bc617e13","frontmatter":{"path":"/osa-12/2-generatorer","title":"Generatorer"}}},{"node":{"id":"1d27636e-74f4-5c30-a1d8-08a303684945","frontmatter":{"path":"/osa-12/3-funktionell-programmering","title":"Funktionell programmering"}}},{"node":{"id":"6785750f-f145-5b88-81e9-b52e36ba53c6","frontmatter":{"path":"/osa-12/4-reguljara-uttryck","title":"Reguljära uttryck"}}},{"node":{"id":"d21df33a-4bf4-5ee3-9e2a-431d57561f09","frontmatter":{"path":"/osa-12","title":"Modul 12"}}},{"node":{"id":"14e3c129-50ec-581f-8679-8132248d41c1","frontmatter":{"path":"/osa-13/1-pygame","title":"Pygame"}}},{"node":{"id":"01bc3b9b-4f80-5561-8b56-3a7f09082263","frontmatter":{"path":"/osa-13/2-animation","title":"Animation"}}},{"node":{"id":"dd68786f-e2fc-5957-b47a-52b74c5199ef","frontmatter":{"path":"/osa-13/3-handelser","title":"Händelser"}}},{"node":{"id":"4a1aaa41-d6f7-51cd-8b89-95842cb9e02d","frontmatter":{"path":"/osa-13/4-fler-pygame-tekniker","title":"Fler pygame-tekniker"}}},{"node":{"id":"cdcf0ce1-e881-5ca6-8fa9-d0d343ec4e15","frontmatter":{"path":"/osa-13","title":"Modul 13"}}},{"node":{"id":"0ab28435-7654-5a8e-88d6-daa17d78103b","frontmatter":{"path":"/osa-14/1-spelprojekt","title":"Spelprojekt"}}},{"node":{"id":"b7a0628c-e4ba-583e-a52a-dd0ad78028d8","frontmatter":{"path":"/osa-14/2-robot-och-ladar","title":"Robot och lådor"}}},{"node":{"id":"6ccdbdff-7539-5a23-b23c-2ad48a99386f","frontmatter":{"path":"/osa-14/3-fardigstallande-av-spelet","title":"Färdigställande av spelet"}}},{"node":{"id":"1b505c9f-9b1b-58bd-8df7-553fef49cc8d","frontmatter":{"path":"/osa-14/4-ditt-eget-sepl","title":"Ditt eget spel"}}},{"node":{"id":"55c54859-8c7f-5fd9-8a8d-2c54ee677577","frontmatter":{"path":"/osa-14","title":"Modul 14"}}},{"node":{"id":"b5c346d1-d175-5824-98bb-4a4c3b45204d","frontmatter":{"path":"/osa-2/1-terminologi","title":"Programmeringsterminologi"}}},{"node":{"id":"db7188b0-0253-5c30-b8d2-0e115e235fb3","frontmatter":{"path":"/osa-2/2-else-elif","title":"Mera om if-satser"}}},{"node":{"id":"49d15928-f8b9-5883-9f29-86c307f6929e","frontmatter":{"path":"/osa-2/3-kombinera-villkor","title":"Kombinera villkor"}}},{"node":{"id":"93f1f9c8-6b27-5892-8bd4-7d1d008bf07a","frontmatter":{"path":"/osa-2/4-loopar","title":"Enkla loopar"}}},{"node":{"id":"5523b5b8-61f8-506d-bfe0-c6cc774390ce","frontmatter":{"path":"/osa-2","title":"Modul 2"}}},{"node":{"id":"02012307-c2a6-5cf2-9105-c10933c14b37","frontmatter":{"path":"/osa-3/1-loopar-med-villkor","title":"Loopar med villkor"}}},{"node":{"id":"efb889f4-4a19-515e-a0f6-4297d76a2757","frontmatter":{"path":"/osa-3/2-behandla-strangar","title":"Behandla strängar"}}},{"node":{"id":"a602077d-bbae-5eb7-a354-cc44b29ae96a","frontmatter":{"path":"/osa-3/3-mer-om-loopar","title":"Mera om loopar"}}},{"node":{"id":"6d878692-b9c7-57e6-ae58-044e5a6bef6f","frontmatter":{"path":"/osa-3/4-definiera-funktioner","title":"Definiera funktioner"}}},{"node":{"id":"682b5a18-73c5-56e2-8374-237baccbab40","frontmatter":{"path":"/osa-3","title":"Modul 3"}}},{"node":{"id":"3de95518-6b44-54db-9bcd-0c90a41d2fd5","frontmatter":{"path":"/osa-4/1-vscode","title":"Editorn Visual Studio Code, Pythontolken och det inbyggda debuggningsverktyget"}}},{"node":{"id":"7de9921c-7f94-58fe-84b9-7676dddb3b94","frontmatter":{"path":"/osa-4/2-mer-om-funktioner","title":"Mer om funktioner"}}},{"node":{"id":"29e29c69-360c-5f5c-8f34-5aef22eb327f","frontmatter":{"path":"/osa-4/3-listor","title":"Listor"}}},{"node":{"id":"bfe57880-0cbb-54e4-be9c-8fa180eafe6b","frontmatter":{"path":"/osa-4/4-iteration","title":"Iteration"}}},{"node":{"id":"2eab46f0-5373-5cbe-b2a0-1d071854a053","frontmatter":{"path":"/osa-4/5-utskrift","title":"Formatera utskrift"}}},{"node":{"id":"a5974fee-f2eb-5b89-88a5-6dd3754baaad","frontmatter":{"path":"/osa-4/6-strangar-listor","title":"Mera strängar och listor"}}},{"node":{"id":"e125c469-ee19-505e-9a41-83da6143ecd8","frontmatter":{"path":"/osa-4","title":"Modul 4"}}},{"node":{"id":"2558444a-be1d-5bc6-95ab-e091da2443fc","frontmatter":{"path":"/osa-5/1-mer-om-listor","title":"Mer om listor"}}},{"node":{"id":"b452d9be-0569-56c2-ba89-a040d4cb40dc","frontmatter":{"path":"/osa-5/2-referenser","title":"Referenser"}}},{"node":{"id":"ebe4ca3f-e657-5907-bfcc-ae84d9947aff","frontmatter":{"path":"/osa-5/3-lexikon","title":"Lexikon"}}},{"node":{"id":"f1dd5d66-ac87-5e53-92a0-0b7e3ece6ed8","frontmatter":{"path":"/osa-5/4-tuple","title":"Tuple"}}},{"node":{"id":"161c0109-5c00-5bed-b7af-90dc7ddf5713","frontmatter":{"path":"/osa-5","title":"Modul 5"}}},{"node":{"id":"e6cfa6e1-e99b-50e0-bc6a-3c0f153420e8","frontmatter":{"path":"/osa-6/1-lasa-filer","title":"Läsa filer"}}},{"node":{"id":"ce8d90a4-ca7c-5797-abc1-3fe0094bfa4b","frontmatter":{"path":"/osa-6/2-skriva-filer","title":"Skriva filer"}}},{"node":{"id":"519d5330-277a-59ba-be50-c2f63080df94","frontmatter":{"path":"/osa-6/3-fel","title":"Förbered dig på fel"}}},{"node":{"id":"82393756-3ef8-5d07-a8da-fed818ca43f0","frontmatter":{"path":"/osa-6/4-lokala-globala-variabler","title":"Lokala och globala variabler"}}},{"node":{"id":"007d85ae-a118-5b10-8a7e-18302b15eba8","frontmatter":{"path":"/osa-6","title":"Modul 6"}}},{"node":{"id":"bbb2346d-b1ee-551d-89c1-516f119b0eed","frontmatter":{"path":"/osa-7/1-moduler","title":"Moduler"}}},{"node":{"id":"ecb9af64-49f9-5e28-a544-3934e95233cf","frontmatter":{"path":"/osa-7/2-slumpmassighet","title":"Slumpmässighet"}}},{"node":{"id":"ebe469ef-c486-523a-9621-5dc4040c5cd8","frontmatter":{"path":"/osa-7/3-tid-datum","title":"Tid och datum"}}},{"node":{"id":"b9cf2d99-08f6-5de5-8425-c9b483241567","frontmatter":{"path":"/osa-7/4-behandla-data","title":"Behandla data"}}},{"node":{"id":"27075b37-8a6a-5554-9079-465a36d2da2d","frontmatter":{"path":"/osa-7/5-egna-moduler","title":"Skapa dina egna moduler"}}},{"node":{"id":"69492225-4d69-59ea-b33d-5301d35cf4ed","frontmatter":{"path":"/osa-7/6-funktionaliteter-python","title":"Flera funktionaliteter i Python"}}},{"node":{"id":"70ae841a-e6e9-5252-afae-6329fb67bcad","frontmatter":{"path":"/osa-7","title":"Modul 7"}}},{"node":{"id":"4afc4486-3cfe-53d1-b4c0-6db26484acfa","frontmatter":{"path":"/osa-8/1-objekt-och-metoder","title":"Objekt och metoder"}}},{"node":{"id":"6be37772-e94b-5b36-8a02-fffa7eef9feb","frontmatter":{"path":"/osa-8/2-klasser-och-objekt","title":"Klasser och objekt"}}},{"node":{"id":"8b6aec39-f8b9-525c-9f25-d8e73389fa42","frontmatter":{"path":"/osa-8/3-egna-klasser","title":"Egna klasser"}}},{"node":{"id":"85db460a-77c6-5087-8e97-a3c772186fd9","frontmatter":{"path":"/osa-8/4-metoder-i-egna-klasser","title":"Metoder i egna klasser"}}},{"node":{"id":"0e59dee0-5dd9-5827-83b9-a55e7d585c31","frontmatter":{"path":"/osa-8/5-fler-exempel","title":"Fler exempel"}}},{"node":{"id":"64715d0c-54f1-5aa7-a566-d2c5be6523ea","frontmatter":{"path":"/osa-8","title":"Modul 8"}}},{"node":{"id":"f7457509-a9a6-5420-8d03-ff1c61df8dc4","frontmatter":{"path":"/osa-9/1-objekt-och-referenser","title":"Objekt och referenser"}}},{"node":{"id":"16689ce4-b6aa-5bc4-9a30-44820994d6ea","frontmatter":{"path":"/osa-9/2-objekt-som-attribut","title":"Objekt som attribut "}}},{"node":{"id":"07985959-e85a-5f45-8923-babacb943c04","frontmatter":{"path":"/osa-9/3-inkapsling","title":"Inkapsling"}}},{"node":{"id":"83108600-9a37-5fd1-9a2b-13492879a9d6","frontmatter":{"path":"/osa-9/4-metodernas-rackvidd","title":"Metodernas räckvidd"}}},{"node":{"id":"a553cdc9-d6ac-5a14-ab43-d44811b407a2","frontmatter":{"path":"/osa-9/5-klassattribut","title":"Klassattribut"}}},{"node":{"id":"f7d7c9f1-6b54-5268-a308-995d49dd913d","frontmatter":{"path":"/osa-9/6-fler-exempel-med-klasser","title":"Fler exempel med klasser"}}},{"node":{"id":"c1fef3f7-8ca3-5780-9dec-19bd672b4627","frontmatter":{"path":"/osa-9","title":"Modul 9"}}}]}},"pageContext":{}}, "staticQueryHashes": ["1357757885","994120085"]} \ No newline at end of file diff --git a/page-data/osa-8/4-metoder-i-egna-klasser/page-data.json b/page-data/osa-8/4-metoder-i-egna-klasser/page-data.json index 09878c958..326a27cc3 100644 --- a/page-data/osa-8/4-metoder-i-egna-klasser/page-data.json +++ b/page-data/osa-8/4-metoder-i-egna-klasser/page-data.json @@ -1,5 +1,5 @@ { "componentChunkName": "component---src-templates-course-content-template-js", "path": "/osa-8/4-metoder-i-egna-klasser", - "result": {"data":{"page":{"htmlAst":{"type":"element","tagName":"div","properties":{},"children":[{"type":"element","tagName":"text-box","properties":{"variant":"learningObjectives","name":"Inlärningsmål"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Efter den här delen:"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Vet du hur klassmetoder fungerar"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Kan du skriva nya metoder i dina egna klasser"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Kommer du att förstå begreppen inkapsling och klient inom objektorienterad programmering"}]},{"type":"text","value":"\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Klasser som endast innehåller dataattribut skiljer sig inte så mycket från ordlistor. Nedan kan du se två sätt att modellera ett bankkonto, först med en klassdefinition och sedan med hjälp av en ordlista."}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Exempel 1: bankkoto med klassdefinition"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Bankkonto"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kontonummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" agare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" arsranta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"kontonummer "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" kontonummer\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"agare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" agare\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" saldo\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"arsranta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" arsranta\n\npeters_konto "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bankkonto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"12345-678\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1500.0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0.015"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Exempel2: bankkonto med ordlista"}]},{"type":"text","value":"\npeters_konto "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"kontonummer\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"12345-678\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"agare\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"saldo\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1500.0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"arsranta\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0.0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Med en ordlista är implementeringen mycket kortare och enklare. Med en klass är strukturen däremot mer \"hårt bunden\", så vi kan förvänta oss att alla "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bankkonto"}]},{"type":"text","value":"-objekt är strukturellt lika. Dessutom är en klass också namngiven. Klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bankkonto"}]},{"type":"text","value":" refereras till när ett nytt bankkonto skapas, och objektets typ är "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bankkonto"}]},{"type":"text","value":", inte dict."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"En annan stor fördel med klasser är att de förutom data även kan innehålla funktionalitet. En av de vägledande principerna för objektorienterad programmering är att ett objekt används för att komma åt både den data som är kopplad till ett objekt och funktionaliteten för att bearbeta denna data."}]},{"type":"element","tagName":"h2","properties":{"id":"metoder-i-klasser","style":"position:relative;"},"children":[{"type":"text","value":"Metoder i klasser"},{"type":"element","tagName":"a","properties":{"href":"#metoder-i-klasser","ariaLabel":"metoder i klasser permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"En metod är ett underprogram eller en funktion som är knuten till en specifik klass. Vanligtvis påverkar en metod bara ett enda objekt. En metod definieras inom klassdefinitionen och den kan komma åt klassens dataattribut precis som vilken annan variabel som helst."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss fortsätta med klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bankkonto"}]},{"type":"text","value":" som introducerades ovan. Nedan har vi en ny metod som lägger till ränta på kontot:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Bankkonto"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kontonummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" agare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" arsranta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"kontonummer "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" kontonummer\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"agare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" agare\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" saldo\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"arsranta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" arsranta\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Metoden lägger till den årliga räntat till saldot"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"tillsatt_ranta"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+="}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"arsranta\n\n\npeters_konto "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bankkonto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"12345-678\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1500.0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0.015"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\npeters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_ranta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"peters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"1522.5"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"tillsatt_ranta"}]},{"type":"text","value":" multiplicerar saldot på kontot med den årliga ränteprocenten och lägger sedan till resultatet till det aktuella saldot. Metoden verkar bara på det objekt som den anropas på."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss se hur detta fungerar när vi har skapat flera instanser av klassen:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Klassen Bankkonto är definierat såsom i förra exemplet"}]},{"type":"text","value":"\n\npeters_konto "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bankkonto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"12345-678\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1500.0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0.015"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\npernillas_konto "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bankkonto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"99999-999\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Pernilla Pythonson\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1500.0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0.05"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\npers_konto "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bankkonto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"1111-222\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Per Persson\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1500.0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0.001"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi tillsätter ränta till Peters och Pernillas konton, men inte Pers"}]},{"type":"text","value":"\npeters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_ranta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\npernillas_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_ranta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi skriver ut alla"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"peters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"pernillas_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"pers_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"1522.5\n1575.0\n1500.0"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Som du kan se ovan läggs den årliga räntan endast till på de konton som metoden anropas på. Eftersom den årliga räntan är olika för Peters och Paulas konton, blir resultatet olika för dessa två konton. Saldot på Pernillas konto ändras inte, eftersom metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"tillsatt_ranta"}]},{"type":"text","value":" inte anropas på objektet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"pernillas_konto"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"h2","properties":{"id":"inkapsling","style":"position:relative;"},"children":[{"type":"text","value":"Inkapsling"},{"type":"element","tagName":"a","properties":{"href":"#inkapsling","ariaLabel":"inkapsling permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Inom objektorienterad programmering dyker ordet klient upp då och då. Det används för att hänvisa till ett kodavsnitt som skapar ett objekt och använder den tjänst som tillges av dess metoder. När data som finns i ett objekt endast används genom de metoder som det tillges, garanteras objektets interna integritet. I praktiken innebär detta att t.ex. en "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bankkonto"}]},{"type":"text","value":"-klass erbjuder metoder för att hantera "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"saldo"}]},{"type":"text","value":"-attributet, så att saldot aldrig nås direkt av klienten. Dessa metoder kan sedan verifiera att saldot till exempel inte tillåts gå under noll."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ett exempel på hur detta skulle fungera:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Bankkonto"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kontonummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" agare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" arsranta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"kontonummer "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" kontonummer\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"agare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" agare\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" saldo\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"arsranta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" arsranta\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Metoden tillsätter den årliga räntat till saldot av kontot"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"tillsatt_ranta"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+="}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"arsranta\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Den här metoden \"tar ut\" pengar från kontot"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Metoden returnerar True ifall det lyckades, och False ifall det misslyckades"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"uttag"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" uttagssumma"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" uttagssumma "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"<="}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-="}]},{"type":"text","value":" uttagssumma\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"True"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"False"}]},{"type":"text","value":"\n\npeters_konto "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bankkonto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"12345-678\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1500.0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0.015"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" peters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"uttag"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1000"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Uttaget lyckades, kontots saldo är nu\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" peters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Uttaget lyckades inte, saldot var otillräckligt\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi försöker på nytt"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" peters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"uttag"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1000"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Uttaget lyckades, kontots saldo är nu\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" peters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Uttaget lyckades inte, saldot var otillräckligt\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Uttaget lyckades, kontots saldo är nu 500.0\nUttaget lyckades inte, saldot var otillräckligt"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Att bibehålla objektets interna integritet och erbjuda lämpliga metoder för att säkerställa detta kallas inkapsling. Tanken är att objektets inre arbete är dolt för klienten, men objektet erbjuder metoder som kan användas för att komma åt den data som lagras i objektet."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Att lägga till en metod innebär inte att attributet automatiskt döljs. Även om klassdefinitionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bankkonto"}]},{"type":"text","value":" innehåller metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"uttag"}]},{"type":"text","value":" för att ta ut pengar, kan klientkoden fortfarande komma åt och ändra attributet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"saldo"}]},{"type":"text","value":" direkt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"peters_konto "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bankkonto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"12345-678\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1500.0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0.015"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi försöker lyfta 2000"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" peters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"uttag"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2000"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Uttaget lyckades, kontots saldo är nu\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" peters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Uttaget lyckades inte, saldot var otillräckligt\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi \"tvingar\" ett uttag på 2000"}]},{"type":"text","value":"\n peters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2000"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Saldot är nu:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" peters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Det är möjligt att dölja dataattributen från klientkoden, vilket kan bidra till att lösa detta problem. Vi återkommer till detta ämne i nästa del."}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Minskande räknare","tmcname":"osa08-10_minskande_raknare"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Denna övning har flera delar. Varje del är värt ett poäng och kan lämnas in separat."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Övningsmallen innehåller en delvis ifylld klass "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"MinskandeRaknare"}]},{"type":"text","value":":"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"MinskandeRaknare"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" borjan_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"varde "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" borjan_varde\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"skriv_ut_varde"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"värde:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"minska"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"pass"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# resten av metoderna här"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Klassen används på följande sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"raknare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" MinskandeRaknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"minska"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"minska"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"värde: 10\nvärde: 9\nvärde: 8"}]}]},{"type":"element","tagName":"h3","properties":{"id":"minska-raknarens-varde","style":"position:relative;"},"children":[{"type":"text","value":"Minska räknarens värde"},{"type":"element","tagName":"a","properties":{"href":"#minska-raknarens-varde","ariaLabel":"minska raknarens varde permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Komplettera metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"minska"}]},{"type":"text","value":" som definieras i mallen, så att den minskar värdet som lagras i räknaren med ett. Se exemplet ovan för förväntat beteende."}]},{"type":"element","tagName":"h3","properties":{"id":"raknaren-far-inte-ha-ett-negativt-varde","style":"position:relative;"},"children":[{"type":"text","value":"Räknaren får inte ha ett negativt värde"},{"type":"element","tagName":"a","properties":{"href":"#raknaren-far-inte-ha-ett-negativt-varde","ariaLabel":"raknaren far inte ha ett negativt varde permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Lägg till funktionalitet till din "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"minska"}]},{"type":"text","value":"-metod, så att räknarens värde aldrig når negativa värden. Om värdet på räknaren är 0 kommer den inte att minskas ytterligare."}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"raknare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" MinskandeRaknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"minska"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"minska"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"minska"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"värde: 2\nvärde: 1\nvärde: 0\nvärde: 0"}]}]},{"type":"element","tagName":"h3","properties":{"id":"nollande-av-raknaren","style":"position:relative;"},"children":[{"type":"text","value":"Nollande av räknaren"},{"type":"element","tagName":"a","properties":{"href":"#nollande-av-raknaren","ariaLabel":"nollande av raknaren permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en metod "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"nolla"}]},{"type":"text","value":" som sätter värdet på räknaren till 0:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"raknare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" MinskandeRaknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"100"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"nolla"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"värde: 100\nvärde: 0"}]}]},{"type":"element","tagName":"h3","properties":{"id":"aterstallning-av-raknaren","style":"position:relative;"},"children":[{"type":"text","value":"Återställning av räknaren"},{"type":"element","tagName":"a","properties":{"href":"#aterstallning-av-raknaren","ariaLabel":"aterstallning av raknaren permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en metod "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"aterstall_ursprungligt_varde()"}]},{"type":"text","value":", som återställer räknaren till sitt ursprungliga tillstånd:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"raknare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" MinskandeRaknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"55"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"minska"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"minska"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"minska"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"minska"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"aterstall_ursprungligt_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"värde: 51\nvärde: 55"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Som avslutning på detta avsnitt tittar vi på en klass som modellerar en spelares personliga bästa. Klassdefinitionen innehåller separata valideringsmetoder som kontrollerar att de argument som skickas är giltiga. Metoderna anropas redan i konstruktorn. Detta säkerställer att det skapade objektet är sunt internt."}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"from"}]},{"type":"text","value":" datetime "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"import"}]},{"type":"text","value":" date\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"PersonligtRekord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" spelare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" dag"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" manad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" ar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" poang"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Standardvärden"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"spelare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"\""}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"datum "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" date"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1900"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"poang "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn_ok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"spelare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"spelare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" spelare\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"dtm_ok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"dag"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" manad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" ar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"datum "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" date"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" manad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" dag"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"poang_ok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"poang"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"poang "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" poang\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Hjälparmetoder som kollar att argumenten är giltiga"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"namn_ok"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Namnet ska vara minst två tecken"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"dtm_ok"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" dag"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" manad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" ar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"try"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n date"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" manad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" dag"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"True"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"except"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Ett undantag ifall datumet inte är giltigt"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"False"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"poang_ok"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" poang"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" poang "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n resultat1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" PersonligtRekord"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"11"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2020"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"235"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tulos1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"poang"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tulos1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"spelare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tulos1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"datum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Datumet är inte giltigt"}]},{"type":"text","value":"\n resultat2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" PersonligtRekord"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Pernilla\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"13"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2019"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4555"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tulos2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"poang"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tulos2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"spelare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"tulos2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"datum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Skriver ut standardvärdet 1900-01-01"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"235\nPeter\n2020-11-01\n4555\nPernilla\n1900-01-01"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I exemplet ovan anropades även hjälpmetoderna via parameternamnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":" när de användes i konstruktorn. Det är också möjligt att inkludera /statiska/ metoddefinitioner i klassdefinitioner. Dessa är metoder som kan anropas utan att det någonsin skapas en instans av klassen. Vi återkommer till detta i nästa del."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Parameternamnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":" används endast när man hänvisar till /objektets egenskaper som en instans av klassen/. Det gäller både dataattributen och de metoder som är knutna till ett objekt. För att göra terminologin mer förvirrande kallas dataattributen och metoderna tillsammans ibland helt enkelt för objektets attribut, vilket är anledningen till att vi i detta material ofta har angett dataattribut när vi menar de variabler som definieras inom klassen. Det är här terminologin hos vissa Python-programmerare skiljer sig något från den terminologi som mer allmänt används inom objektorienterad programmering, där attribut vanligtvis bara hänvisar till dataattributen hos ett objekt."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Det är också möjligt att skapa lokala variabler inom metoddefinitioner utan att hänvisa till "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":". Detta bör du göra om det inte finns något behov av att komma åt variablerna utanför metoden. Lokala variabler inom metoder har inga speciella nyckelord; de används precis som alla vanliga variabler som du har stött på hittills. ."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Så här skulle det till exempel fungera:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Bonuskort"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" saldo\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"tillsatt_bonus"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Nu är variabeln bonus en lokal variabel, inte ett"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# data attribut till objektet"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Den kan inte nås genom ett objekt"}]},{"type":"text","value":"\n bonus "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0.25"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+="}]},{"type":"text","value":" bonus\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"tillsatt_superbonus"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Variabeln superbonus är också en lokal variabel."}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vanligtvis är hjälpvariabler lokala variabler eftersom"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# det inte finns något behov av att komma åt dem från andra"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# metoder i klassen eller direkt via ett objekt."}]},{"type":"text","value":"\n superbonus "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0.5"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+="}]},{"type":"text","value":" superbonus\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__str__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\"Bonuskort(namn="}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":", saldo="}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":")\""}]}]}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"För- och efternamn","tmcname":"osa08-10b_for_och_efternamn"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en klass "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Person"}]},{"type":"text","value":", som får "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"endast ett attribut"}]},{"type":"text","value":" "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"namn"}]},{"type":"text","value":", som ges till konstruktorn."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa dessutom två metoder:"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"ge_fornamn"}]},{"type":"text","value":" returnerar personens förnamn och metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"ge_efternamn"}]},{"type":"text","value":" på samma sätt personens efternamn."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Du kan anta att det namn som skickas till konstruktorn kommer att innehålla endast för- och efternamn åtskilda med ett mellanslag."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Exempel på användning:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n peter "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"peter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"ge_fornamn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"peter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"ge_efternamn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n pauli "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Pernilla Pythonson\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"pernilla"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"ge_fornamn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"pernilla"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"ge_efternamn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Peter\nPython\nPernilla\nPythonson"}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Nummerstatistik","tmcname":"osa08-11_nummerstatistik"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I den här övningen ska du skapa ett program för att arbeta med siffror, på samma sätt som i "},{"type":"element","tagName":"a","properties":{"href":"/ohjelmointi-24-sv/osa-2/4-yksinkertainen-silmukka#programming-exercise-lukujen-kasittelya"},"children":[{"type":"text","value":"slutet av modul 2"}]},{"type":"text","value":" i kursen Introduktion till Programmering. Den här gången ska du definiera en klass för ändamålet."}]},{"type":"element","tagName":"h3","properties":{"id":"mangden-nummer","style":"position:relative;"},"children":[{"type":"text","value":"Mängden nummer"},{"type":"element","tagName":"a","properties":{"href":"#mangden-nummer","ariaLabel":"mangden nummer permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en klass med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Nummerstatistik"}]},{"type":"text","value":", med följande metoder:"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"tillsatt_nummer"}]},{"type":"text","value":" lägger till ett nytt nummer till statistiken"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"mangden_nummer"}]},{"type":"text","value":" returnerar mängden nummer som har tillsatts"}]},{"type":"text","value":"\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I det här skedet finns det inget behov av att lagra själva siffrorna i någon datastruktur. Det räcker att bara komma ihåg hur många som har lagts till. Metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"tillsatt_nummer"}]},{"type":"text","value":" tar emot ett argument, men det finns inget behov av att bearbeta det faktiska värdet på något sätt ännu."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen borde ha följande struktur:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"NummerStatistik"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"nummer "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"tillsatt_nummer"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"pass"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"mangden_nummer"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"pass"}]}]}]}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"statistik "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" NummerStatistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nstatistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nstatistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nstatistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nstatistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Mängden nummer:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" statistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"mangden_nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Mängden nummer: 4"}]}]},{"type":"element","tagName":"h3","properties":{"id":"summa-och-medeltal","style":"position:relative;"},"children":[{"type":"text","value":"Summa och medeltal"},{"type":"element","tagName":"a","properties":{"href":"#summa-och-medeltal","ariaLabel":"summa och medeltal permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Tillsätt följande metoder till klassdefinitionen:"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"summa"}]},{"type":"text","value":" returnerar summan av talen som satts till (en tom statistik returnerar 0)"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"medeltat"}]},{"type":"text","value":" returnerar medeltalet av numren (en tom statistiks medeltal är 0)"}]},{"type":"text","value":"\n"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"statistik "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" NummerStatistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nstatistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nstatistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nstatistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nstatistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Mängden nummer:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" statistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"mangden_nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Summa:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" statistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"summa"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Medeltal:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" statistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"medeltal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Mängd: 4\nSumma: 11\nMedeltal: 2.75"}]}]},{"type":"element","tagName":"h3","properties":{"id":"anvandarinmatning","style":"position:relative;"},"children":[{"type":"text","value":"Användarinmatning"},{"type":"element","tagName":"a","properties":{"href":"#anvandarinmatning","ariaLabel":"anvandarinmatning permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skriv ett huvudprogram som fortsätter att fråga användaren om heltal tills användaren skriver in -1. Programmet ska sedan skriva ut summan och medelvärdet av de inmatade talen."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ditt program ska använda "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"NummerStatistik"}]},{"type":"text","value":"-objekt för att hålla koll på numren som läggs till."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"OBS: Du behöver inte ändra "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"NummerStatistik"}]},{"type":"text","value":"-klassen, i denna del, använd en instans av klassen för att slutföra denna del."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"OBS2: Ditt huvudprogram ska inte vara inuti ett "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"if __name__ == \"__main__\""}]},{"type":"text","value":"-block, annars fungerar inte testen."}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ange nummer:\n"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"4"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"2"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"5"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"2"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"-1"}]},{"type":"text","value":"\nSumma: 13\nMedeltal: 3.25"}]}]},{"type":"element","tagName":"h3","properties":{"id":"flera-summor","style":"position:relative;"},"children":[{"type":"text","value":"Flera summor"},{"type":"element","tagName":"a","properties":{"href":"#flera-summor","ariaLabel":"flera summor permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Bygg på ditt huvudprogram så att det också separat räknar summan av de jämna och udda tal som läggs till."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"OBS: Ändra inte din "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"NummerStatistik"}]},{"type":"text","value":"-klassdefinition i denna del av övningen heller. Definiera i stället tre "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"NummerStatistik"}]},{"type":"text","value":"-objekt. Ett av dem ska hålla reda på alla siffror, ett annat ska hålla reda på de jämna siffrorna och det tredje ska hålla reda på de udda siffror som skrivs in."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"OBS2: Ditt huvudprogram ska inte vara inuti ett "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"if __name__ == \"__main__\""}]},{"type":"text","value":"-block, annars fungerar inte testen."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Programmet ska fungera så här:"}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ange nummer:\n"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"4"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"2"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"5"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"2"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"-1"}]},{"type":"text","value":"\nSumma: 13\nMedeltal: 3.25\nJämna talens summa: 8\nUdda talens summa: 5"}]}]}]}]},"html":"

    Efter den här delen:

      \n
    • Vet du hur klassmetoder fungerar
    • \n
    • Kan du skriva nya metoder i dina egna klasser
    • \n
    • Kommer du att förstå begreppen inkapsling och klient inom objektorienterad programmering
    • \n

    Klasser som endast innehåller dataattribut skiljer sig inte så mycket från ordlistor. Nedan kan du se två sätt att modellera ett bankkonto, först med en klassdefinition och sedan med hjälp av en ordlista.

    # Exempel 1: bankkoto med klassdefinition\nclass Bankkonto:\n\n    def __init__(self, kontonummer: str, agare: str, saldo: float, arsranta: float):\n        self.kontonummer = kontonummer\n        self.agare = agare\n        self.saldo = saldo\n        self.arsranta = arsranta\n\npeters_konto = Bankkonto(\"12345-678\", \"Peter Python\", 1500.0, 0.015)
    # Exempel2: bankkonto med ordlista\npeters_konto = {\"kontonummer\": \"12345-678\", \"agare\": \"Peter Python\", \"saldo\": 1500.0, \"arsranta\": 0.0}

    Med en ordlista är implementeringen mycket kortare och enklare. Med en klass är strukturen däremot mer \"hårt bunden\", så vi kan förvänta oss att alla Bankkonto-objekt är strukturellt lika. Dessutom är en klass också namngiven. Klassen Bankkonto refereras till när ett nytt bankkonto skapas, och objektets typ är Bankkonto, inte dict.

    En annan stor fördel med klasser är att de förutom data även kan innehålla funktionalitet. En av de vägledande principerna för objektorienterad programmering är att ett objekt används för att komma åt både den data som är kopplad till ett objekt och funktionaliteten för att bearbeta denna data.

    Metoder i klasser

    En metod är ett underprogram eller en funktion som är knuten till en specifik klass. Vanligtvis påverkar en metod bara ett enda objekt. En metod definieras inom klassdefinitionen och den kan komma åt klassens dataattribut precis som vilken annan variabel som helst.

    Låt oss fortsätta med klassen Bankkonto som introducerades ovan. Nedan har vi en ny metod som lägger till ränta på kontot:

    class Bankkonto:\n\n    def __init__(self, kontonummer: str, agare: str, saldo: float, arsranta: float):\n        self.kontonummer = kontonummer\n        self.agare = agare\n        self.saldo = saldo\n        self.arsranta = arsranta\n\n    # Metoden lägger till den årliga räntat till saldot\n    def tillsatt_ranta(self):\n        self.saldo += self.saldo * self.arsranta\n\n\npeters_konto = Bankkonto(\"12345-678\", \"Peter Python\", 1500.0, 0.015)\npeters_konto.tillsatt_ranta()\nprint(peters_konto.saldo)

    1522.5

    Metoden tillsatt_ranta multiplicerar saldot på kontot med den årliga ränteprocenten och lägger sedan till resultatet till det aktuella saldot. Metoden verkar bara på det objekt som den anropas på.

    Låt oss se hur detta fungerar när vi har skapat flera instanser av klassen:

    # Klassen Bankkonto är definierat såsom i förra exemplet\n\npeters_konto = Bankkonto(\"12345-678\", \"Peter Python\", 1500.0, 0.015)\npernillas_konto = Bankkonto(\"99999-999\", \"Pernilla Pythonson\", 1500.0, 0.05)\npers_konto = Bankkonto(\"1111-222\", \"Per Persson\", 1500.0, 0.001)\n\n# Vi tillsätter ränta till Peters och Pernillas konton, men inte Pers\npeters_konto.tillsatt_ranta()\npernillas_konto.tillsatt_ranta()\n\n# Vi skriver ut alla\nprint(peters_konto.saldo)\nprint(pernillas_konto.saldo)\nprint(pers_konto.saldo)

    1522.5\n1575.0\n1500.0

    Som du kan se ovan läggs den årliga räntan endast till på de konton som metoden anropas på. Eftersom den årliga räntan är olika för Peters och Paulas konton, blir resultatet olika för dessa två konton. Saldot på Pernillas konto ändras inte, eftersom metoden tillsatt_ranta inte anropas på objektet pernillas_konto.

    Inkapsling

    Inom objektorienterad programmering dyker ordet klient upp då och då. Det används för att hänvisa till ett kodavsnitt som skapar ett objekt och använder den tjänst som tillges av dess metoder. När data som finns i ett objekt endast används genom de metoder som det tillges, garanteras objektets interna integritet. I praktiken innebär detta att t.ex. en Bankkonto-klass erbjuder metoder för att hantera saldo-attributet, så att saldot aldrig nås direkt av klienten. Dessa metoder kan sedan verifiera att saldot till exempel inte tillåts gå under noll.

    Ett exempel på hur detta skulle fungera:

    class Bankkonto:\n\n    def __init__(self, kontonummer: str, agare: str, saldo: float, arsranta: float):\n        self.kontonummer = kontonummer\n        self.agare = agare\n        self.saldo = saldo\n        self.arsranta = arsranta\n\n    # Metoden tillsätter den årliga räntat till saldot av kontot\n    def tillsatt_ranta(self):\n        self.saldo += self.saldo * self.arsranta\n\n    # Den här metoden \"tar ut\" pengar från kontot\n    # Metoden returnerar True ifall det lyckades, och False ifall det misslyckades\n    def uttag(self, uttagssumma: float):\n        if uttagssumma <= self.saldo:\n            self.saldo -= uttagssumma\n            return True\n\n        return False\n\npeters_konto = Bankkonto(\"12345-678\", \"Peter Python\", 1500.0, 0.015)\n\nif peters_konto.uttag(1000):\n    print(\"Uttaget lyckades, kontots saldo är nu\", peters_konto.saldo)\nelse:\n    print(\"Uttaget lyckades inte, saldot var otillräckligt\")\n\n# Vi försöker på nytt\nif peters_konto.uttag(1000):\n    print(\"Uttaget lyckades, kontots saldo är nu\", peters_konto.saldo)\nelse:\n    print(\"Uttaget lyckades inte, saldot var otillräckligt\")

    Uttaget lyckades, kontots saldo är nu 500.0\nUttaget lyckades inte, saldot var otillräckligt

    Att bibehålla objektets interna integritet och erbjuda lämpliga metoder för att säkerställa detta kallas inkapsling. Tanken är att objektets inre arbete är dolt för klienten, men objektet erbjuder metoder som kan användas för att komma åt den data som lagras i objektet.

    Att lägga till en metod innebär inte att attributet automatiskt döljs. Även om klassdefinitionen Bankkonto innehåller metoden uttag för att ta ut pengar, kan klientkoden fortfarande komma åt och ändra attributet saldo direkt:

    peters_konto = Bankkonto(\"12345-678\", \"Peter Python\", 1500.0, 0.015)\n\n# Vi försöker lyfta 2000\nif peters_konto.uttag(2000):\n    print(\"Uttaget lyckades, kontots saldo är nu\", peters_konto.saldo)\nelse:\n    print(\"Uttaget lyckades inte, saldot var otillräckligt\")\n\n    # Vi \"tvingar\" ett uttag på 2000\n    peters_konto.saldo -= 2000\n\nprint(\"Saldot är nu:\", peters_konto.saldo)

    Det är möjligt att dölja dataattributen från klientkoden, vilket kan bidra till att lösa detta problem. Vi återkommer till detta ämne i nästa del.

    Denna övning har flera delar. Varje del är värt ett poäng och kan lämnas in separat.

    Övningsmallen innehåller en delvis ifylld klass MinskandeRaknare:

    class MinskandeRaknare:\n    def __init__(self, borjan_varde: int):\n        self.varde = borjan_varde\n\n    def skriv_ut_varde(self):\n        print(\"värde:\", self.varde)\n\n    def minska(self):\n        pass\n\n    # resten av metoderna här

    Klassen används på följande sätt:

    raknare = MinskandeRaknare(10)\nraknare.skriv_ut_varde()\nraknare.minska()\nraknare.skriv_ut_varde()\nraknare.minska()\nraknare.skriv_ut_varde()

    värde: 10\nvärde: 9\nvärde: 8

    Minska räknarens värde

    Komplettera metoden minska som definieras i mallen, så att den minskar värdet som lagras i räknaren med ett. Se exemplet ovan för förväntat beteende.

    Räknaren får inte ha ett negativt värde

    Lägg till funktionalitet till din minska-metod, så att räknarens värde aldrig når negativa värden. Om värdet på räknaren är 0 kommer den inte att minskas ytterligare.

    raknare = MinskandeRaknare(2)\nraknare.skriv_ut_varde()\nraknare.minska()\nraknare.skriv_ut_varde()\nraknare.minska()\nraknare.skriv_ut_varde()\nraknare.minska()\nraknare.skriv_ut_varde()

    värde: 2\nvärde: 1\nvärde: 0\nvärde: 0

    Nollande av räknaren

    Skapa en metod nolla som sätter värdet på räknaren till 0:

    raknare = MinskandeRaknare(100)\nraknare.skriv_ut_varde()\nraknare.nolla()\nraknare.skriv_ut_varde()

    värde: 100\nvärde: 0

    Återställning av räknaren

    Skapa en metod aterstall_ursprungligt_varde(), som återställer räknaren till sitt ursprungliga tillstånd:

    raknare = MinskandeRaknare(55)\nraknare.minska()\nraknare.minska()\nraknare.minska()\nraknare.minska()\nraknare.skriv_ut_varde()\nraknare.aterstall_ursprungligt_varde()\nraknare.skriv_ut_varde()

    värde: 51\nvärde: 55

    Som avslutning på detta avsnitt tittar vi på en klass som modellerar en spelares personliga bästa. Klassdefinitionen innehåller separata valideringsmetoder som kontrollerar att de argument som skickas är giltiga. Metoderna anropas redan i konstruktorn. Detta säkerställer att det skapade objektet är sunt internt.

    from datetime import date\n\nclass PersonligtRekord:\n\n    def __init__(self, spelare: str, dag: int, manad: int, ar: int, poang: int):\n        # Standardvärden\n        self.spelare = \"\"\n        self.datum = date(1900, 1, 1)\n        self.poang = 0\n\n        if self.namn_ok(spelare):\n            self.spelare = spelare\n\n        if self.dtm_ok(dag, manad, ar):\n            self.datum = date(ar, manad, dag)\n\n        if self.poang_ok(poang):\n            self.poang = poang\n\n    # Hjälparmetoder som kollar att argumenten är giltiga\n    def namn_ok(self, namn: str):\n        return len(namn) >= 2 # Namnet ska vara minst två tecken\n\n    def dtm_ok(self, dag, manad, ar):\n        try:\n            date(ar, manad, dag)\n            return True\n        except:\n            # Ett undantag ifall datumet inte är giltigt\n            return False\n\n    def poang_ok(self, poang):\n        return poang >= 0\n\nif __name__ == \"__main__\":\n    resultat1 = PersonligtRekord(\"Peter\", 1, 11, 2020, 235)\n    print(tulos1.poang)\n    print(tulos1.spelare)\n    print(tulos1.datum)\n\n    # Datumet är inte giltigt\n    resultat2 = PersonligtRekord(\"Pernilla\", 4, 13, 2019, 4555)\n    print(tulos2.poang)\n    print(tulos2.spelare)\n    print(tulos2.datum) # Skriver ut standardvärdet 1900-01-01

    235\nPeter\n2020-11-01\n4555\nPernilla\n1900-01-01

    I exemplet ovan anropades även hjälpmetoderna via parameternamnet self när de användes i konstruktorn. Det är också möjligt att inkludera /statiska/ metoddefinitioner i klassdefinitioner. Dessa är metoder som kan anropas utan att det någonsin skapas en instans av klassen. Vi återkommer till detta i nästa del.

    Parameternamnet self används endast när man hänvisar till /objektets egenskaper som en instans av klassen/. Det gäller både dataattributen och de metoder som är knutna till ett objekt. För att göra terminologin mer förvirrande kallas dataattributen och metoderna tillsammans ibland helt enkelt för objektets attribut, vilket är anledningen till att vi i detta material ofta har angett dataattribut när vi menar de variabler som definieras inom klassen. Det är här terminologin hos vissa Python-programmerare skiljer sig något från den terminologi som mer allmänt används inom objektorienterad programmering, där attribut vanligtvis bara hänvisar till dataattributen hos ett objekt.

    Det är också möjligt att skapa lokala variabler inom metoddefinitioner utan att hänvisa till self. Detta bör du göra om det inte finns något behov av att komma åt variablerna utanför metoden. Lokala variabler inom metoder har inga speciella nyckelord; de används precis som alla vanliga variabler som du har stött på hittills. .

    Så här skulle det till exempel fungera:

    class Bonuskort:\n    def __init__(self, namn: str, saldo: float):\n        self.namn = namn\n        self.saldo = saldo\n\n    def tillsatt_bonus(self):\n        # Nu är variabeln bonus en lokal variabel, inte ett\n        # data attribut till objektet\n        # Den kan inte nås genom ett objekt\n        bonus = self.saldo * 0.25\n        self.saldo += bonus\n\n    def tillsatt_superbonus(self):\n        # Variabeln superbonus är också en lokal variabel.\n        # Vanligtvis är hjälpvariabler lokala variabler eftersom\n        # det inte finns något behov av att komma åt dem från andra\n        # metoder i klassen eller direkt via ett objekt.\n        superbonus = self.saldo * 0.5\n        self.saldo += superbonus\n\n    def __str__(self):\n        return f\"Bonuskort(namn={self.namn}, saldo={self.saldo})\"

    Skapa en klass Person, som får endast ett attribut namn, som ges till konstruktorn.

    Skapa dessutom två metoder:

    Metoden ge_fornamn returnerar personens förnamn och metoden ge_efternamn på samma sätt personens efternamn.

    Du kan anta att det namn som skickas till konstruktorn kommer att innehålla endast för- och efternamn åtskilda med ett mellanslag.

    Exempel på användning:

    if __name__ == \"__main__\":\n    peter = Person(\"Peter Python\")\n    print(peter.ge_fornamn())\n    print(peter.ge_efternamn())\n\n    pauli = Person(\"Pernilla Pythonson\")\n    print(pernilla.ge_fornamn())\n    print(pernilla.ge_efternamn())

    Peter\nPython\nPernilla\nPythonson

    I den här övningen ska du skapa ett program för att arbeta med siffror, på samma sätt som i slutet av modul 2 i kursen Introduktion till Programmering. Den här gången ska du definiera en klass för ändamålet.

    Mängden nummer

    Skapa en klass med namnet Nummerstatistik, med följande metoder:

      \n
    • metoden tillsatt_nummer lägger till ett nytt nummer till statistiken
    • \n
    • metoden mangden_nummer returnerar mängden nummer som har tillsatts
    • \n

    I det här skedet finns det inget behov av att lagra själva siffrorna i någon datastruktur. Det räcker att bara komma ihåg hur många som har lagts till. Metoden tillsatt_nummer tar emot ett argument, men det finns inget behov av att bearbeta det faktiska värdet på något sätt ännu.

    Funktionen borde ha följande struktur:

    class  NummerStatistik:\n    def __init__(self):\n        self.nummer = 0\n\n    def tillsatt_nummer(self, nummer:int):\n        pass\n\n    def mangden_nummer(self):\n        pass
    statistik = NummerStatistik()\nstatistik.tillsatt_nummer(3)\nstatistik.tillsatt_nummer(5)\nstatistik.tillsatt_nummer(1)\nstatistik.tillsatt_nummer(2)\nprint(\"Mängden nummer:\", statistik.mangden_nummer())

    Mängden nummer: 4

    Summa och medeltal

    Tillsätt följande metoder till klassdefinitionen:

      \n
    • metoden summa returnerar summan av talen som satts till (en tom statistik returnerar 0)
    • \n
    • metoden medeltat returnerar medeltalet av numren (en tom statistiks medeltal är 0)
    • \n
    statistik = NummerStatistik()\nstatistik.tillsatt_nummer(3)\nstatistik.tillsatt_nummer(5)\nstatistik.tillsatt_nummer(1)\nstatistik.tillsatt_nummer(2)\nprint(\"Mängden nummer:\", statistik.mangden_nummer())\nprint(\"Summa:\", statistik.summa())\nprint(\"Medeltal:\", statistik.medeltal())

    Mängd: 4\nSumma: 11\nMedeltal: 2.75

    Användarinmatning

    Skriv ett huvudprogram som fortsätter att fråga användaren om heltal tills användaren skriver in -1. Programmet ska sedan skriva ut summan och medelvärdet av de inmatade talen.

    Ditt program ska använda NummerStatistik-objekt för att hålla koll på numren som läggs till.

    OBS: Du behöver inte ändra NummerStatistik-klassen, i denna del, använd en instans av klassen för att slutföra denna del.

    OBS2: Ditt huvudprogram ska inte vara inuti ett if __name__ == \"__main__\"-block, annars fungerar inte testen.

    Ange nummer:\n4\n2\n5\n2\n-1\nSumma: 13\nMedeltal: 3.25

    Flera summor

    Bygg på ditt huvudprogram så att det också separat räknar summan av de jämna och udda tal som läggs till.

    OBS: Ändra inte din NummerStatistik-klassdefinition i denna del av övningen heller. Definiera i stället tre NummerStatistik-objekt. Ett av dem ska hålla reda på alla siffror, ett annat ska hålla reda på de jämna siffrorna och det tredje ska hålla reda på de udda siffror som skrivs in.

    OBS2: Ditt huvudprogram ska inte vara inuti ett if __name__ == \"__main__\"-block, annars fungerar inte testen.

    Programmet ska fungera så här:

    Ange nummer:\n4\n2\n5\n2\n-1\nSumma: 13\nMedeltal: 3.25\nJämna talens summa: 8\nUdda talens summa: 5

    ","frontmatter":{"path":"/osa-8/4-metoder-i-egna-klasser","title":"Metoder i egna klasser"},"fileAbsolutePath":"/home/runner/work/ohjelmointi-24-sv/ohjelmointi-24-sv/data/osa-8/4-metoder-i-egna-klasser.md"},"allPages":{"edges":[{"node":{"id":"b5e8ae41-d492-55f7-88a7-1c7292333ab1","frontmatter":{"path":"/arvostelu-ja-kokeet","title":"Arvostelu ja kokeet"}}},{"node":{"id":"af4df6be-211d-5ba1-acea-9edbefa06c49","frontmatter":{"path":"/frontmatter-guide","title":"Frontmatter-guide"}}},{"node":{"id":"56769133-4836-5fbb-a857-8fb0c6803e6d","frontmatter":{"path":"/","title":"Tietoa kurssista"}}},{"node":{"id":"e86762f0-c2a9-5598-aba3-2b8d7db7807c","frontmatter":{"path":"/kaikki-tehtavat","title":"Kaikki tehtävät"}}},{"node":{"id":"5d065309-85e8-5823-9527-ec1c3cf38d4d","frontmatter":{"path":"/tuki","title":"Tukea tehtäviin"}}},{"node":{"id":"ac195ee0-ad04-5cc9-9643-963f93d29ad2","frontmatter":{"path":"/usein-kysytyt-kysymykset","title":"Usein kysytyt kysymykset"}}},{"node":{"id":"51a165d7-8ce5-5d53-9c15-5321b6adef8c","frontmatter":{"path":"/verkkotentti","title":"Verkkotentti 4.6."}}},{"node":{"id":"4d9cf293-01e9-5e6c-a88f-599560e33c9a","frontmatter":{"path":"/verkkotentti-ohja","title":"Ohjelmoinnin jatkokurssin verkkotentti 16.12."}}},{"node":{"id":"279e1cca-fb0b-5d3f-b527-be05243d138d","frontmatter":{"path":"/verkkotentti-ohpe","title":"Ohjelmoinnin perusteiden verkkotentti 09.03."}}},{"node":{"id":"347bdde4-ba21-5f22-8a88-0287dfe29a45","frontmatter":{"path":"/virheilmoitukset","title":"Yleiset virheilmoitukset"}}},{"node":{"id":"3bf12e3a-1542-57f4-812d-dd32cebc99e2","frontmatter":{"path":"/sanasto","title":"Sanasto"}}},{"node":{"id":"9910673b-d62d-5d8d-a756-5267160d891f","frontmatter":{"path":"/osa-1/1-introduktion","title":"Introduktion"}}},{"node":{"id":"0b17a28e-f939-57cc-aa5b-4db407cdf34a","frontmatter":{"path":"/osa-1/2-info-fran-anvandaren","title":"Information från användaren"}}},{"node":{"id":"b95794f2-f3b3-597c-a4ec-6f023b584f81","frontmatter":{"path":"/osa-1/3-mer-om-variabler","title":"Mer om variabler"}}},{"node":{"id":"02cd0849-e7a5-5fd1-bf66-35f0197d3e75","frontmatter":{"path":"/osa-1/4-rakneoperationer","title":"Räkneoperationer"}}},{"node":{"id":"42690a69-3997-5b84-b999-15d9c3212884","frontmatter":{"path":"/osa-1/5-villkorssatser","title":"If-satser"}}},{"node":{"id":"96a0ec65-c0a3-5150-95c5-48c260f88162","frontmatter":{"path":"/osa-1","title":"Modul 1"}}},{"node":{"id":"e7a4d0c8-b8c1-53fa-ab51-9cc06fd417a3","frontmatter":{"path":"/osa-10/1-klasshierarkier","title":"Klasshierarkier"}}},{"node":{"id":"5f6d4b8b-7d05-5c79-9f2f-9e30b397167b","frontmatter":{"path":"/osa-10/2-atkamstmodifierare","title":"Åtkomstmodifierare"}}},{"node":{"id":"bb896c90-aabc-5a9d-8d4b-50839da286db","frontmatter":{"path":"/osa-10/3-objektorienterade-programmeringstekniker","title":"Objektorienterade programmeringstekniker"}}},{"node":{"id":"a2dca4f1-d64d-5e77-a3ca-8b2a208e9afa","frontmatter":{"path":"/osa-10/4-storre-applikation","title":"Att utveckla en större applikation"}}},{"node":{"id":"8c9cf5a7-f02e-5ccf-ab8f-f078c3ccecb6","frontmatter":{"path":"/osa-10","title":"Modul 10"}}},{"node":{"id":"f6688d26-5502-5c17-a8ee-db66f650f1f1","frontmatter":{"path":"/osa-11/1-list-comprehension","title":"List comprehension"}}},{"node":{"id":"1eac8489-72f2-5d53-904b-c960e2622018","frontmatter":{"path":"/osa-11/2-mer-om-comprehensions","title":"Mer om comprehensions"}}},{"node":{"id":"09630fca-7768-53f3-8aca-6e5ac638fc68","frontmatter":{"path":"/osa-11/3-rekursion","title":"Rekursion"}}},{"node":{"id":"70f6008e-a762-574c-a92a-c5c585d9677e","frontmatter":{"path":"/osa-11/4-lisaa-esimerkkeja","title":"Fler exempel på rekursion"}}},{"node":{"id":"eb8ed7d7-c39d-52db-949d-f75649498c67","frontmatter":{"path":"/osa-11","title":"Modul 11"}}},{"node":{"id":"9bba31dc-e14c-5400-a25b-7339107e9ba7","frontmatter":{"path":"/osa-12/1-funktioner-som-argument","title":"Funktioner som argument"}}},{"node":{"id":"5b9e4584-7234-5216-a118-d2a1bc617e13","frontmatter":{"path":"/osa-12/2-generatorer","title":"Generatorer"}}},{"node":{"id":"1d27636e-74f4-5c30-a1d8-08a303684945","frontmatter":{"path":"/osa-12/3-funktionell-programmering","title":"Funktionell programmering"}}},{"node":{"id":"6785750f-f145-5b88-81e9-b52e36ba53c6","frontmatter":{"path":"/osa-12/4-reguljara-uttryck","title":"Reguljära uttryck"}}},{"node":{"id":"d21df33a-4bf4-5ee3-9e2a-431d57561f09","frontmatter":{"path":"/osa-12","title":"Modul 12"}}},{"node":{"id":"14e3c129-50ec-581f-8679-8132248d41c1","frontmatter":{"path":"/osa-13/1-pygame","title":"Pygame"}}},{"node":{"id":"01bc3b9b-4f80-5561-8b56-3a7f09082263","frontmatter":{"path":"/osa-13/2-animation","title":"Animation"}}},{"node":{"id":"dd68786f-e2fc-5957-b47a-52b74c5199ef","frontmatter":{"path":"/osa-13/3-handelser","title":"Händelser"}}},{"node":{"id":"4a1aaa41-d6f7-51cd-8b89-95842cb9e02d","frontmatter":{"path":"/osa-13/4-fler-pygame-tekniker","title":"Fler pygame-tekniker"}}},{"node":{"id":"cdcf0ce1-e881-5ca6-8fa9-d0d343ec4e15","frontmatter":{"path":"/osa-13","title":"Modul 13"}}},{"node":{"id":"0ab28435-7654-5a8e-88d6-daa17d78103b","frontmatter":{"path":"/osa-14/1-spelprojekt","title":"Spelprojekt"}}},{"node":{"id":"b7a0628c-e4ba-583e-a52a-dd0ad78028d8","frontmatter":{"path":"/osa-14/2-robot-och-ladar","title":"Robot och lådor"}}},{"node":{"id":"6ccdbdff-7539-5a23-b23c-2ad48a99386f","frontmatter":{"path":"/osa-14/3-fardigstallande-av-spelet","title":"Färdigställande av spelet"}}},{"node":{"id":"1b505c9f-9b1b-58bd-8df7-553fef49cc8d","frontmatter":{"path":"/osa-14/4-ditt-eget-sepl","title":"Ditt eget spel"}}},{"node":{"id":"55c54859-8c7f-5fd9-8a8d-2c54ee677577","frontmatter":{"path":"/osa-14","title":"Modul 14"}}},{"node":{"id":"b5c346d1-d175-5824-98bb-4a4c3b45204d","frontmatter":{"path":"/osa-2/1-terminologi","title":"Programmeringsterminologi"}}},{"node":{"id":"db7188b0-0253-5c30-b8d2-0e115e235fb3","frontmatter":{"path":"/osa-2/2-else-elif","title":"Mera om if-satser"}}},{"node":{"id":"49d15928-f8b9-5883-9f29-86c307f6929e","frontmatter":{"path":"/osa-2/3-kombinera-villkor","title":"Kombinera villkor"}}},{"node":{"id":"93f1f9c8-6b27-5892-8bd4-7d1d008bf07a","frontmatter":{"path":"/osa-2/4-loopar","title":"Enkla loopar"}}},{"node":{"id":"5523b5b8-61f8-506d-bfe0-c6cc774390ce","frontmatter":{"path":"/osa-2","title":"Modul 2"}}},{"node":{"id":"02012307-c2a6-5cf2-9105-c10933c14b37","frontmatter":{"path":"/osa-3/1-loopar-med-villkor","title":"Loopar med villkor"}}},{"node":{"id":"efb889f4-4a19-515e-a0f6-4297d76a2757","frontmatter":{"path":"/osa-3/2-behandla-strangar","title":"Behandla strängar"}}},{"node":{"id":"a602077d-bbae-5eb7-a354-cc44b29ae96a","frontmatter":{"path":"/osa-3/3-mer-om-loopar","title":"Mera om loopar"}}},{"node":{"id":"6d878692-b9c7-57e6-ae58-044e5a6bef6f","frontmatter":{"path":"/osa-3/4-definiera-funktioner","title":"Definiera funktioner"}}},{"node":{"id":"682b5a18-73c5-56e2-8374-237baccbab40","frontmatter":{"path":"/osa-3","title":"Modul 3"}}},{"node":{"id":"3de95518-6b44-54db-9bcd-0c90a41d2fd5","frontmatter":{"path":"/osa-4/1-vscode","title":"Editorn Visual Studio Code, Pythontolken och det inbyggda debuggningsverktyget"}}},{"node":{"id":"7de9921c-7f94-58fe-84b9-7676dddb3b94","frontmatter":{"path":"/osa-4/2-mer-om-funktioner","title":"Mer om funktioner"}}},{"node":{"id":"29e29c69-360c-5f5c-8f34-5aef22eb327f","frontmatter":{"path":"/osa-4/3-listor","title":"Listor"}}},{"node":{"id":"bfe57880-0cbb-54e4-be9c-8fa180eafe6b","frontmatter":{"path":"/osa-4/4-iteration","title":"Iteration"}}},{"node":{"id":"2eab46f0-5373-5cbe-b2a0-1d071854a053","frontmatter":{"path":"/osa-4/5-utskrift","title":"Formatera utskrift"}}},{"node":{"id":"a5974fee-f2eb-5b89-88a5-6dd3754baaad","frontmatter":{"path":"/osa-4/6-strangar-listor","title":"Mera strängar och listor"}}},{"node":{"id":"e125c469-ee19-505e-9a41-83da6143ecd8","frontmatter":{"path":"/osa-4","title":"Modul 4"}}},{"node":{"id":"2558444a-be1d-5bc6-95ab-e091da2443fc","frontmatter":{"path":"/osa-5/1-mer-om-listor","title":"Mer om listor"}}},{"node":{"id":"b452d9be-0569-56c2-ba89-a040d4cb40dc","frontmatter":{"path":"/osa-5/2-referenser","title":"Referenser"}}},{"node":{"id":"ebe4ca3f-e657-5907-bfcc-ae84d9947aff","frontmatter":{"path":"/osa-5/3-lexikon","title":"Lexikon"}}},{"node":{"id":"f1dd5d66-ac87-5e53-92a0-0b7e3ece6ed8","frontmatter":{"path":"/osa-5/4-tuple","title":"Tuple"}}},{"node":{"id":"161c0109-5c00-5bed-b7af-90dc7ddf5713","frontmatter":{"path":"/osa-5","title":"Modul 5"}}},{"node":{"id":"e6cfa6e1-e99b-50e0-bc6a-3c0f153420e8","frontmatter":{"path":"/osa-6/1-lasa-filer","title":"Läsa filer"}}},{"node":{"id":"ce8d90a4-ca7c-5797-abc1-3fe0094bfa4b","frontmatter":{"path":"/osa-6/2-skriva-filer","title":"Skriva filer"}}},{"node":{"id":"519d5330-277a-59ba-be50-c2f63080df94","frontmatter":{"path":"/osa-6/3-fel","title":"Förbered dig på fel"}}},{"node":{"id":"82393756-3ef8-5d07-a8da-fed818ca43f0","frontmatter":{"path":"/osa-6/4-lokala-globala-variabler","title":"Lokala och globala variabler"}}},{"node":{"id":"007d85ae-a118-5b10-8a7e-18302b15eba8","frontmatter":{"path":"/osa-6","title":"Modul 6"}}},{"node":{"id":"bbb2346d-b1ee-551d-89c1-516f119b0eed","frontmatter":{"path":"/osa-7/1-moduler","title":"Moduler"}}},{"node":{"id":"ecb9af64-49f9-5e28-a544-3934e95233cf","frontmatter":{"path":"/osa-7/2-slumpmassighet","title":"Slumpmässighet"}}},{"node":{"id":"ebe469ef-c486-523a-9621-5dc4040c5cd8","frontmatter":{"path":"/osa-7/3-tid-datum","title":"Tid och datum"}}},{"node":{"id":"b9cf2d99-08f6-5de5-8425-c9b483241567","frontmatter":{"path":"/osa-7/4-behandla-data","title":"Behandla data"}}},{"node":{"id":"27075b37-8a6a-5554-9079-465a36d2da2d","frontmatter":{"path":"/osa-7/5-egna-moduler","title":"Skapa dina egna moduler"}}},{"node":{"id":"69492225-4d69-59ea-b33d-5301d35cf4ed","frontmatter":{"path":"/osa-7/6-funktionaliteter-python","title":"Flera funktionaliteter i Python"}}},{"node":{"id":"70ae841a-e6e9-5252-afae-6329fb67bcad","frontmatter":{"path":"/osa-7","title":"Modul 7"}}},{"node":{"id":"4afc4486-3cfe-53d1-b4c0-6db26484acfa","frontmatter":{"path":"/osa-8/1-objekt-och-metoder","title":"Objekt och metoder"}}},{"node":{"id":"6be37772-e94b-5b36-8a02-fffa7eef9feb","frontmatter":{"path":"/osa-8/2-klasser-och-objekt","title":"Klasser och objekt"}}},{"node":{"id":"8b6aec39-f8b9-525c-9f25-d8e73389fa42","frontmatter":{"path":"/osa-8/3-egna-klasser","title":"Egna klasser"}}},{"node":{"id":"85db460a-77c6-5087-8e97-a3c772186fd9","frontmatter":{"path":"/osa-8/4-metoder-i-egna-klasser","title":"Metoder i egna klasser"}}},{"node":{"id":"0e59dee0-5dd9-5827-83b9-a55e7d585c31","frontmatter":{"path":"/osa-8/5-fler-exempel","title":"Fler exempel"}}},{"node":{"id":"64715d0c-54f1-5aa7-a566-d2c5be6523ea","frontmatter":{"path":"/osa-8","title":"Modul 8"}}},{"node":{"id":"f7457509-a9a6-5420-8d03-ff1c61df8dc4","frontmatter":{"path":"/osa-9/1-objekt-och-referenser","title":"Objekt och referenser"}}},{"node":{"id":"16689ce4-b6aa-5bc4-9a30-44820994d6ea","frontmatter":{"path":"/osa-9/2-objekt-som-attribut","title":"Objekt som attribut "}}},{"node":{"id":"07985959-e85a-5f45-8923-babacb943c04","frontmatter":{"path":"/osa-9/3-inkapsling","title":"Inkapsling"}}},{"node":{"id":"83108600-9a37-5fd1-9a2b-13492879a9d6","frontmatter":{"path":"/osa-9/4-metodernas-rackvidd","title":"Metodernas räckvidd"}}},{"node":{"id":"a553cdc9-d6ac-5a14-ab43-d44811b407a2","frontmatter":{"path":"/osa-9/5-klassattribut","title":"Klassattribut"}}},{"node":{"id":"f7d7c9f1-6b54-5268-a308-995d49dd913d","frontmatter":{"path":"/osa-9/6-fler-exempel-med-klasser","title":"Fler exempel med klasser"}}},{"node":{"id":"c1fef3f7-8ca3-5780-9dec-19bd672b4627","frontmatter":{"path":"/osa-9","title":"Modul 9"}}}]}},"pageContext":{}}, + "result": {"data":{"page":{"htmlAst":{"type":"element","tagName":"div","properties":{},"children":[{"type":"element","tagName":"text-box","properties":{"variant":"learningObjectives","name":"Inlärningsmål"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Efter den här delen:"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Vet du hur klassmetoder fungerar"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Kan du skriva nya metoder i dina egna klasser"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Kommer du att förstå begreppen inkapsling och klient inom objektorienterad programmering"}]},{"type":"text","value":"\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Klasser som endast innehåller dataattribut skiljer sig inte så mycket från ordlistor. Nedan kan du se två sätt att modellera ett bankkonto, först med en klassdefinition och sedan med hjälp av en ordlista."}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Exempel 1: bankkoto med klassdefinition"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Bankkonto"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kontonummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" agare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" arsranta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"kontonummer "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" kontonummer\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"agare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" agare\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" saldo\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"arsranta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" arsranta\n\npeters_konto "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bankkonto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"12345-678\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1500.0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0.015"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Exempel2: bankkonto med ordlista"}]},{"type":"text","value":"\npeters_konto "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"kontonummer\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"12345-678\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"agare\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"saldo\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1500.0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"arsranta\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0.0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Med en ordlista är implementeringen mycket kortare och enklare. Med en klass är strukturen däremot mer \"hårt bunden\", så vi kan förvänta oss att alla "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bankkonto"}]},{"type":"text","value":"-objekt är strukturellt lika. Dessutom är en klass också namngiven. Klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bankkonto"}]},{"type":"text","value":" refereras till när ett nytt bankkonto skapas, och objektets typ är "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bankkonto"}]},{"type":"text","value":", inte dict."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"En annan stor fördel med klasser är att de förutom data även kan innehålla funktionalitet. En av de vägledande principerna för objektorienterad programmering är att ett objekt används för att komma åt både den data som är kopplad till ett objekt och funktionaliteten för att bearbeta denna data."}]},{"type":"element","tagName":"h2","properties":{"id":"metoder-i-klasser","style":"position:relative;"},"children":[{"type":"text","value":"Metoder i klasser"},{"type":"element","tagName":"a","properties":{"href":"#metoder-i-klasser","ariaLabel":"metoder i klasser permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"En metod är ett underprogram eller en funktion som är knuten till en specifik klass. Vanligtvis påverkar en metod bara ett enda objekt. En metod definieras inom klassdefinitionen och den kan komma åt klassens dataattribut precis som vilken annan variabel som helst."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss fortsätta med klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bankkonto"}]},{"type":"text","value":" som introducerades ovan. Nedan har vi en ny metod som lägger till ränta på kontot:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Bankkonto"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kontonummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" agare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" arsranta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"kontonummer "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" kontonummer\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"agare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" agare\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" saldo\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"arsranta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" arsranta\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Metoden lägger till den årliga räntat till saldot"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"tillsatt_ranta"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+="}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"arsranta\n\n\npeters_konto "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bankkonto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"12345-678\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1500.0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0.015"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\npeters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_ranta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"peters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"1522.5"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"tillsatt_ranta"}]},{"type":"text","value":" multiplicerar saldot på kontot med den årliga ränteprocenten och lägger sedan till resultatet till det aktuella saldot. Metoden verkar bara på det objekt som den anropas på."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss se hur detta fungerar när vi har skapat flera instanser av klassen:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Klassen Bankkonto är definierat såsom i förra exemplet"}]},{"type":"text","value":"\n\npeters_konto "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bankkonto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"12345-678\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1500.0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0.015"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\npernillas_konto "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bankkonto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"99999-999\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Pernilla Pythonson\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1500.0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0.05"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\npers_konto "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bankkonto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"1111-222\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Per Persson\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1500.0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0.001"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi tillsätter ränta till Peters och Pernillas konton, men inte Pers"}]},{"type":"text","value":"\npeters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_ranta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\npernillas_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_ranta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi skriver ut alla"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"peters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"pernillas_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"pers_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"1522.5\n1575.0\n1500.0"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Som du kan se ovan läggs den årliga räntan endast till på de konton som metoden anropas på. Eftersom den årliga räntan är olika för Peters och Paulas konton, blir resultatet olika för dessa två konton. Saldot på Pernillas konto ändras inte, eftersom metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"tillsatt_ranta"}]},{"type":"text","value":" inte anropas på objektet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"pernillas_konto"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"h2","properties":{"id":"inkapsling","style":"position:relative;"},"children":[{"type":"text","value":"Inkapsling"},{"type":"element","tagName":"a","properties":{"href":"#inkapsling","ariaLabel":"inkapsling permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Inom objektorienterad programmering dyker ordet klient upp då och då. Det används för att hänvisa till ett kodavsnitt som skapar ett objekt och använder den tjänst som tillges av dess metoder. När data som finns i ett objekt endast används genom de metoder som det tillges, garanteras objektets interna integritet. I praktiken innebär detta att t.ex. en "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bankkonto"}]},{"type":"text","value":"-klass erbjuder metoder för att hantera "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"saldo"}]},{"type":"text","value":"-attributet, så att saldot aldrig nås direkt av klienten. Dessa metoder kan sedan verifiera att saldot till exempel inte tillåts gå under noll."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ett exempel på hur detta skulle fungera:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Bankkonto"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kontonummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" agare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" arsranta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"kontonummer "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" kontonummer\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"agare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" agare\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" saldo\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"arsranta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" arsranta\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Metoden tillsätter den årliga räntat till saldot av kontot"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"tillsatt_ranta"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+="}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"arsranta\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Den här metoden \"tar ut\" pengar från kontot"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Metoden returnerar True ifall det lyckades, och False ifall det misslyckades"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"uttag"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" uttagssumma"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" uttagssumma "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"<="}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-="}]},{"type":"text","value":" uttagssumma\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"True"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"False"}]},{"type":"text","value":"\n\npeters_konto "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bankkonto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"12345-678\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1500.0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0.015"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" peters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"uttag"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1000"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Uttaget lyckades, kontots saldo är nu\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" peters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Uttaget lyckades inte, saldot var otillräckligt\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi försöker på nytt"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" peters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"uttag"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1000"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Uttaget lyckades, kontots saldo är nu\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" peters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Uttaget lyckades inte, saldot var otillräckligt\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Uttaget lyckades, kontots saldo är nu 500.0\nUttaget lyckades inte, saldot var otillräckligt"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Att bibehålla objektets interna integritet och erbjuda lämpliga metoder för att säkerställa detta kallas inkapsling. Tanken är att objektets inre arbete är dolt för klienten, men objektet erbjuder metoder som kan användas för att komma åt den data som lagras i objektet."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Att lägga till en metod innebär inte att attributet automatiskt döljs. Även om klassdefinitionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bankkonto"}]},{"type":"text","value":" innehåller metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"uttag"}]},{"type":"text","value":" för att ta ut pengar, kan klientkoden fortfarande komma åt och ändra attributet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"saldo"}]},{"type":"text","value":" direkt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"peters_konto "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bankkonto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"12345-678\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1500.0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0.015"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi försöker lyfta 2000"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" peters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"uttag"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2000"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Uttaget lyckades, kontots saldo är nu\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" peters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Uttaget lyckades inte, saldot var otillräckligt\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi \"tvingar\" ett uttag på 2000"}]},{"type":"text","value":"\n peters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2000"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Saldot är nu:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" peters_konto"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Det är möjligt att dölja dataattributen från klientkoden, vilket kan bidra till att lösa detta problem. Vi återkommer till detta ämne i nästa del."}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Minskande räknare","tmcname":"osa08-10_minskande_raknare"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Denna övning har flera delar. Varje del är värt ett poäng och kan lämnas in separat."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Övningsmallen innehåller en delvis ifylld klass "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"MinskandeRaknare"}]},{"type":"text","value":":"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"MinskandeRaknare"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" borjan_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"varde "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" borjan_varde\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"skriv_ut_varde"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"värde:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"minska"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"pass"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# resten av metoderna här"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Klassen används på följande sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"raknare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" MinskandeRaknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"minska"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"minska"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"värde: 10\nvärde: 9\nvärde: 8"}]}]},{"type":"element","tagName":"h3","properties":{"id":"minska-raknarens-varde","style":"position:relative;"},"children":[{"type":"text","value":"Minska räknarens värde"},{"type":"element","tagName":"a","properties":{"href":"#minska-raknarens-varde","ariaLabel":"minska raknarens varde permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Komplettera metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"minska"}]},{"type":"text","value":" som definieras i mallen, så att den minskar värdet som lagras i räknaren med ett. Se exemplet ovan för förväntat beteende."}]},{"type":"element","tagName":"h3","properties":{"id":"raknaren-far-inte-ha-ett-negativt-varde","style":"position:relative;"},"children":[{"type":"text","value":"Räknaren får inte ha ett negativt värde"},{"type":"element","tagName":"a","properties":{"href":"#raknaren-far-inte-ha-ett-negativt-varde","ariaLabel":"raknaren far inte ha ett negativt varde permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Lägg till funktionalitet till din "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"minska"}]},{"type":"text","value":"-metod, så att räknarens värde aldrig når negativa värden. Om värdet på räknaren är 0 kommer den inte att minskas ytterligare."}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"raknare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" MinskandeRaknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"minska"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"minska"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"minska"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"värde: 2\nvärde: 1\nvärde: 0\nvärde: 0"}]}]},{"type":"element","tagName":"h3","properties":{"id":"nollande-av-raknaren","style":"position:relative;"},"children":[{"type":"text","value":"Nollande av räknaren"},{"type":"element","tagName":"a","properties":{"href":"#nollande-av-raknaren","ariaLabel":"nollande av raknaren permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en metod "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"nolla"}]},{"type":"text","value":" som sätter värdet på räknaren till 0:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"raknare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" MinskandeRaknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"100"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"nolla"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"värde: 100\nvärde: 0"}]}]},{"type":"element","tagName":"h3","properties":{"id":"aterstallning-av-raknaren","style":"position:relative;"},"children":[{"type":"text","value":"Återställning av räknaren"},{"type":"element","tagName":"a","properties":{"href":"#aterstallning-av-raknaren","ariaLabel":"aterstallning av raknaren permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en metod "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"aterstall_ursprungligt_varde()"}]},{"type":"text","value":", som återställer räknaren till sitt ursprungliga tillstånd:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"raknare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" MinskandeRaknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"55"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"minska"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"minska"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"minska"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"minska"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"aterstall_ursprungligt_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nraknare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"skriv_ut_varde"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"värde: 51\nvärde: 55"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Som avslutning på detta avsnitt tittar vi på en klass som modellerar en spelares personliga bästa. Klassdefinitionen innehåller separata valideringsmetoder som kontrollerar att de argument som skickas är giltiga. Metoderna anropas redan i konstruktorn. Detta säkerställer att det skapade objektet är sunt internt."}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"from"}]},{"type":"text","value":" datetime "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"import"}]},{"type":"text","value":" date\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"PersonligtRekord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" spelare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" dag"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" manad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" ar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" poang"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Standardvärden"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"spelare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"\""}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"datum "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" date"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1900"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"poang "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn_ok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"spelare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"spelare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" spelare\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"dtm_ok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"dag"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" manad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" ar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"datum "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" date"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" manad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" dag"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"poang_ok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"poang"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"poang "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" poang\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Hjälparmetoder som kollar att argumenten är giltiga"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"namn_ok"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Namnet ska vara minst två tecken"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"dtm_ok"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" dag"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" manad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" ar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"try"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n date"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" manad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" dag"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"True"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"except"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Ett undantag ifall datumet inte är giltigt"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"False"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"poang_ok"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" poang"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" poang "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n resultat1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" PersonligtRekord"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"11"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2020"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"235"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"resultat1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"poang"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"resultat1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"spelare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"resultat1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"datum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Datumet är inte giltigt"}]},{"type":"text","value":"\n resultat2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" PersonligtRekord"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Pernilla\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"13"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2019"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4555"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"resultat2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"poang"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"resultat2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"spelare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"resultat2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"datum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Skriver ut standardvärdet 1900-01-01"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"235\nPeter\n2020-11-01\n4555\nPernilla\n1900-01-01"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I exemplet ovan anropades även hjälpmetoderna via parameternamnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":" när de användes i konstruktorn. Det är också möjligt att inkludera /statiska/ metoddefinitioner i klassdefinitioner. Dessa är metoder som kan anropas utan att det någonsin skapas en instans av klassen. Vi återkommer till detta i nästa del."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Parameternamnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":" används endast när man hänvisar till /objektets egenskaper som en instans av klassen/. Det gäller både dataattributen och de metoder som är knutna till ett objekt. För att göra terminologin mer förvirrande kallas dataattributen och metoderna tillsammans ibland helt enkelt för objektets attribut, vilket är anledningen till att vi i detta material ofta har angett dataattribut när vi menar de variabler som definieras inom klassen. Det är här terminologin hos vissa Python-programmerare skiljer sig något från den terminologi som mer allmänt används inom objektorienterad programmering, där attribut vanligtvis bara hänvisar till dataattributen hos ett objekt."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Det är också möjligt att skapa lokala variabler inom metoddefinitioner utan att hänvisa till "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":". Detta bör du göra om det inte finns något behov av att komma åt variablerna utanför metoden. Lokala variabler inom metoder har inga speciella nyckelord; de används precis som alla vanliga variabler som du har stött på hittills. ."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Så här skulle det till exempel fungera:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Bonuskort"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" saldo\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"tillsatt_bonus"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Nu är variabeln bonus en lokal variabel, inte ett"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# data attribut till objektet"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Den kan inte nås genom ett objekt"}]},{"type":"text","value":"\n bonus "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0.25"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+="}]},{"type":"text","value":" bonus\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"tillsatt_superbonus"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Variabeln superbonus är också en lokal variabel."}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vanligtvis är hjälpvariabler lokala variabler eftersom"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# det inte finns något behov av att komma åt dem från andra"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# metoder i klassen eller direkt via ett objekt."}]},{"type":"text","value":"\n superbonus "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0.5"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+="}]},{"type":"text","value":" superbonus\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__str__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\"Bonuskort(namn="}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":", saldo="}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":")\""}]}]}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"För- och efternamn","tmcname":"osa08-10b_for_och_efternamn"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en klass "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Person"}]},{"type":"text","value":", som får "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"endast ett attribut"}]},{"type":"text","value":" "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"namn"}]},{"type":"text","value":", som ges till konstruktorn."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa dessutom två metoder:"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"ge_fornamn"}]},{"type":"text","value":" returnerar personens förnamn och metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"ge_efternamn"}]},{"type":"text","value":" på samma sätt personens efternamn."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Du kan anta att det namn som skickas till konstruktorn kommer att innehålla endast för- och efternamn åtskilda med ett mellanslag."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Exempel på användning:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n peter "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"peter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"ge_fornamn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"peter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"ge_efternamn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n pauli "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Pernilla Pythonson\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"pernilla"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"ge_fornamn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"pernilla"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"ge_efternamn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Peter\nPython\nPernilla\nPythonson"}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Nummerstatistik","tmcname":"osa08-11_nummerstatistik"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I den här övningen ska du skapa ett program för att arbeta med siffror, på samma sätt som i "},{"type":"element","tagName":"a","properties":{"href":"/ohjelmointi-24-sv/osa-2/4-yksinkertainen-silmukka#programming-exercise-lukujen-kasittelya"},"children":[{"type":"text","value":"slutet av modul 2"}]},{"type":"text","value":" i kursen Introduktion till Programmering. Den här gången ska du definiera en klass för ändamålet."}]},{"type":"element","tagName":"h3","properties":{"id":"mangden-nummer","style":"position:relative;"},"children":[{"type":"text","value":"Mängden nummer"},{"type":"element","tagName":"a","properties":{"href":"#mangden-nummer","ariaLabel":"mangden nummer permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa en klass med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Nummerstatistik"}]},{"type":"text","value":", med följande metoder:"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"tillsatt_nummer"}]},{"type":"text","value":" lägger till ett nytt nummer till statistiken"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"mangden_nummer"}]},{"type":"text","value":" returnerar mängden nummer som har tillsatts"}]},{"type":"text","value":"\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I det här skedet finns det inget behov av att lagra själva siffrorna i någon datastruktur. Det räcker att bara komma ihåg hur många som har lagts till. Metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"tillsatt_nummer"}]},{"type":"text","value":" tar emot ett argument, men det finns inget behov av att bearbeta det faktiska värdet på något sätt ännu."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen borde ha följande struktur:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"NummerStatistik"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"nummer "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"tillsatt_nummer"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"pass"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"mangden_nummer"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"pass"}]}]}]}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"statistik "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" NummerStatistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nstatistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nstatistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nstatistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nstatistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Mängden nummer:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" statistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"mangden_nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Mängden nummer: 4"}]}]},{"type":"element","tagName":"h3","properties":{"id":"summa-och-medeltal","style":"position:relative;"},"children":[{"type":"text","value":"Summa och medeltal"},{"type":"element","tagName":"a","properties":{"href":"#summa-och-medeltal","ariaLabel":"summa och medeltal permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Tillsätt följande metoder till klassdefinitionen:"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"summa"}]},{"type":"text","value":" returnerar summan av talen som satts till (en tom statistik returnerar 0)"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"medeltat"}]},{"type":"text","value":" returnerar medeltalet av numren (en tom statistiks medeltal är 0)"}]},{"type":"text","value":"\n"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"statistik "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" NummerStatistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nstatistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nstatistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nstatistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nstatistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Mängden nummer:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" statistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"mangden_nummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Summa:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" statistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"summa"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Medeltal:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" statistik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"medeltal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Mängd: 4\nSumma: 11\nMedeltal: 2.75"}]}]},{"type":"element","tagName":"h3","properties":{"id":"anvandarinmatning","style":"position:relative;"},"children":[{"type":"text","value":"Användarinmatning"},{"type":"element","tagName":"a","properties":{"href":"#anvandarinmatning","ariaLabel":"anvandarinmatning permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skriv ett huvudprogram som fortsätter att fråga användaren om heltal tills användaren skriver in -1. Programmet ska sedan skriva ut summan och medelvärdet av de inmatade talen."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ditt program ska använda "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"NummerStatistik"}]},{"type":"text","value":"-objekt för att hålla koll på numren som läggs till."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"OBS: Du behöver inte ändra "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"NummerStatistik"}]},{"type":"text","value":"-klassen, i denna del, använd en instans av klassen för att slutföra denna del."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"OBS2: Ditt huvudprogram ska inte vara inuti ett "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"if __name__ == \"__main__\""}]},{"type":"text","value":"-block, annars fungerar inte testen."}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ange nummer:\n"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"4"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"2"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"5"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"2"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"-1"}]},{"type":"text","value":"\nSumma: 13\nMedeltal: 3.25"}]}]},{"type":"element","tagName":"h3","properties":{"id":"flera-summor","style":"position:relative;"},"children":[{"type":"text","value":"Flera summor"},{"type":"element","tagName":"a","properties":{"href":"#flera-summor","ariaLabel":"flera summor permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Bygg på ditt huvudprogram så att det också separat räknar summan av de jämna och udda tal som läggs till."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"OBS: Ändra inte din "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"NummerStatistik"}]},{"type":"text","value":"-klassdefinition i denna del av övningen heller. Definiera i stället tre "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"NummerStatistik"}]},{"type":"text","value":"-objekt. Ett av dem ska hålla reda på alla siffror, ett annat ska hålla reda på de jämna siffrorna och det tredje ska hålla reda på de udda siffror som skrivs in."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"OBS2: Ditt huvudprogram ska inte vara inuti ett "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"if __name__ == \"__main__\""}]},{"type":"text","value":"-block, annars fungerar inte testen."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Programmet ska fungera så här:"}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ange nummer:\n"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"4"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"2"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"5"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"2"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"-1"}]},{"type":"text","value":"\nSumma: 13\nMedeltal: 3.25\nJämna talens summa: 8\nUdda talens summa: 5"}]}]}]}]},"html":"

    Efter den här delen:

      \n
    • Vet du hur klassmetoder fungerar
    • \n
    • Kan du skriva nya metoder i dina egna klasser
    • \n
    • Kommer du att förstå begreppen inkapsling och klient inom objektorienterad programmering
    • \n

    Klasser som endast innehåller dataattribut skiljer sig inte så mycket från ordlistor. Nedan kan du se två sätt att modellera ett bankkonto, först med en klassdefinition och sedan med hjälp av en ordlista.

    # Exempel 1: bankkoto med klassdefinition\nclass Bankkonto:\n\n    def __init__(self, kontonummer: str, agare: str, saldo: float, arsranta: float):\n        self.kontonummer = kontonummer\n        self.agare = agare\n        self.saldo = saldo\n        self.arsranta = arsranta\n\npeters_konto = Bankkonto(\"12345-678\", \"Peter Python\", 1500.0, 0.015)
    # Exempel2: bankkonto med ordlista\npeters_konto = {\"kontonummer\": \"12345-678\", \"agare\": \"Peter Python\", \"saldo\": 1500.0, \"arsranta\": 0.0}

    Med en ordlista är implementeringen mycket kortare och enklare. Med en klass är strukturen däremot mer \"hårt bunden\", så vi kan förvänta oss att alla Bankkonto-objekt är strukturellt lika. Dessutom är en klass också namngiven. Klassen Bankkonto refereras till när ett nytt bankkonto skapas, och objektets typ är Bankkonto, inte dict.

    En annan stor fördel med klasser är att de förutom data även kan innehålla funktionalitet. En av de vägledande principerna för objektorienterad programmering är att ett objekt används för att komma åt både den data som är kopplad till ett objekt och funktionaliteten för att bearbeta denna data.

    Metoder i klasser

    En metod är ett underprogram eller en funktion som är knuten till en specifik klass. Vanligtvis påverkar en metod bara ett enda objekt. En metod definieras inom klassdefinitionen och den kan komma åt klassens dataattribut precis som vilken annan variabel som helst.

    Låt oss fortsätta med klassen Bankkonto som introducerades ovan. Nedan har vi en ny metod som lägger till ränta på kontot:

    class Bankkonto:\n\n    def __init__(self, kontonummer: str, agare: str, saldo: float, arsranta: float):\n        self.kontonummer = kontonummer\n        self.agare = agare\n        self.saldo = saldo\n        self.arsranta = arsranta\n\n    # Metoden lägger till den årliga räntat till saldot\n    def tillsatt_ranta(self):\n        self.saldo += self.saldo * self.arsranta\n\n\npeters_konto = Bankkonto(\"12345-678\", \"Peter Python\", 1500.0, 0.015)\npeters_konto.tillsatt_ranta()\nprint(peters_konto.saldo)

    1522.5

    Metoden tillsatt_ranta multiplicerar saldot på kontot med den årliga ränteprocenten och lägger sedan till resultatet till det aktuella saldot. Metoden verkar bara på det objekt som den anropas på.

    Låt oss se hur detta fungerar när vi har skapat flera instanser av klassen:

    # Klassen Bankkonto är definierat såsom i förra exemplet\n\npeters_konto = Bankkonto(\"12345-678\", \"Peter Python\", 1500.0, 0.015)\npernillas_konto = Bankkonto(\"99999-999\", \"Pernilla Pythonson\", 1500.0, 0.05)\npers_konto = Bankkonto(\"1111-222\", \"Per Persson\", 1500.0, 0.001)\n\n# Vi tillsätter ränta till Peters och Pernillas konton, men inte Pers\npeters_konto.tillsatt_ranta()\npernillas_konto.tillsatt_ranta()\n\n# Vi skriver ut alla\nprint(peters_konto.saldo)\nprint(pernillas_konto.saldo)\nprint(pers_konto.saldo)

    1522.5\n1575.0\n1500.0

    Som du kan se ovan läggs den årliga räntan endast till på de konton som metoden anropas på. Eftersom den årliga räntan är olika för Peters och Paulas konton, blir resultatet olika för dessa två konton. Saldot på Pernillas konto ändras inte, eftersom metoden tillsatt_ranta inte anropas på objektet pernillas_konto.

    Inkapsling

    Inom objektorienterad programmering dyker ordet klient upp då och då. Det används för att hänvisa till ett kodavsnitt som skapar ett objekt och använder den tjänst som tillges av dess metoder. När data som finns i ett objekt endast används genom de metoder som det tillges, garanteras objektets interna integritet. I praktiken innebär detta att t.ex. en Bankkonto-klass erbjuder metoder för att hantera saldo-attributet, så att saldot aldrig nås direkt av klienten. Dessa metoder kan sedan verifiera att saldot till exempel inte tillåts gå under noll.

    Ett exempel på hur detta skulle fungera:

    class Bankkonto:\n\n    def __init__(self, kontonummer: str, agare: str, saldo: float, arsranta: float):\n        self.kontonummer = kontonummer\n        self.agare = agare\n        self.saldo = saldo\n        self.arsranta = arsranta\n\n    # Metoden tillsätter den årliga räntat till saldot av kontot\n    def tillsatt_ranta(self):\n        self.saldo += self.saldo * self.arsranta\n\n    # Den här metoden \"tar ut\" pengar från kontot\n    # Metoden returnerar True ifall det lyckades, och False ifall det misslyckades\n    def uttag(self, uttagssumma: float):\n        if uttagssumma <= self.saldo:\n            self.saldo -= uttagssumma\n            return True\n\n        return False\n\npeters_konto = Bankkonto(\"12345-678\", \"Peter Python\", 1500.0, 0.015)\n\nif peters_konto.uttag(1000):\n    print(\"Uttaget lyckades, kontots saldo är nu\", peters_konto.saldo)\nelse:\n    print(\"Uttaget lyckades inte, saldot var otillräckligt\")\n\n# Vi försöker på nytt\nif peters_konto.uttag(1000):\n    print(\"Uttaget lyckades, kontots saldo är nu\", peters_konto.saldo)\nelse:\n    print(\"Uttaget lyckades inte, saldot var otillräckligt\")

    Uttaget lyckades, kontots saldo är nu 500.0\nUttaget lyckades inte, saldot var otillräckligt

    Att bibehålla objektets interna integritet och erbjuda lämpliga metoder för att säkerställa detta kallas inkapsling. Tanken är att objektets inre arbete är dolt för klienten, men objektet erbjuder metoder som kan användas för att komma åt den data som lagras i objektet.

    Att lägga till en metod innebär inte att attributet automatiskt döljs. Även om klassdefinitionen Bankkonto innehåller metoden uttag för att ta ut pengar, kan klientkoden fortfarande komma åt och ändra attributet saldo direkt:

    peters_konto = Bankkonto(\"12345-678\", \"Peter Python\", 1500.0, 0.015)\n\n# Vi försöker lyfta 2000\nif peters_konto.uttag(2000):\n    print(\"Uttaget lyckades, kontots saldo är nu\", peters_konto.saldo)\nelse:\n    print(\"Uttaget lyckades inte, saldot var otillräckligt\")\n\n    # Vi \"tvingar\" ett uttag på 2000\n    peters_konto.saldo -= 2000\n\nprint(\"Saldot är nu:\", peters_konto.saldo)

    Det är möjligt att dölja dataattributen från klientkoden, vilket kan bidra till att lösa detta problem. Vi återkommer till detta ämne i nästa del.

    Denna övning har flera delar. Varje del är värt ett poäng och kan lämnas in separat.

    Övningsmallen innehåller en delvis ifylld klass MinskandeRaknare:

    class MinskandeRaknare:\n    def __init__(self, borjan_varde: int):\n        self.varde = borjan_varde\n\n    def skriv_ut_varde(self):\n        print(\"värde:\", self.varde)\n\n    def minska(self):\n        pass\n\n    # resten av metoderna här

    Klassen används på följande sätt:

    raknare = MinskandeRaknare(10)\nraknare.skriv_ut_varde()\nraknare.minska()\nraknare.skriv_ut_varde()\nraknare.minska()\nraknare.skriv_ut_varde()

    värde: 10\nvärde: 9\nvärde: 8

    Minska räknarens värde

    Komplettera metoden minska som definieras i mallen, så att den minskar värdet som lagras i räknaren med ett. Se exemplet ovan för förväntat beteende.

    Räknaren får inte ha ett negativt värde

    Lägg till funktionalitet till din minska-metod, så att räknarens värde aldrig når negativa värden. Om värdet på räknaren är 0 kommer den inte att minskas ytterligare.

    raknare = MinskandeRaknare(2)\nraknare.skriv_ut_varde()\nraknare.minska()\nraknare.skriv_ut_varde()\nraknare.minska()\nraknare.skriv_ut_varde()\nraknare.minska()\nraknare.skriv_ut_varde()

    värde: 2\nvärde: 1\nvärde: 0\nvärde: 0

    Nollande av räknaren

    Skapa en metod nolla som sätter värdet på räknaren till 0:

    raknare = MinskandeRaknare(100)\nraknare.skriv_ut_varde()\nraknare.nolla()\nraknare.skriv_ut_varde()

    värde: 100\nvärde: 0

    Återställning av räknaren

    Skapa en metod aterstall_ursprungligt_varde(), som återställer räknaren till sitt ursprungliga tillstånd:

    raknare = MinskandeRaknare(55)\nraknare.minska()\nraknare.minska()\nraknare.minska()\nraknare.minska()\nraknare.skriv_ut_varde()\nraknare.aterstall_ursprungligt_varde()\nraknare.skriv_ut_varde()

    värde: 51\nvärde: 55

    Som avslutning på detta avsnitt tittar vi på en klass som modellerar en spelares personliga bästa. Klassdefinitionen innehåller separata valideringsmetoder som kontrollerar att de argument som skickas är giltiga. Metoderna anropas redan i konstruktorn. Detta säkerställer att det skapade objektet är sunt internt.

    from datetime import date\n\nclass PersonligtRekord:\n\n    def __init__(self, spelare: str, dag: int, manad: int, ar: int, poang: int):\n        # Standardvärden\n        self.spelare = \"\"\n        self.datum = date(1900, 1, 1)\n        self.poang = 0\n\n        if self.namn_ok(spelare):\n            self.spelare = spelare\n\n        if self.dtm_ok(dag, manad, ar):\n            self.datum = date(ar, manad, dag)\n\n        if self.poang_ok(poang):\n            self.poang = poang\n\n    # Hjälparmetoder som kollar att argumenten är giltiga\n    def namn_ok(self, namn: str):\n        return len(namn) >= 2 # Namnet ska vara minst två tecken\n\n    def dtm_ok(self, dag, manad, ar):\n        try:\n            date(ar, manad, dag)\n            return True\n        except:\n            # Ett undantag ifall datumet inte är giltigt\n            return False\n\n    def poang_ok(self, poang):\n        return poang >= 0\n\nif __name__ == \"__main__\":\n    resultat1 = PersonligtRekord(\"Peter\", 1, 11, 2020, 235)\n    print(resultat1.poang)\n    print(resultat1.spelare)\n    print(resultat1.datum)\n\n    # Datumet är inte giltigt\n    resultat2 = PersonligtRekord(\"Pernilla\", 4, 13, 2019, 4555)\n    print(resultat2.poang)\n    print(resultat2.spelare)\n    print(resultat2.datum) # Skriver ut standardvärdet 1900-01-01

    235\nPeter\n2020-11-01\n4555\nPernilla\n1900-01-01

    I exemplet ovan anropades även hjälpmetoderna via parameternamnet self när de användes i konstruktorn. Det är också möjligt att inkludera /statiska/ metoddefinitioner i klassdefinitioner. Dessa är metoder som kan anropas utan att det någonsin skapas en instans av klassen. Vi återkommer till detta i nästa del.

    Parameternamnet self används endast när man hänvisar till /objektets egenskaper som en instans av klassen/. Det gäller både dataattributen och de metoder som är knutna till ett objekt. För att göra terminologin mer förvirrande kallas dataattributen och metoderna tillsammans ibland helt enkelt för objektets attribut, vilket är anledningen till att vi i detta material ofta har angett dataattribut när vi menar de variabler som definieras inom klassen. Det är här terminologin hos vissa Python-programmerare skiljer sig något från den terminologi som mer allmänt används inom objektorienterad programmering, där attribut vanligtvis bara hänvisar till dataattributen hos ett objekt.

    Det är också möjligt att skapa lokala variabler inom metoddefinitioner utan att hänvisa till self. Detta bör du göra om det inte finns något behov av att komma åt variablerna utanför metoden. Lokala variabler inom metoder har inga speciella nyckelord; de används precis som alla vanliga variabler som du har stött på hittills. .

    Så här skulle det till exempel fungera:

    class Bonuskort:\n    def __init__(self, namn: str, saldo: float):\n        self.namn = namn\n        self.saldo = saldo\n\n    def tillsatt_bonus(self):\n        # Nu är variabeln bonus en lokal variabel, inte ett\n        # data attribut till objektet\n        # Den kan inte nås genom ett objekt\n        bonus = self.saldo * 0.25\n        self.saldo += bonus\n\n    def tillsatt_superbonus(self):\n        # Variabeln superbonus är också en lokal variabel.\n        # Vanligtvis är hjälpvariabler lokala variabler eftersom\n        # det inte finns något behov av att komma åt dem från andra\n        # metoder i klassen eller direkt via ett objekt.\n        superbonus = self.saldo * 0.5\n        self.saldo += superbonus\n\n    def __str__(self):\n        return f\"Bonuskort(namn={self.namn}, saldo={self.saldo})\"

    Skapa en klass Person, som får endast ett attribut namn, som ges till konstruktorn.

    Skapa dessutom två metoder:

    Metoden ge_fornamn returnerar personens förnamn och metoden ge_efternamn på samma sätt personens efternamn.

    Du kan anta att det namn som skickas till konstruktorn kommer att innehålla endast för- och efternamn åtskilda med ett mellanslag.

    Exempel på användning:

    if __name__ == \"__main__\":\n    peter = Person(\"Peter Python\")\n    print(peter.ge_fornamn())\n    print(peter.ge_efternamn())\n\n    pauli = Person(\"Pernilla Pythonson\")\n    print(pernilla.ge_fornamn())\n    print(pernilla.ge_efternamn())

    Peter\nPython\nPernilla\nPythonson

    I den här övningen ska du skapa ett program för att arbeta med siffror, på samma sätt som i slutet av modul 2 i kursen Introduktion till Programmering. Den här gången ska du definiera en klass för ändamålet.

    Mängden nummer

    Skapa en klass med namnet Nummerstatistik, med följande metoder:

      \n
    • metoden tillsatt_nummer lägger till ett nytt nummer till statistiken
    • \n
    • metoden mangden_nummer returnerar mängden nummer som har tillsatts
    • \n

    I det här skedet finns det inget behov av att lagra själva siffrorna i någon datastruktur. Det räcker att bara komma ihåg hur många som har lagts till. Metoden tillsatt_nummer tar emot ett argument, men det finns inget behov av att bearbeta det faktiska värdet på något sätt ännu.

    Funktionen borde ha följande struktur:

    class  NummerStatistik:\n    def __init__(self):\n        self.nummer = 0\n\n    def tillsatt_nummer(self, nummer:int):\n        pass\n\n    def mangden_nummer(self):\n        pass
    statistik = NummerStatistik()\nstatistik.tillsatt_nummer(3)\nstatistik.tillsatt_nummer(5)\nstatistik.tillsatt_nummer(1)\nstatistik.tillsatt_nummer(2)\nprint(\"Mängden nummer:\", statistik.mangden_nummer())

    Mängden nummer: 4

    Summa och medeltal

    Tillsätt följande metoder till klassdefinitionen:

      \n
    • metoden summa returnerar summan av talen som satts till (en tom statistik returnerar 0)
    • \n
    • metoden medeltat returnerar medeltalet av numren (en tom statistiks medeltal är 0)
    • \n
    statistik = NummerStatistik()\nstatistik.tillsatt_nummer(3)\nstatistik.tillsatt_nummer(5)\nstatistik.tillsatt_nummer(1)\nstatistik.tillsatt_nummer(2)\nprint(\"Mängden nummer:\", statistik.mangden_nummer())\nprint(\"Summa:\", statistik.summa())\nprint(\"Medeltal:\", statistik.medeltal())

    Mängd: 4\nSumma: 11\nMedeltal: 2.75

    Användarinmatning

    Skriv ett huvudprogram som fortsätter att fråga användaren om heltal tills användaren skriver in -1. Programmet ska sedan skriva ut summan och medelvärdet av de inmatade talen.

    Ditt program ska använda NummerStatistik-objekt för att hålla koll på numren som läggs till.

    OBS: Du behöver inte ändra NummerStatistik-klassen, i denna del, använd en instans av klassen för att slutföra denna del.

    OBS2: Ditt huvudprogram ska inte vara inuti ett if __name__ == \"__main__\"-block, annars fungerar inte testen.

    Ange nummer:\n4\n2\n5\n2\n-1\nSumma: 13\nMedeltal: 3.25

    Flera summor

    Bygg på ditt huvudprogram så att det också separat räknar summan av de jämna och udda tal som läggs till.

    OBS: Ändra inte din NummerStatistik-klassdefinition i denna del av övningen heller. Definiera i stället tre NummerStatistik-objekt. Ett av dem ska hålla reda på alla siffror, ett annat ska hålla reda på de jämna siffrorna och det tredje ska hålla reda på de udda siffror som skrivs in.

    OBS2: Ditt huvudprogram ska inte vara inuti ett if __name__ == \"__main__\"-block, annars fungerar inte testen.

    Programmet ska fungera så här:

    Ange nummer:\n4\n2\n5\n2\n-1\nSumma: 13\nMedeltal: 3.25\nJämna talens summa: 8\nUdda talens summa: 5

    ","frontmatter":{"path":"/osa-8/4-metoder-i-egna-klasser","title":"Metoder i egna klasser"},"fileAbsolutePath":"/home/runner/work/ohjelmointi-24-sv/ohjelmointi-24-sv/data/osa-8/4-metoder-i-egna-klasser.md"},"allPages":{"edges":[{"node":{"id":"b5e8ae41-d492-55f7-88a7-1c7292333ab1","frontmatter":{"path":"/arvostelu-ja-kokeet","title":"Arvostelu ja kokeet"}}},{"node":{"id":"af4df6be-211d-5ba1-acea-9edbefa06c49","frontmatter":{"path":"/frontmatter-guide","title":"Frontmatter-guide"}}},{"node":{"id":"56769133-4836-5fbb-a857-8fb0c6803e6d","frontmatter":{"path":"/","title":"Tietoa kurssista"}}},{"node":{"id":"e86762f0-c2a9-5598-aba3-2b8d7db7807c","frontmatter":{"path":"/kaikki-tehtavat","title":"Kaikki tehtävät"}}},{"node":{"id":"5d065309-85e8-5823-9527-ec1c3cf38d4d","frontmatter":{"path":"/tuki","title":"Tukea tehtäviin"}}},{"node":{"id":"ac195ee0-ad04-5cc9-9643-963f93d29ad2","frontmatter":{"path":"/usein-kysytyt-kysymykset","title":"Usein kysytyt kysymykset"}}},{"node":{"id":"51a165d7-8ce5-5d53-9c15-5321b6adef8c","frontmatter":{"path":"/verkkotentti","title":"Verkkotentti 4.6."}}},{"node":{"id":"4d9cf293-01e9-5e6c-a88f-599560e33c9a","frontmatter":{"path":"/verkkotentti-ohja","title":"Ohjelmoinnin jatkokurssin verkkotentti 16.12."}}},{"node":{"id":"279e1cca-fb0b-5d3f-b527-be05243d138d","frontmatter":{"path":"/verkkotentti-ohpe","title":"Ohjelmoinnin perusteiden verkkotentti 09.03."}}},{"node":{"id":"347bdde4-ba21-5f22-8a88-0287dfe29a45","frontmatter":{"path":"/virheilmoitukset","title":"Yleiset virheilmoitukset"}}},{"node":{"id":"3bf12e3a-1542-57f4-812d-dd32cebc99e2","frontmatter":{"path":"/sanasto","title":"Sanasto"}}},{"node":{"id":"9910673b-d62d-5d8d-a756-5267160d891f","frontmatter":{"path":"/osa-1/1-introduktion","title":"Introduktion"}}},{"node":{"id":"0b17a28e-f939-57cc-aa5b-4db407cdf34a","frontmatter":{"path":"/osa-1/2-info-fran-anvandaren","title":"Information från användaren"}}},{"node":{"id":"b95794f2-f3b3-597c-a4ec-6f023b584f81","frontmatter":{"path":"/osa-1/3-mer-om-variabler","title":"Mer om variabler"}}},{"node":{"id":"02cd0849-e7a5-5fd1-bf66-35f0197d3e75","frontmatter":{"path":"/osa-1/4-rakneoperationer","title":"Räkneoperationer"}}},{"node":{"id":"42690a69-3997-5b84-b999-15d9c3212884","frontmatter":{"path":"/osa-1/5-villkorssatser","title":"If-satser"}}},{"node":{"id":"96a0ec65-c0a3-5150-95c5-48c260f88162","frontmatter":{"path":"/osa-1","title":"Modul 1"}}},{"node":{"id":"e7a4d0c8-b8c1-53fa-ab51-9cc06fd417a3","frontmatter":{"path":"/osa-10/1-klasshierarkier","title":"Klasshierarkier"}}},{"node":{"id":"5f6d4b8b-7d05-5c79-9f2f-9e30b397167b","frontmatter":{"path":"/osa-10/2-atkamstmodifierare","title":"Åtkomstmodifierare"}}},{"node":{"id":"bb896c90-aabc-5a9d-8d4b-50839da286db","frontmatter":{"path":"/osa-10/3-objektorienterade-programmeringstekniker","title":"Objektorienterade programmeringstekniker"}}},{"node":{"id":"a2dca4f1-d64d-5e77-a3ca-8b2a208e9afa","frontmatter":{"path":"/osa-10/4-storre-applikation","title":"Att utveckla en större applikation"}}},{"node":{"id":"8c9cf5a7-f02e-5ccf-ab8f-f078c3ccecb6","frontmatter":{"path":"/osa-10","title":"Modul 10"}}},{"node":{"id":"f6688d26-5502-5c17-a8ee-db66f650f1f1","frontmatter":{"path":"/osa-11/1-list-comprehension","title":"List comprehension"}}},{"node":{"id":"1eac8489-72f2-5d53-904b-c960e2622018","frontmatter":{"path":"/osa-11/2-mer-om-comprehensions","title":"Mer om comprehensions"}}},{"node":{"id":"09630fca-7768-53f3-8aca-6e5ac638fc68","frontmatter":{"path":"/osa-11/3-rekursion","title":"Rekursion"}}},{"node":{"id":"70f6008e-a762-574c-a92a-c5c585d9677e","frontmatter":{"path":"/osa-11/4-lisaa-esimerkkeja","title":"Fler exempel på rekursion"}}},{"node":{"id":"eb8ed7d7-c39d-52db-949d-f75649498c67","frontmatter":{"path":"/osa-11","title":"Modul 11"}}},{"node":{"id":"9bba31dc-e14c-5400-a25b-7339107e9ba7","frontmatter":{"path":"/osa-12/1-funktioner-som-argument","title":"Funktioner som argument"}}},{"node":{"id":"5b9e4584-7234-5216-a118-d2a1bc617e13","frontmatter":{"path":"/osa-12/2-generatorer","title":"Generatorer"}}},{"node":{"id":"1d27636e-74f4-5c30-a1d8-08a303684945","frontmatter":{"path":"/osa-12/3-funktionell-programmering","title":"Funktionell programmering"}}},{"node":{"id":"6785750f-f145-5b88-81e9-b52e36ba53c6","frontmatter":{"path":"/osa-12/4-reguljara-uttryck","title":"Reguljära uttryck"}}},{"node":{"id":"d21df33a-4bf4-5ee3-9e2a-431d57561f09","frontmatter":{"path":"/osa-12","title":"Modul 12"}}},{"node":{"id":"14e3c129-50ec-581f-8679-8132248d41c1","frontmatter":{"path":"/osa-13/1-pygame","title":"Pygame"}}},{"node":{"id":"01bc3b9b-4f80-5561-8b56-3a7f09082263","frontmatter":{"path":"/osa-13/2-animation","title":"Animation"}}},{"node":{"id":"dd68786f-e2fc-5957-b47a-52b74c5199ef","frontmatter":{"path":"/osa-13/3-handelser","title":"Händelser"}}},{"node":{"id":"4a1aaa41-d6f7-51cd-8b89-95842cb9e02d","frontmatter":{"path":"/osa-13/4-fler-pygame-tekniker","title":"Fler pygame-tekniker"}}},{"node":{"id":"cdcf0ce1-e881-5ca6-8fa9-d0d343ec4e15","frontmatter":{"path":"/osa-13","title":"Modul 13"}}},{"node":{"id":"0ab28435-7654-5a8e-88d6-daa17d78103b","frontmatter":{"path":"/osa-14/1-spelprojekt","title":"Spelprojekt"}}},{"node":{"id":"b7a0628c-e4ba-583e-a52a-dd0ad78028d8","frontmatter":{"path":"/osa-14/2-robot-och-ladar","title":"Robot och lådor"}}},{"node":{"id":"6ccdbdff-7539-5a23-b23c-2ad48a99386f","frontmatter":{"path":"/osa-14/3-fardigstallande-av-spelet","title":"Färdigställande av spelet"}}},{"node":{"id":"1b505c9f-9b1b-58bd-8df7-553fef49cc8d","frontmatter":{"path":"/osa-14/4-ditt-eget-sepl","title":"Ditt eget spel"}}},{"node":{"id":"55c54859-8c7f-5fd9-8a8d-2c54ee677577","frontmatter":{"path":"/osa-14","title":"Modul 14"}}},{"node":{"id":"b5c346d1-d175-5824-98bb-4a4c3b45204d","frontmatter":{"path":"/osa-2/1-terminologi","title":"Programmeringsterminologi"}}},{"node":{"id":"db7188b0-0253-5c30-b8d2-0e115e235fb3","frontmatter":{"path":"/osa-2/2-else-elif","title":"Mera om if-satser"}}},{"node":{"id":"49d15928-f8b9-5883-9f29-86c307f6929e","frontmatter":{"path":"/osa-2/3-kombinera-villkor","title":"Kombinera villkor"}}},{"node":{"id":"93f1f9c8-6b27-5892-8bd4-7d1d008bf07a","frontmatter":{"path":"/osa-2/4-loopar","title":"Enkla loopar"}}},{"node":{"id":"5523b5b8-61f8-506d-bfe0-c6cc774390ce","frontmatter":{"path":"/osa-2","title":"Modul 2"}}},{"node":{"id":"02012307-c2a6-5cf2-9105-c10933c14b37","frontmatter":{"path":"/osa-3/1-loopar-med-villkor","title":"Loopar med villkor"}}},{"node":{"id":"efb889f4-4a19-515e-a0f6-4297d76a2757","frontmatter":{"path":"/osa-3/2-behandla-strangar","title":"Behandla strängar"}}},{"node":{"id":"a602077d-bbae-5eb7-a354-cc44b29ae96a","frontmatter":{"path":"/osa-3/3-mer-om-loopar","title":"Mera om loopar"}}},{"node":{"id":"6d878692-b9c7-57e6-ae58-044e5a6bef6f","frontmatter":{"path":"/osa-3/4-definiera-funktioner","title":"Definiera funktioner"}}},{"node":{"id":"682b5a18-73c5-56e2-8374-237baccbab40","frontmatter":{"path":"/osa-3","title":"Modul 3"}}},{"node":{"id":"3de95518-6b44-54db-9bcd-0c90a41d2fd5","frontmatter":{"path":"/osa-4/1-vscode","title":"Editorn Visual Studio Code, Pythontolken och det inbyggda debuggningsverktyget"}}},{"node":{"id":"7de9921c-7f94-58fe-84b9-7676dddb3b94","frontmatter":{"path":"/osa-4/2-mer-om-funktioner","title":"Mer om funktioner"}}},{"node":{"id":"29e29c69-360c-5f5c-8f34-5aef22eb327f","frontmatter":{"path":"/osa-4/3-listor","title":"Listor"}}},{"node":{"id":"bfe57880-0cbb-54e4-be9c-8fa180eafe6b","frontmatter":{"path":"/osa-4/4-iteration","title":"Iteration"}}},{"node":{"id":"2eab46f0-5373-5cbe-b2a0-1d071854a053","frontmatter":{"path":"/osa-4/5-utskrift","title":"Formatera utskrift"}}},{"node":{"id":"a5974fee-f2eb-5b89-88a5-6dd3754baaad","frontmatter":{"path":"/osa-4/6-strangar-listor","title":"Mera strängar och listor"}}},{"node":{"id":"e125c469-ee19-505e-9a41-83da6143ecd8","frontmatter":{"path":"/osa-4","title":"Modul 4"}}},{"node":{"id":"2558444a-be1d-5bc6-95ab-e091da2443fc","frontmatter":{"path":"/osa-5/1-mer-om-listor","title":"Mer om listor"}}},{"node":{"id":"b452d9be-0569-56c2-ba89-a040d4cb40dc","frontmatter":{"path":"/osa-5/2-referenser","title":"Referenser"}}},{"node":{"id":"ebe4ca3f-e657-5907-bfcc-ae84d9947aff","frontmatter":{"path":"/osa-5/3-lexikon","title":"Lexikon"}}},{"node":{"id":"f1dd5d66-ac87-5e53-92a0-0b7e3ece6ed8","frontmatter":{"path":"/osa-5/4-tuple","title":"Tuple"}}},{"node":{"id":"161c0109-5c00-5bed-b7af-90dc7ddf5713","frontmatter":{"path":"/osa-5","title":"Modul 5"}}},{"node":{"id":"e6cfa6e1-e99b-50e0-bc6a-3c0f153420e8","frontmatter":{"path":"/osa-6/1-lasa-filer","title":"Läsa filer"}}},{"node":{"id":"ce8d90a4-ca7c-5797-abc1-3fe0094bfa4b","frontmatter":{"path":"/osa-6/2-skriva-filer","title":"Skriva filer"}}},{"node":{"id":"519d5330-277a-59ba-be50-c2f63080df94","frontmatter":{"path":"/osa-6/3-fel","title":"Förbered dig på fel"}}},{"node":{"id":"82393756-3ef8-5d07-a8da-fed818ca43f0","frontmatter":{"path":"/osa-6/4-lokala-globala-variabler","title":"Lokala och globala variabler"}}},{"node":{"id":"007d85ae-a118-5b10-8a7e-18302b15eba8","frontmatter":{"path":"/osa-6","title":"Modul 6"}}},{"node":{"id":"bbb2346d-b1ee-551d-89c1-516f119b0eed","frontmatter":{"path":"/osa-7/1-moduler","title":"Moduler"}}},{"node":{"id":"ecb9af64-49f9-5e28-a544-3934e95233cf","frontmatter":{"path":"/osa-7/2-slumpmassighet","title":"Slumpmässighet"}}},{"node":{"id":"ebe469ef-c486-523a-9621-5dc4040c5cd8","frontmatter":{"path":"/osa-7/3-tid-datum","title":"Tid och datum"}}},{"node":{"id":"b9cf2d99-08f6-5de5-8425-c9b483241567","frontmatter":{"path":"/osa-7/4-behandla-data","title":"Behandla data"}}},{"node":{"id":"27075b37-8a6a-5554-9079-465a36d2da2d","frontmatter":{"path":"/osa-7/5-egna-moduler","title":"Skapa dina egna moduler"}}},{"node":{"id":"69492225-4d69-59ea-b33d-5301d35cf4ed","frontmatter":{"path":"/osa-7/6-funktionaliteter-python","title":"Flera funktionaliteter i Python"}}},{"node":{"id":"70ae841a-e6e9-5252-afae-6329fb67bcad","frontmatter":{"path":"/osa-7","title":"Modul 7"}}},{"node":{"id":"4afc4486-3cfe-53d1-b4c0-6db26484acfa","frontmatter":{"path":"/osa-8/1-objekt-och-metoder","title":"Objekt och metoder"}}},{"node":{"id":"6be37772-e94b-5b36-8a02-fffa7eef9feb","frontmatter":{"path":"/osa-8/2-klasser-och-objekt","title":"Klasser och objekt"}}},{"node":{"id":"8b6aec39-f8b9-525c-9f25-d8e73389fa42","frontmatter":{"path":"/osa-8/3-egna-klasser","title":"Egna klasser"}}},{"node":{"id":"85db460a-77c6-5087-8e97-a3c772186fd9","frontmatter":{"path":"/osa-8/4-metoder-i-egna-klasser","title":"Metoder i egna klasser"}}},{"node":{"id":"0e59dee0-5dd9-5827-83b9-a55e7d585c31","frontmatter":{"path":"/osa-8/5-fler-exempel","title":"Fler exempel"}}},{"node":{"id":"64715d0c-54f1-5aa7-a566-d2c5be6523ea","frontmatter":{"path":"/osa-8","title":"Modul 8"}}},{"node":{"id":"f7457509-a9a6-5420-8d03-ff1c61df8dc4","frontmatter":{"path":"/osa-9/1-objekt-och-referenser","title":"Objekt och referenser"}}},{"node":{"id":"16689ce4-b6aa-5bc4-9a30-44820994d6ea","frontmatter":{"path":"/osa-9/2-objekt-som-attribut","title":"Objekt som attribut "}}},{"node":{"id":"07985959-e85a-5f45-8923-babacb943c04","frontmatter":{"path":"/osa-9/3-inkapsling","title":"Inkapsling"}}},{"node":{"id":"83108600-9a37-5fd1-9a2b-13492879a9d6","frontmatter":{"path":"/osa-9/4-metodernas-rackvidd","title":"Metodernas räckvidd"}}},{"node":{"id":"a553cdc9-d6ac-5a14-ab43-d44811b407a2","frontmatter":{"path":"/osa-9/5-klassattribut","title":"Klassattribut"}}},{"node":{"id":"f7d7c9f1-6b54-5268-a308-995d49dd913d","frontmatter":{"path":"/osa-9/6-fler-exempel-med-klasser","title":"Fler exempel med klasser"}}},{"node":{"id":"c1fef3f7-8ca3-5780-9dec-19bd672b4627","frontmatter":{"path":"/osa-9","title":"Modul 9"}}}]}},"pageContext":{}}, "staticQueryHashes": ["1357757885","994120085"]} \ No newline at end of file diff --git a/page-data/osa-9/1-objekt-och-referenser/page-data.json b/page-data/osa-9/1-objekt-och-referenser/page-data.json index 5ee84da28..9dc51e874 100644 --- a/page-data/osa-9/1-objekt-och-referenser/page-data.json +++ b/page-data/osa-9/1-objekt-och-referenser/page-data.json @@ -1,5 +1,5 @@ { "componentChunkName": "component---src-templates-course-content-template-js", "path": "/osa-9/1-objekt-och-referenser", - "result": {"data":{"page":{"htmlAst":{"type":"element","tagName":"div","properties":{},"children":[{"type":"element","tagName":"text-box","properties":{"variant":"learningObjectives","name":"Inlärningsmål"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Efter den här delen"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Kommer du att kunna använda olika datastrukturer för att hantera objekt"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Vet du hur objekt kan bli passerade som argument"}]},{"type":"text","value":"\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Varje värde i Python är ett objekt. Alla objekt som du skapar baserat på en klass som du själv har definierat fungerar exakt på samma sätt som alla \"vanliga\" Python-objekt. Objekt kan till exempel lagras i en lista:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"from"}]},{"type":"text","value":" datetime "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"import"}]},{"type":"text","value":" date\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"SlutfordKurs"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kurs"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" studiepoang"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" slutforsdatum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" date"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"kurs "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" kurs\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"studiepoang "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" studiepoang\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"slutforsdatum "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" slutforsdatum\n\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi skapar några slutförda kurser och lägger dessa i en lista"}]},{"type":"text","value":"\n prestationer "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n mat1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" SlutfordKurs"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Matematik 1\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" date"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2020"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"11"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n prg1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" SlutfordKurs"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Programmering 1\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"6"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" date"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2019"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"12"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"17"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n prestationer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"mat1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n prestationer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"prg1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi lägger några till rakt till listan"}]},{"type":"text","value":"\n prestationer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"SlutfordKurs"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Fysik 2\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" date"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2019"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"11"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n prestationer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"SlutfordKurs"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Programmering 2\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" date"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2020"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"19"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi går igenom alla slutförda kurser, skriver ut deras namn och räknar ihop den totala mängden studiepoäng"}]},{"type":"text","value":"\n studiepoang "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" prestation "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" prestationer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"prestation"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"kurs"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n studiepoang "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+="}]},{"type":"text","value":" prestation"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"studiepoang\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Studiepoäng totalt:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" studiepoang"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Matematik 1\nProgrammering 1\nFysik 2\nProgrammering 2\nStudiepoäng totalt: 20"}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Snabbaste bilen","tmcname":"osa09-01_snabbaste_bil"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Uppgiftsbotten har en klass med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bil"}]},{"type":"text","value":" som representerar en bil genom två attribut: "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"marke (str)"}]},{"type":"text","value":" och "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"topphastighet (int)"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa funktionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"snabbaste_bil(bilar: list)"}]},{"type":"text","value":", som får en lista av "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bil"}]},{"type":"text","value":"-objekt som argument."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska returnera märket på den snabbaste bilen. Du kan anta att det alltid kommer att finnas en enda bil med den högsta topphastigheten. Ändra inte listan som ges som argument, gör heller inte några ändringar i klassdefinitionen för "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bil"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Du kan använda följande kod för att testa din funktion:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n bil1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bil"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Mersu\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"195"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n bil2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bil"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Lada\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"110"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n bil3 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bil"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Ferrari\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"280"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n bil4 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bil"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Trabant\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"85"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n bilar "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"bil1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" bil2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" bil3"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" bil4"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"snabbaste_bil"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"bilar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ferrari"}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Godkända prestationer","tmcname":"osa09-02_godkanda_prestationer"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I uppgiftsbotten hittas klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Provprestation"}]},{"type":"text","value":", som, liksom namnet anger, tar modell av en provtagares prestation i ett prov. Den har två attribut, "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"presterare (str)"}]},{"type":"text","value":" och "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"poang (int)"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa funktionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"godkanda(prestationer: list, poanggrans: int)"}]},{"type":"text","value":", som får som parametrar en lista av provprestationer och ett heltal som representerar det minsta poängantalet för att bli godkänd."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska skapa och returnera en ny lista, som innehåller endast de prov som kom över poänggränsen i den ursprungliga listan. Ändra inte listan som ges som argument, ändra heller inte definitionen för klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Provprestation"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Du kan använda följande kod för att testa funktionen:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n s1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Provprestation"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"12"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n s2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Provprestation"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Pernilla\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"19"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n s3 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Provprestation"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Per\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"15"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n s4 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Provprestation"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Pia\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"9"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n s5 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Provprestation"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Petra\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"17"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n klarade "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" godkanda"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"s1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" s2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" s3"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" s4"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" s5"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"15"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" godkand "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" klarade"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"klarade"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Provprestation (presterare: Pernilla, poang: 19)\nProvprestation (presterare: Per, poang: 15)\nProvprestation (presterare: Petra, poang: 17)"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Du kanske minns att listor inte innehåller några objekt i sig själva. De innehåller referenser till objekt. Exakt samma objekt kan förekomma flera gånger i en och samma lista, och det kan refereras till flera gånger i listan eller utanför den. Låt oss ta en titt på ett exempel:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Produkt"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" enhet"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"enhet "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" enhet\n\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n affarslista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n mjolk "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Produkt"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Mjölk\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"liter\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n affarslista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"mjolk"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n affarslista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"mjolk"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n affarslista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"Produkt"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Gurka\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"st\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-wrapper"],"style":"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 313px; margin-bottom: 1rem;"},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"a","properties":{"className":["gatsby-resp-image-link"],"href":"/ohjelmointi-24-sv/static/13e71ea262de820629eb873bb73f2d94/80977/9_1_1.png","style":"display: block","target":"_blank","rel":["noopener"]},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-background-image"],"style":"padding-bottom: 64.34782608695653%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAYAAACpUE5eAAAACXBIWXMAAAsTAAALEwEAmpwYAAABdUlEQVQ4y22TiarCQAxF+/9/pQVRLLihFKu4r1iXui8YOeHlMXa8UNLpJDc3SwP5w/v9VrtYLGS73crhcJD9fq/PbreT9XptrnK9XmW5XEqWZXqP/+VykXa7LUGeEIdfgNRAME8e0+nUJ1ytVhLHsQwGA6nVatLv9/V7mqb/gbfbTcbjsSRJoiT1el1Go5H6eoSUUqlUpFAoqGMYhnI6nVS5+dzvdw0uFosSRZFUq1UVQRKPcLPZaDmQPB4Pfce6JdNDzig9n896BpPJxCekwb9AIgMkx+PR86FNHiGZ6RcEnU5Her2eWlMBns+n3jNlSqV8EnyV7JKanc/nGoS173Zn4I7SDYE5uWRu862HEOeBKsp3474I8wpfr5cuOgqwBJPEhmHL7sYF+awuMQpoNIHD4VB7xFrRZ86z2eyLUEtuNpvSaDSkXC5Lq9XSEpk0JOyhAWX2lxiJTdoVEdjSWj/cS7YfUv7RUqmkEyUxIkje7XY9hR86hOegM+cgfwAAAABJRU5ErkJggg=='); background-size: cover; display: block;"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"picture","properties":{},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/13e71ea262de820629eb873bb73f2d94/a0b58/9_1_1.webp 230w","/ohjelmointi-24-sv/static/13e71ea262de820629eb873bb73f2d94/12766/9_1_1.webp 313w"],"sizes":"(max-width: 313px) 100vw, 313px","type":"image/webp"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/13e71ea262de820629eb873bb73f2d94/81c8e/9_1_1.png 230w","/ohjelmointi-24-sv/static/13e71ea262de820629eb873bb73f2d94/80977/9_1_1.png 313w"],"sizes":"(max-width: 313px) 100vw, 313px","type":"image/png"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"img","properties":{"className":["gatsby-resp-image-image"],"src":"/ohjelmointi-24-sv/static/13e71ea262de820629eb873bb73f2d94/80977/9_1_1.png","alt":"9 1 1","title":"9 1 1","loading":"lazy","decoding":"async","style":"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"},"children":[]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Om det finns mer än en referens till samma objekt spelar det ingen roll vilken av referenserna som används:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Hund"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__str__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn\n\nhundar "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\nmolly "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Hund"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Molly\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhundar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"molly"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhundar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"molly"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhundar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"Hund"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Molly\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Hundar i början:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" hund "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" hundar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"hund"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Hunden på index 0 får ett nytt namn:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhundar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Rex\""}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" hund "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" hundar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"hund"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Hunden på index 2 får ett nytt namn:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhundar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Fifi\""}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" hund "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" hundar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"hund"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Koirat alussa:\nMolly\nMolly\nMolly\nHunden på index 0 får ett nytt namn::\nRex\nRex\nMolly\nHunden på index 2 får ett nytt namn:\nRex\nRex\nFifi"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Referenserna på index 0 och 1 i listan hänvisar till samma objekt. Var och en av referenserna kan användas för att komma åt objektet. Referensen på index 2 hänvisar till ett annat objekt, men med till synes samma innehåll. Om innehållet i det senare objektet ändras påverkas inte det andra."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Operatorn "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"is"}]},{"type":"text","value":" används för att kontrollera om de två referenserna hänvisar till exakt samma objekt, medan operatorn "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" talar om för dig om innehållet i objekten är detsamma. Följande exempel gör förhoppningsvis skillnaden tydlig:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"lista1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\nlista2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\nlista3 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" lista1\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista1 "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"is"}]},{"type":"text","value":" lista2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista1 "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"is"}]},{"type":"text","value":" lista3"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista2 "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"is"}]},{"type":"text","value":" lista3"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" lista2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" lista3"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" lista3"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"False\nTrue\nFalse"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"True\nTrue\nTrue"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Alla Python-objekt kan också lagras i en ordlista eller någon annan datastruktur. Detta gäller även objekt som är av en klass som du själv har definierat."}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Studerande"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" sp"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"sp "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" sp\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi använder studerandenummer som nyckel och värdet som fås är ett objekt av typen Studerande"}]},{"type":"text","value":"\n studeranden "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n studeranden"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"12345\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Studerande"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Olle Studerande\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n studeranden"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"54321\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Studerande"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Ove Studerande\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"67"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"http://www.pythontutor.com/visualize.html#mode=edit","target":"_blank","rel":["noopener","noreferrer"]},"children":[{"type":"text","value":"Visualiseringsverktyget"}]},{"type":"text","value":" kan hjälpa dig att förstå exemplet ovan:"}]},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-wrapper"],"style":"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 920px; margin-bottom: 1rem;"},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"a","properties":{"className":["gatsby-resp-image-link"],"href":"/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/15171/9_1_2.png","style":"display: block","target":"_blank","rel":["noopener"]},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-background-image"],"style":"padding-bottom: 43.04347826086957%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAIAAAC9o5sfAAAACXBIWXMAABYlAAAWJQFJUiTwAAABPklEQVQoz2WR20rEMBBA/f+/8k0RFUVExdVda7ubtnHbSSfN3FLtVlHWA4E85DBnyEkYUow44Oj36PexB4wRpx9yzvPJ2cymf5xQSuM4ElHre1fvmSX/IGqA4xBHFgkBzPRYHgZ0BwIAMxFRSslynqbJeTi9uC9cr6ptceHr8zBcxXiNeKXazzIz9wcAYMkzs3yQY6Jy14ZILAJ+ReNONIqgCJrJLHddt1q9FEVRVVXT1AAQQmDmpXzJU5WuOuu7x3nv/CcbADabTVG873aurhvnnPfeOdc0zSHh9+lIXL7ddPvbMNwzl7OMiCmlnKcwUB+Sqi3xfycvmJl3dxHvRB5Ui28ZIxIRM5uZqorIcjn6HjMt15feX0K4IXqb5cQWQ6jK8nW93m63bdsy8zLnaPI05fDxHOOTyLNq9SV/Av8dBuHbnwNlAAAAAElFTkSuQmCC'); background-size: cover; display: block;"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"picture","properties":{},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/a0b58/9_1_2.webp 230w","/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/bc10c/9_1_2.webp 460w","/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/966d8/9_1_2.webp 920w","/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/445df/9_1_2.webp 1380w","/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/78de1/9_1_2.webp 1840w","/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/995bd/9_1_2.webp 2230w"],"sizes":"(max-width: 920px) 100vw, 920px","type":"image/webp"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/81c8e/9_1_2.png 230w","/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/08a84/9_1_2.png 460w","/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/c0255/9_1_2.png 920w","/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/b1001/9_1_2.png 1380w","/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/161ec/9_1_2.png 1840w","/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/15171/9_1_2.png 2230w"],"sizes":"(max-width: 920px) 100vw, 920px","type":"image/png"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"img","properties":{"className":["gatsby-resp-image-image"],"src":"/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/c0255/9_1_2.png","alt":"9 1 2","title":"9 1 2","loading":"lazy","decoding":"async","style":"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"},"children":[]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"element","tagName":"h2","properties":{"id":"self-eller-inget-self","style":"position:relative;"},"children":[{"type":"text","value":"Self eller inget self?"},{"type":"element","tagName":"a","properties":{"href":"#self-eller-inget-self","ariaLabel":"self eller inget self permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Hittills har vi bara snuddat vid ytan när det gäller att använda parameternamnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":". Låt oss titta närmare på när det bör eller inte bör användas."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Nedan har vi en enkel klass som låter oss skapa ett ordförråd-objekt som innehåller några ord:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Ordforrad"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"tillsatt_ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"not"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"utskrift"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"sorted"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nordforrad "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Ordforrad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nordforrad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_ord"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nordforrad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_ord"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"objekt\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nordforrad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_ord"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"objekt-orienterad programmering\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nordforrad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_ord"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"objekt\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nordforrad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_ord"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"nörd\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nordforrad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"utskrift"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"nörd\nobjekt\nobjekt-orienterad programmering\npython"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Listan med ord lagras i ett attribut med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self.ord"}]},{"type":"text","value":". I det här fallet är parameternamnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":" obligatoriskt både i klassens konstruktormetod och i alla andra metoder som använder variabeln. Om "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":" utelämnas kommer de olika metoderna inte att få tillgång till samma lista med ord."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss lägga till en ny metod i vår klassdefinition. Metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"langsta_ord(self)"}]},{"type":"text","value":" returnerar (ett av) de längsta orden i ordförrådet."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Följande är ett sätt att utföra denna uppgift, men vi kommer snart att se att det inte är ett särskilt bra sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Ordforrad"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# ..."}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"langsta_ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# vi definierar två hjälpvariabler"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"langsta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"\""}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"langsta_langd "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"langsta_langd"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"langsta_langd "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"langsta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"langsta"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Den här metoden använder två hjälpvariabler som deklareras med parameternamnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":". Kom ihåg att namnen på variablerna inte spelar någon roll i funktionell mening, så dessa variabler kan också namnges mer förvirrande som till exempel "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"hjalpare"}]},{"type":"text","value":" och "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"hjalpare2"}]},{"type":"text","value":". Koden börjar se lite kryptisk ut:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Ordforrad"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# ..."}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"langsta_ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# vi definierar två hjälpvariabler"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"\""}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"När en variabel deklareras med parameternamnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":" blir den ett attribut till objektet. Detta innebär att variabeln kommer att existera så länge objektet existerar. Specifikt kommer variabeln att fortsätta existera även efter att metoden som deklarerar den har avslutat sin exekvering (engelska “Execution”). I exemplet ovan är detta helt onödigt, eftersom hjälpvariablerna endast är avsedda att användas inom metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"longest_word(self)"}]},{"type":"text","value":". Så att deklarera hjälpvariabler med parameternamnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":" är inte en särskilt bra idé här."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Förutom att variabler kan existera efter sitt \"utgångsdatum\" kan användning av "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":" för att skapa nya attribut där de inte är nödvändiga orsaka svåra buggar i din kod. Särskilt generiskt namngivna attribut som "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self.hjalpare"}]},{"type":"text","value":", som sedan används i flera olika metoder, kan orsaka oväntade beteenden som är svåra att spåra."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Om t.ex. en hjälpvariabel deklareras som ett attribut och tilldelas ett ursprungligt värde i konstruktorn, men variabeln sedan används i ett orelaterat sammanhang i en annan metod, blir resultatet ofta oförutsägbart:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Ordforrad"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# vi definierar hjälparvariabler"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"\""}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"\""}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare3 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"\""}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare4 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"\""}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# ..."}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"langsta_ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# detta fungerar inte eftersom hjalpare2 har fel typ"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Man skulle kunna tro att detta skulle lösas genom att bara deklarera attributen där de används, utanför konstruktorn, men detta resulterar i en situation där de attribut som är tillgängliga via ett objekt är beroende av vilka metoder som har utförts. I föregående del såg vi att fördelen med att deklarera attribut i konstruktorn är att alla instanser av klassen då kommer att ha exakt samma attribut. Om så inte är fallet kan det lätt leda till fel om man använder olika instanser av klassen."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Sammanfattningsvis, om du behöver hjälpvariabler för användning inom en enda metod, är det korrekta sättet att göra det utan "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":". För att göra din kod lättare att förstå, använd också informativa variabelnamn:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Ordforrad"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# ..."}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"langsta_ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# detta är det korrekta sättet att definiera"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# hjälpvariabler för användning i en enda metod"}]},{"type":"text","value":"\n langsta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"\""}]},{"type":"text","value":"\n langsta_langd "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">"}]},{"type":"text","value":" langsta_langd"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n langsta_langd "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n langsta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" langsta"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I implementeringen ovan är hjälpvariablerna endast tillgängliga när metoden utförs. De värden som lagras i dem kan inte orsaka komplikationer i andra delar av programmet."}]},{"type":"element","tagName":"h2","properties":{"id":"objekt-som-argument-till-funktioner","style":"position:relative;"},"children":[{"type":"text","value":"Objekt som argument till funktioner"},{"type":"element","tagName":"a","properties":{"href":"#objekt-som-argument-till-funktioner","ariaLabel":"objekt som argument till funktioner permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"De objekt som skapas baserat på våra egna klasser är vanligtvis mutabla. Du kanske kommer ihåg att till exempel Python-listor är föränderliga: när de passeras som argument till funktioner kan deras innehåll ändras som ett resultat av exekveringen."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss titta på ett enkelt exempel där en funktion får en referens till ett objekt av typen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Studerande"}]},{"type":"text","value":" som sitt argument. Funktionen ändrar sedan namnet på studenten. Både funktionen och huvudfunktionen som anropar den har åtkomst till samma objekt, så ändringen syns även i huvudfunktionen."}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Studerande"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" studerandenummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"studerandenummer "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" studerandenummer\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__str__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" ("}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"studerandenummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":")\""}]}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# observera att typledtråden använder namnet på klassen definierad ovan"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"andra_namn"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"studerande"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" Studerande"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n studerande"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Olle Studerande\""}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# skapa ett Studerande-objekt"}]},{"type":"text","value":"\nolle "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Studerande"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Olle Elev\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"12345\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"olle"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nandra_namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"olle"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"olle"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Olle Elev (12345)\nOlle Studerande (12345)"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Det är också möjligt att skapa objekt inom funktioner. Om en funktion returnerar en referens till det nyskapade objektet är det också åtkomligt inom huvudfunktionen:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"from"}]},{"type":"text","value":" random "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"import"}]},{"type":"text","value":" randint"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" choice\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Studerande"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" studerandenummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"studerandenummer "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" studerandenummer\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__str__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" ("}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"studerandenummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":")\""}]}]},{"type":"text","value":"\n\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Denna funktion skapar och returnerar ett nytt Studerande-objekt."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Den väljer slumpmässigt värden för namnet och studerandenumret."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"ny_studerande"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n fornamn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Atte\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Minna\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Maria\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n efternamn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Virtanen\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Lahtinen\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Leinonen\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Pythonson\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Slumpmässigt namn"}]},{"type":"text","value":"\n namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" choice"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"fornamn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\" \""}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+"}]},{"type":"text","value":" choice"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"efternamn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Slumpmässigt studerandenummer"}]},{"type":"text","value":"\n studerandenummer "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"randint"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10000"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"99999"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Skapa och returnera ett Studerande-objekt"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" Studerande"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" studerandenummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Kalla funktionen fem gånger och spara resultatet i en lista"}]},{"type":"text","value":"\n studeranden "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" i "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"range"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n studeranden"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ny_studerande"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Skriv ut resultatet"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" studerande "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" studeranden"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"studerande"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Om du kör ovanstående kan det resultera i följande utskrift (OBS: eftersom slumpen är inblandad kommer resultaten sannolikt att bli annorlunda om du testar koden själv)."}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Maria Lahtinen (36213)\nAtte Virtanen (11859)\nMaria Pythonen (77330)\nAtte Pythonson (86451)\nMinna Pythonson (86211)"}]}]},{"type":"element","tagName":"h2","properties":{"id":"objekt-som-argument-till-metoder","style":"position:relative;"},"children":[{"type":"text","value":"Objekt som argument till metoder"},{"type":"element","tagName":"a","properties":{"href":"#objekt-som-argument-till-metoder","ariaLabel":"objekt som argument till metoder permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"På liknande sätt kan objekt fungera som argument till metoder. Låt oss ta en titt på ett exempel från en nöjespark:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Person"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" langd"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"langd "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" langd\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Akattraktion"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" langdgrans"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"besokare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"langdgrans "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" langdgrans\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"ta_ombord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"langd "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">="}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"langdgrans"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"besokare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" kom ombord\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" var för kort :(\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__str__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" ("}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"besokare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" besökare)\""}]}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Attraktionen innehåller en metod "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"motta_besökare"}]},{"type":"text","value":", som tar ett objekt av typen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Person"}]},{"type":"text","value":" som argument. Om besökaren är tillräckligt lång släpps denne ombord och antalet besökare ökas. Klasserna kan testas på följande sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"berg_och_dalbana "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Akattraktion"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Berg_och_dalbana\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"120"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\njakob "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Jakob\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"172"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nvilma "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Vilma\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"105"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nberg_och_dalbana"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"ta_ombord"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"jakob"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nberg_och_dalbana"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"ta_ombord"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"vilma"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"berg_och_dalbana"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Jakob kom ombord\nVenla var för kort :(\nBerg_och_dalbana (1 besökare)"}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Bebiscenter","tmcname":"osa09-03_bebiscenter"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I uppgiftsbotten finns färdigt redan en klass "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Person"}]},{"type":"text","value":" såväl som en ram för klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"BebisCenter"}]},{"type":"text","value":". Ett "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"BebisCenter"}]},{"type":"text","value":"-objekt utför olika handlingar såsom mäter eller matar personer. I denna uppgift implementerar du resten av "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"BebisCenter"}]},{"type":"text","value":"-klassen. Koden för klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Person"}]},{"type":"text","value":" ska inte ändras överhuvudtaget!"}]},{"type":"element","tagName":"h2","properties":{"id":"vagning-av-person","style":"position:relative;"},"children":[{"type":"text","value":"Vägning av person"},{"type":"element","tagName":"a","properties":{"href":"#vagning-av-person","ariaLabel":"vagning av person permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"BebisCenter"}]},{"type":"text","value":"-klassens definitione finns en ram för funktionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"vagning"}]}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"BebisCenter"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"vagning"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# returnera vikten av personen som passerades som argument"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Metoden tar ett "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Person"}]},{"type":"text","value":"-objekt som sitt argument. Den ska returnera personens vikt. Du kan komma åt en persons vikt genom attributet som definieras i "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Person"}]},{"type":"text","value":"-klassen. Vänligen fyll i resten av implementationen för metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"vagning"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Nedan finns ett exempel på en huvudfunktion där ett "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"BebisCenter"}]},{"type":"text","value":" väger två olika "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Person"}]},{"type":"text","value":"-objekt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"haga_barnvard "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" BebisCenter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nerik "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Erik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"110"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\npeter "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"33"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"176"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"85"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" väger "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"haga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" kg\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"peter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" väger "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"haga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"peter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" kg\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Erik väger 7 kg\nPeter väger 85 kg"}]}]},{"type":"element","tagName":"h2","properties":{"id":"matning","style":"position:relative;"},"children":[{"type":"text","value":"Matning"},{"type":"element","tagName":"a","properties":{"href":"#matning","ariaLabel":"matning permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Det är möjligt att ändra tillståndet för ett objekt som skickas som ett argument. Implementera metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"mata(person: Person)"}]},{"type":"text","value":" som ökar vikten på den person som skickas som argument med ett."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I följande exempel vägs två personer, och sedan matas en av dem tre gånger. Därefter vägs personerna igen:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"haga_barnvard "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" BabyCenter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nerik "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Erik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"110"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\npeter "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"33"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"176"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"85"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" väger "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"haga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" kg\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"peter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" väger "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"haga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"peter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" kg\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nhaga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"mata"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhaga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"mata"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhaga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"mata"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" väger "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"haga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" kg\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"peter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" väger "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"haga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"peter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" kg\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Utskriften borde visa att Eriks vikt har stigit med tre:"}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Erik väger 7 kg\nPeter väger 85 kg"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Erik väger 10 kg\nPeter väger 85 kg"}]}]},{"type":"element","tagName":"h2","properties":{"id":"raknande-av-vagningar","style":"position:relative;"},"children":[{"type":"text","value":"Räknande av vägningar"},{"type":"element","tagName":"a","properties":{"href":"#raknande-av-vagningar","ariaLabel":"raknande av vagningar permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Implementera metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"vagningar"}]},{"type":"text","value":"() som returnerar det totala antalet vägningar som ett "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"BabyCenter"}]},{"type":"text","value":"-objekt har utfört. OBS: Du kommer att behöva ett nytt attribut för att hålla reda på antalet vägningar. Du kan använda följande kod för att testa din metod:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"haga_barnvard "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" BabyCenter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nerik "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Erik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"110"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\npeter "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"33"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"176"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"85"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\"Vägningar utförda "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"haga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nhaga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhaga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\"Vägningar utförda "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"haga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nhaga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhaga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhaga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhaga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\"Vägningar utförda "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"haga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Vägningar utförda 0\nVägningar utförda 2\nVägningar utförda 6"}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Lunchkort och betalterminal","tmcname":"osa09-04_lunchkort_och_betalterminal"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I föregående del fanns en "},{"type":"element","tagName":"a","properties":{"href":"/ohjelmointi-24-sv/osa-8/5-lisaa-esimerkkeja#programming-exercise-maksukortti"},"children":[{"type":"text","value":"övning"}]},{"type":"text","value":" där du implementerade klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Lunchkort"}]},{"type":"text","value":". Kortet hade separata metoder för att äta en vanlig och en speciell lunch, samt en metod för att sätta in pengar på kortet."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Lunchkort"}]},{"type":"text","value":", så som du ombads implementera den, har dock vissa problem. Kortet självt hade kunskap om priserna på de olika lunchalternativen och visste att subtrahera rätt mängd pengar från saldot baserat på dessa. Men tänk dig att priserna ändrades eller att nya varor infördes i systemet, men att flera kort redan var registrerade i systemet. Detta skulle innebära att alla befintliga kort skulle behöva ersättas med versioner med kunskap om de nya priserna."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"En bättre lösning skulle vara att göra korten ”dumma”, okunniga om priserna på olika produkter. Syftet med kortet skulle vara att helt enkelt hålla reda på det tillgängliga saldot. Alla mer komplicerade funktioner bör rymmas inom en annan klass: betalterminalen."}]},{"type":"element","tagName":"h2","properties":{"id":"ett-simplare-lunchkort","style":"position:relative;"},"children":[{"type":"text","value":"Ett simplare Lunchkort"},{"type":"element","tagName":"a","properties":{"href":"#ett-simplare-lunchkort","ariaLabel":"ett simplare lunchkort permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Vi förverkligar först en dummare version av "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Lunchkort"}]},{"type":"text","value":"-klassen. Kortet borde endast ha funktioner för att få reda på det tillfälliga saldot, lägga till pengar på kortet och subtrahera pengar från saldot. Fyll i metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"subtrahera_saldo(mangd)"}]},{"type":"text","value":" enligt kommentarerna i övningsfältet:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Lunchkort"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" saldo\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"tillsatt_pengar"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" mangd"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+="}]},{"type":"text","value":" mangd\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"subtrahera_saldo"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" mangd"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"pass"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Metoden ska endast kunna subtrahera från saldot"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# ifall det finns tillräckligt med pengar på kortet"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Lyckad betalning returnerar True, icke-lyckad False."}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Huvudtestprogram:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n kort "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Lunchkort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Saldo\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n resultat "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"subtrahera_saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"8"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Betalningen lyckades:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" resultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Saldo\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n resultat "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"subtrahera_saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Betalningen lyckads:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" resultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Saldo\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Saldo 10\nBetalningen lyckades: True\nSaldo 2\nBetalningen lyckades: False\nSaldo 2"}]}]},{"type":"element","tagName":"h2","properties":{"id":"betalningsterminalen-och-hanterandet-av-kontantbetalning","style":"position:relative;"},"children":[{"type":"text","value":"Betalningsterminalen och hanterandet av kontantbetalning"},{"type":"element","tagName":"a","properties":{"href":"#betalningsterminalen-och-hanterandet-av-kontantbetalning","ariaLabel":"betalningsterminalen och hanterandet av kontantbetalning permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I studentkafeterian går det att betala med kontanter eller Lunchkort. En betalterminal används för att hantera både kontant- och korttransaktioner. Låt oss börja med kontanttransaktionerna."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Här har vi en ram för en "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Betalterminal"}]},{"type":"text","value":"-klass. Implementera metoderna enligt beskrivningen i kommentarerna:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Betalterminal"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# I kassan finns det ursprungligen 1000 euro i kontanter"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"pengar "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1000"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"formanliga "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"special "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"at_formanligt"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" betalning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# En formånlig lunch kostar 2.50 euro"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Öka värdet på pengarna som finns i terminalen med en förmånlig lunchs pris,"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# öka mängden förmånliga luncher och returnera rätt mängd växel."}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Ifall betalningen inte är tillräckligt stor säljs ingen lunch och hela summan returneras"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"at_special"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" betalning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# En special lunch kostar 4.30 euro"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Öka värdet på pengarna som finns i terminalen med en special lunchs pris,"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# öka mängden special luncher och returnera rätt mängd växel."}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Ifall betalningen inte är tillräckligt stor säljs ingen lunch och hela summan returneras"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Exempel på användning:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"exactum "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Betalterminal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nvaxel "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"at_formanligt"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Mängden växel\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" vaxel"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nvaxel "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"at_formanligt"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Mängden växel\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" vaxel"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nvaxel "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"at_special"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4.3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Mängden växel\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" vaxel"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Pengar i kassan\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"pengar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Förmånliga luncher sålda\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"formanliga"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Special luncher sålda\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"special"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Mängden växel 7.5\nMängden växel 2.5\nMängden växel 0.0\nPengar i kassan 1009.3\nFörmånliga luncher sålda 2\nSpecial luncher sålda 1"}]}]},{"type":"element","tagName":"h2","properties":{"id":"betalning-med-kort","style":"position:relative;"},"children":[{"type":"text","value":"Betalning med kort"},{"type":"element","tagName":"a","properties":{"href":"#betalning-med-kort","ariaLabel":"betalning med kort permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss nu implementera korttransaktioner. Vi kommer att behöva metoder som tar ett "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Lunchkort"}]},{"type":"text","value":" som argument och minskar saldot på kortet med lunchens pris. Nedan hittar du ramar av dessa funktioner. Vänligen fyll i metoderna enligt beskrivningen i kommentarerna:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Betalterminal"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# ..."}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"at_formanligt_kort"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" Lunchkort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# En förmånlig lunch kostar 2.50 euro."}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Om kortet har tillräckligt med pengar, subtrahera lunchens pris och returnera True."}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Annars returnera False"}]},{"type":"text","value":"\n\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"at_special_kort"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" Lunchkort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# En special lunch kostar 4.30 euro."}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Om kortet har tillräckligt med pengar, subtrahera lunchens pris och returnera True."}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Annars returnera False"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"OBS:"}]},{"type":"text","value":" betalningar med Lunchkort ändrar inte på mängden pengar i terminalen. Luncher säljes däremot fortfarande så länge pengarna på saldot räcker till, alltså kom ihåg att öka mängden luncher som sålts."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Följande kod kan du använda för att testa din klass:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"exactum "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Betalterminal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nvaxel "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"at_formanligt"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Mängden växel\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" vaxel"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nkort "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Lunchkort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nresultat "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"at_special_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Betalningen lyckades:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" resultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nresultat "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"at_special_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Betalningen lyckades:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" resultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nresultat "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"at_formanligt_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Betalningen lyckades:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" resultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Pengar i kassan\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"pengar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Förmånliga luncher sålda\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"formanliga"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"special luncher sålda\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"special"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Mängden växel 7.5\nBetalningen lyckades: True\nBetalningen lyckades: False\nBetalningen lyckades: True\nPengar i kassan 1002.5\nFörmånliga luncher sålda 2\nspecial luncher sålda 1"}]}]},{"type":"element","tagName":"h2","properties":{"id":"tillsattning-av-pengar-pa-kortet","style":"position:relative;"},"children":[{"type":"text","value":"Tillsättning av pengar på kortet"},{"type":"element","tagName":"a","properties":{"href":"#tillsattning-av-pengar-pa-kortet","ariaLabel":"tillsattning av pengar pa kortet permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Slutligen lägger vi till en metod som gör att du kan sätta in pengar på kortet. Kortägaren betalar detta kontant, så att den insatta summan läggs till de pengar som finns tillgängliga i terminalen. Här är en ram för metoden:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"tillsatt_pengar_kortet"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" Lunchkort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" summa"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"pass"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Du kan använda följande kod för att testa din metod:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"exactum "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Betalterminal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nantons_kort "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Lunchkort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\"Kortets saldo "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"antons_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" euro\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nresultat "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"at_special_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"antons_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Betalningen lyckades:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" resultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nexactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_pengar_kortet"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"antons_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"100"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\"Kortets saldo "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"antons_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" euro\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nresultat "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"at_special_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"antons_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Betalningen lyckades:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" resultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\"Kortets saldo "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"antons_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" euro\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Pengar i kassan\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"pengar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Förmånliga luncher sålda\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"formanliga"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"special luncher sålda\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"special"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Kortets saldo 2 euro\nBetalningen lyckades: False\nKortets saldo 102 euro\nBetalningen lyckades: True\nKortets saldo 97.7 euro\nPengar i kassan 1100\nFörmånliga luncher sålda 0\nspecial luncher sålda 1"}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"en-instans-av-samma-klass-som-argument-till-en-metod","style":"position:relative;"},"children":[{"type":"text","value":"En instans av samma klass som argument till en metod"},{"type":"element","tagName":"a","properties":{"href":"#en-instans-av-samma-klass-som-argument-till-en-metod","ariaLabel":"en instans av samma klass som argument till en metod permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Nedan har vi ytterligare en version av klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Person"}]},{"type":"text","value":":"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Person"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" fodelsear"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" fodelsear"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss anta att vi vill skriva ett program som jämför åldern på objekt av typen Person. Vi kan skriva en separat funktion för detta ändamål:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"aldre_an"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"person1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" person2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" person1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"<"}]},{"type":"text","value":" person2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"True"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"False"}]},{"type":"text","value":"\n\nmuhammad "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Muhammad ibn Musa al-Khwarizmi\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"780"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\npascal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Blaise Pascal\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1623"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\ngrace "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Grace Hopper\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1906"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" aldre_an"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"muhammad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"muhammad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" är äldre än "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"muhammad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" är inte äldre än "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" aldre_an"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"grace"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"grace"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" är äldre än "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"grace"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" är inte äldre än "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Muhammad ibn Musa al-Khwarizmi är äldre än Blaise Pascal\nGrace Hopper är inte äldre än Blaise Pascal"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"En av principerna för objektorienterad programmering är att all funktionalitet som hanterar objekt av en viss typ ska inkluderas i klassdefinitionen, som metoder. I stället för en funktion kan vi alltså skriva en metod som gör det möjligt att jämföra åldern på ett Person-objekt med ett annat Person-objekt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Person"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" fodelsear"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" fodelsear\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# OBS! Typledtrådar måste vara inom citationstecken ifall parametern är av samma typ som klassen självt!"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"aldre_an"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" annat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Person\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"<"}]},{"type":"text","value":" annat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"True"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"False"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Här kallas det objekt som metoden anropas på för "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":", medan det andra Person-objektet kallas för "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"annat"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Kom ihåg att anrop av en metod skiljer sig från anrop av en funktion. En metod är kopplad till ett objekt med punktnotationen:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"muhammad "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Muhammad ibn Musa al-Khwarizmi\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"780"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\npascal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Blaise Pascal\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1623"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\ngrace "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Grace Hopper\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1906"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" muhammad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"aldre_an"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"muhammad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" är äldre än "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"muhammad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" är inte äldre än "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" grace"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"aldre_an"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"grace"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" är äldre än "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"grace"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" är inte äldre än "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Till vänster om punkten finns själva objektet, som kallas "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":" i metoddefinitionen. Inom parentes står argumentet till metoden, vilket är det objekt som kallas "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"annat"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Utskriften från programmet är exakt densamma som med funktionsimplementeringen ovan."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Till sist, en ganska kosmetisk punkt: "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"if...else"}]},{"type":"text","value":"-strukturen i metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"aldre_an"}]},{"type":"text","value":" är i stort sett onödig. Värdet på det booleska uttrycket i villkoret är redan exakt samma sanningsvärde som returneras. Metoden kan alltså förenklas:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Person"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" fodelsear"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" fodelsear\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# OBS! Typledtrådar måste vara inom citationstecken ifall parametern är av samma typ som klassen självt!"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"aldre_an"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" annat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Person\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"<"}]},{"type":"text","value":" annat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Liksom det framkommer av kommentarerna i exemplen ovan, så måste typledtråden omslutas av citattecken ifall parametern i en metoddefinition är av samma typ som klassen själv. Om citattecknen utelämnas uppstår ett fel, vilket du kommer att se om du försöker med följande:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Person"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# ..."}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Detta fungerar inte, Person måste vara innanför citationstecken"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"aldre_an"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" annat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"<"}]},{"type":"text","value":" annat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Bostadsjämförelse","tmcname":"osa09-05_bostadsjamforelse"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Databasen hos en fastighetsmäklare innehåller register över tillgängliga fastigheter med objekt som definieras av följande klass:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Bostad"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" rum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kvadratmeter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kvadratpris"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"rum "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" rum\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"kvadratmeter "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" kvadratmeter\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"kvadratpris "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" kvadratpris"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Din uppgift är att implementera metoder som gör det möjligt att jämföra tillgängliga egenskaper."}]},{"type":"element","tagName":"h2","properties":{"id":"ar-den-storre","style":"position:relative;"},"children":[{"type":"text","value":"Är den större?"},{"type":"element","tagName":"a","properties":{"href":"#ar-den-storre","ariaLabel":"ar den storre permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"storre(self, jamforelse)"}]},{"type":"text","value":", som returnerar "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"True"}]},{"type":"text","value":", ifall "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bostad"}]},{"type":"text","value":"-objektet är större än objektet det jämförs med."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Exempel på hur funktionen borde fungera:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"eira_etta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bostad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"16"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5500"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nberghall_tvaa "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bostad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"38"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4200"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\njakobacka_trea "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bostad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"78"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2500"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"eira_etta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"storre"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"berghall_tvaa"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"jakobacka_trea"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"storre"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"berghall_tvaa"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"False\nTrue"}]}]},{"type":"element","tagName":"h2","properties":{"id":"prisskillnad","style":"position:relative;"},"children":[{"type":"text","value":"Prisskillnad"},{"type":"element","tagName":"a","properties":{"href":"#prisskillnad","ariaLabel":"prisskillnad permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"prisskillnad(self, jamforelse)"}]},{"type":"text","value":", som returnerar skillnaden i pris mellan "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bostad"}]},{"type":"text","value":"-objektet självt och det som det jämförs med. Prisskillnaden är det absoluta värdet av skillnaden mellan de två fastigheternas totalpriser. Det totala priset för en fastighet är dess kvadratmeterpris multiplicerat med antalet kvadratmeter i fastigheten."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Exempel på hur funktionen borde fungera:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"eira_etta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bostad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"16"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5500"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nberghall_tvaa "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bostad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"38"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4200"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\njakobacka_trea "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bostad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"78"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2500"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"eira_etta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"prisskillnad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"berghall_tvaa"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"jakobacka_trea"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"prisskillnad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"berghall_tvaa"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"71600\n35400"}]}]},{"type":"element","tagName":"h2","properties":{"id":"dyrare","style":"position:relative;"},"children":[{"type":"text","value":"Dyrare?"},{"type":"element","tagName":"a","properties":{"href":"#dyrare","ariaLabel":"dyrare permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"dyrare(self, jamforelse)"}]},{"type":"text","value":" som returnerar "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"True"}]},{"type":"text","value":", ifall "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bostad"}]},{"type":"text","value":"-objektet är dyrare än objektet som det jämförs med."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Exempel på hur funktionen borde fungera:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"eira_etta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bostad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"16"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5500"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nberghall_tvaa "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bostad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"38"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4200"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\njakobacka_trea "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bostad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"78"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2500"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"eira_etta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"dyrare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"berghall_tvaa"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"jakobacka_trea"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"dyrare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"berghall_tvaa"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"False\nTrue"}]}]}]}]},"html":"

    Efter den här delen

      \n
    • Kommer du att kunna använda olika datastrukturer för att hantera objekt
    • \n
    • Vet du hur objekt kan bli passerade som argument
    • \n

    Varje värde i Python är ett objekt. Alla objekt som du skapar baserat på en klass som du själv har definierat fungerar exakt på samma sätt som alla \"vanliga\" Python-objekt. Objekt kan till exempel lagras i en lista:

    from datetime import date\n\nclass SlutfordKurs:\n\n    def __init__(self, kurs: str, studiepoang: int, slutforsdatum: date):\n        self.kurs = kurs\n        self.studiepoang = studiepoang\n        self.slutforsdatum = slutforsdatum\n\n\nif __name__ == \"__main__\":\n    # Vi skapar några slutförda kurser och lägger dessa i en lista\n    prestationer = []\n\n    mat1 = SlutfordKurs(\"Matematik 1\", 5, date(2020, 3, 11))\n    prg1 = SlutfordKurs(\"Programmering 1\", 6, date(2019, 12, 17))\n\n    prestationer.append(mat1)\n    prestationer.append(prg1)\n\n    # Vi lägger några till rakt till listan\n    prestationer.append(SlutfordKurs(\"Fysik 2\", 4, date(2019, 11, 10)))\n    prestationer.append(SlutfordKurs(\"Programmering 2\", 5, date(2020, 5, 19)))\n\n    # Vi går igenom alla slutförda kurser, skriver ut deras namn och räknar ihop den totala mängden studiepoäng\n    studiepoang = 0\n    for prestation in prestationer:\n        print(prestation.kurs)\n        studiepoang += prestation.studiepoang\n\n    print(\"Studiepoäng totalt:\", studiepoang)

    Matematik 1\nProgrammering 1\nFysik 2\nProgrammering 2\nStudiepoäng totalt: 20

    Uppgiftsbotten har en klass med namnet Bil som representerar en bil genom två attribut: marke (str) och topphastighet (int).

    Skapa funktionen snabbaste_bil(bilar: list), som får en lista av Bil-objekt som argument.

    Funktionen ska returnera märket på den snabbaste bilen. Du kan anta att det alltid kommer att finnas en enda bil med den högsta topphastigheten. Ändra inte listan som ges som argument, gör heller inte några ändringar i klassdefinitionen för Bil.

    Du kan använda följande kod för att testa din funktion:

    if __name__ == \"__main__\":\n    bil1 = Bil(\"Mersu\", 195)\n    bil2 = Bil(\"Lada\", 110)\n    bil3 = Bil(\"Ferrari\", 280)\n    bil4 = Bil(\"Trabant\", 85)\n\n    bilar = [bil1, bil2, bil3, bil4]\n    print(snabbaste_bil(bilar))

    Ferrari

    I uppgiftsbotten hittas klassen Provprestation, som, liksom namnet anger, tar modell av en provtagares prestation i ett prov. Den har två attribut, presterare (str) och poang (int).

    Skapa funktionen godkanda(prestationer: list, poanggrans: int), som får som parametrar en lista av provprestationer och ett heltal som representerar det minsta poängantalet för att bli godkänd.

    Funktionen ska skapa och returnera en ny lista, som innehåller endast de prov som kom över poänggränsen i den ursprungliga listan. Ändra inte listan som ges som argument, ändra heller inte definitionen för klassen Provprestation.

    Du kan använda följande kod för att testa funktionen:

    if __name__ == \"__main__\":\n    s1 = Provprestation(\"Peter\", 12)\n    s2 = Provprestation(\"Pernilla\", 19)\n    s3 = Provprestation(\"Per\", 15)\n    s4 = Provprestation(\"Pia\", 9)\n    s5 = Provprestation(\"Petra\", 17)\n\n    klarade = godkanda([s1, s2, s3, s4, s5], 15)\n    for godkand in klarade:\n        print(klarade)

    Provprestation (presterare: Pernilla, poang: 19)\nProvprestation (presterare: Per, poang: 15)\nProvprestation (presterare: Petra, poang: 17)

    Du kanske minns att listor inte innehåller några objekt i sig själva. De innehåller referenser till objekt. Exakt samma objekt kan förekomma flera gånger i en och samma lista, och det kan refereras till flera gånger i listan eller utanför den. Låt oss ta en titt på ett exempel:

    class Produkt:\n    def __init__(self, namn: int, enhet: str):\n        self.namn = namn\n        self.enhet = enhet\n\n\nif __name__ == \"__main__\":\n    affarslista = []\n    mjolk = Produkt(\"Mjölk\", \"liter\")\n\n    affarslista.append(mjolk)\n    affarslista.append(mjolk)\n    affarslista.append(Produkt(\"Gurka\", \"st\"))
    \n \n \n \n \n \n \"9\n \n \n

    Om det finns mer än en referens till samma objekt spelar det ingen roll vilken av referenserna som används:

    class Hund:\n    def __init__(self, namn):\n        self.namn = namn\n\n    def __str__(self):\n        return self.namn\n\nhundar = []\nmolly = Hund(\"Molly\")\nhundar.append(molly)\nhundar.append(molly)\nhundar.append(Hund(\"Molly\"))\n\nprint(\"Hundar i början:\")\nfor hund in hundar:\n    print(hund)\n\nprint(\"Hunden på index 0 får ett nytt namn:\")\nhundar[0].namn = \"Rex\"\nfor hund in hundar:\n    print(hund)\n\nprint(\"Hunden på index 2 får ett nytt namn:\")\nhundar[2].namn = \"Fifi\"\nfor hund in hundar:\n    print(hund)

    Koirat alussa:\nMolly\nMolly\nMolly\nHunden på index 0 får ett nytt namn::\nRex\nRex\nMolly\nHunden på index 2 får ett nytt namn:\nRex\nRex\nFifi

    Referenserna på index 0 och 1 i listan hänvisar till samma objekt. Var och en av referenserna kan användas för att komma åt objektet. Referensen på index 2 hänvisar till ett annat objekt, men med till synes samma innehåll. Om innehållet i det senare objektet ändras påverkas inte det andra.

    Operatorn is används för att kontrollera om de två referenserna hänvisar till exakt samma objekt, medan operatorn == talar om för dig om innehållet i objekten är detsamma. Följande exempel gör förhoppningsvis skillnaden tydlig:

    lista1 = [1, 2, 3]\nlista2 = [1, 2, 3]\nlista3 = lista1\n\nprint(lista1 is lista2)\nprint(lista1 is lista3)\nprint(lista2 is lista3)\n\nprint()\n\nprint(lista1 == lista2)\nprint(lista1 == lista3)\nprint(lista2 == lista3)

    False\nTrue\nFalse

    True\nTrue\nTrue

    Alla Python-objekt kan också lagras i en ordlista eller någon annan datastruktur. Detta gäller även objekt som är av en klass som du själv har definierat.

    class Studerande:\n    def __init__(self, namn: str, sp: int):\n        self.namn = namn\n        self.sp = sp\n\nif __name__ == \"__main__\":\n    # Vi använder studerandenummer som nyckel och värdet som fås är ett objekt av typen Studerande\n    studeranden = {}\n    studeranden[\"12345\"] = Studerande(\"Olle Studerande\", 10)\n    studeranden[\"54321\"] = Studerande(\"Ove Studerande\", 67)

    Visualiseringsverktyget kan hjälpa dig att förstå exemplet ovan:

    \n \n \n \n \n \n \"9\n \n \n

    Self eller inget self?

    Hittills har vi bara snuddat vid ytan när det gäller att använda parameternamnet self. Låt oss titta närmare på när det bör eller inte bör användas.

    Nedan har vi en enkel klass som låter oss skapa ett ordförråd-objekt som innehåller några ord:

    class Ordforrad:\n    def __init__(self):\n        self.ord = []\n\n    def tillsatt_ord(self, ord: str):\n        if not ord in self.ord:\n            self.ord.append(ord)\n\n    def utskrift(self):\n        for ord in sorted(self.ord):\n            print(ord)\n\nordforrad = Ordforrad()\nordforrad.tillsatt_ord(\"python\")\nordforrad.tillsatt_ord(\"objekt\")\nordforrad.tillsatt_ord(\"objekt-orienterad programmering\")\nordforrad.tillsatt_ord(\"objekt\")\nordforrad.tillsatt_ord(\"nörd\")\n\nordforrad.utskrift()

    nörd\nobjekt\nobjekt-orienterad programmering\npython

    Listan med ord lagras i ett attribut med namnet self.ord. I det här fallet är parameternamnet self obligatoriskt både i klassens konstruktormetod och i alla andra metoder som använder variabeln. Om self utelämnas kommer de olika metoderna inte att få tillgång till samma lista med ord.

    Låt oss lägga till en ny metod i vår klassdefinition. Metoden langsta_ord(self) returnerar (ett av) de längsta orden i ordförrådet.

    Följande är ett sätt att utföra denna uppgift, men vi kommer snart att se att det inte är ett särskilt bra sätt:

    class Ordforrad:\n    def __init__(self):\n        self.ord = []\n\n    # ...\n\n    def langsta_ord(self):\n        # vi definierar två hjälpvariabler\n        self.langsta = \"\"\n        self.langsta_langd = 0\n\n        for ord in self.ord:\n            if len(ord) > self.langsta_langd:\n                self.langsta_langd = len(ord)\n                self.langsta = ord\n\n        return self.langsta

    Den här metoden använder två hjälpvariabler som deklareras med parameternamnet self. Kom ihåg att namnen på variablerna inte spelar någon roll i funktionell mening, så dessa variabler kan också namnges mer förvirrande som till exempel hjalpare och hjalpare2. Koden börjar se lite kryptisk ut:

    class Ordforrad:\n    def __init__(self):\n        self.ord = []\n\n    # ...\n\n    def langsta_ord(self):\n        # vi definierar två hjälpvariabler\n        self.hjalpare = \"\"\n        self.hjalpare2 = 0\n\n        for ord in self.ord:\n            if len(ord) > self.hjalpare2:\n                self.hjalpare2 = len(ord)\n                self.hjalpare = ord\n\n        return self.hjalpare

    När en variabel deklareras med parameternamnet self blir den ett attribut till objektet. Detta innebär att variabeln kommer att existera så länge objektet existerar. Specifikt kommer variabeln att fortsätta existera även efter att metoden som deklarerar den har avslutat sin exekvering (engelska “Execution”). I exemplet ovan är detta helt onödigt, eftersom hjälpvariablerna endast är avsedda att användas inom metoden longest_word(self). Så att deklarera hjälpvariabler med parameternamnet self är inte en särskilt bra idé här.

    Förutom att variabler kan existera efter sitt \"utgångsdatum\" kan användning av self för att skapa nya attribut där de inte är nödvändiga orsaka svåra buggar i din kod. Särskilt generiskt namngivna attribut som self.hjalpare, som sedan används i flera olika metoder, kan orsaka oväntade beteenden som är svåra att spåra.

    Om t.ex. en hjälpvariabel deklareras som ett attribut och tilldelas ett ursprungligt värde i konstruktorn, men variabeln sedan används i ett orelaterat sammanhang i en annan metod, blir resultatet ofta oförutsägbart:

    class Ordforrad:\n    def __init__(self):\n        self.ord = []\n        # vi definierar hjälparvariabler\n        self.hjalpare = \"\"\n        self.hjalpare2 = \"\"\n        self.hjalpare3 = \"\"\n        self.hjalpare4 = \"\"\n\n    # ...\n\n    def langsta_ord(self):\n        for ord in self.ord:\n            # detta fungerar inte eftersom hjalpare2 har fel typ\n            if len(ord) > self.hjalpare2:\n                self.hjalpare2 = len(ord)\n                self.hjalpare = ord\n\n        return self.hjalpare

    Man skulle kunna tro att detta skulle lösas genom att bara deklarera attributen där de används, utanför konstruktorn, men detta resulterar i en situation där de attribut som är tillgängliga via ett objekt är beroende av vilka metoder som har utförts. I föregående del såg vi att fördelen med att deklarera attribut i konstruktorn är att alla instanser av klassen då kommer att ha exakt samma attribut. Om så inte är fallet kan det lätt leda till fel om man använder olika instanser av klassen.

    Sammanfattningsvis, om du behöver hjälpvariabler för användning inom en enda metod, är det korrekta sättet att göra det utan self. För att göra din kod lättare att förstå, använd också informativa variabelnamn:

    class Ordforrad:\n    def __init__(self):\n        self.ord = []\n\n    # ...\n\n    def langsta_ord(self):\n        # detta är det korrekta sättet att definiera\n        # hjälpvariabler för användning i en enda metod\n        langsta = \"\"\n        langsta_langd = 0\n\n        for ord in self.ord:\n            if len(ord) > langsta_langd:\n                langsta_langd = len(ord)\n                langsta = ord\n\n        return langsta

    I implementeringen ovan är hjälpvariablerna endast tillgängliga när metoden utförs. De värden som lagras i dem kan inte orsaka komplikationer i andra delar av programmet.

    Objekt som argument till funktioner

    De objekt som skapas baserat på våra egna klasser är vanligtvis mutabla. Du kanske kommer ihåg att till exempel Python-listor är föränderliga: när de passeras som argument till funktioner kan deras innehåll ändras som ett resultat av exekveringen.

    Låt oss titta på ett enkelt exempel där en funktion får en referens till ett objekt av typen Studerande som sitt argument. Funktionen ändrar sedan namnet på studenten. Både funktionen och huvudfunktionen som anropar den har åtkomst till samma objekt, så ändringen syns även i huvudfunktionen.

    class Studerande:\n    def __init__(self, namn: str, studerandenummer: str):\n        self.namn = namn\n        self.studerandenummer = studerandenummer\n\n    def __str__(self):\n        return f\"{self.namn} ({self.studerandenummer})\"\n\n# observera att typledtråden använder namnet på klassen definierad ovan\ndef andra_namn(studerande: Studerande):\n    studerande.namn = \"Olle Studerande\"\n\n# skapa ett Studerande-objekt\nolle = Studerande(\"Olle Elev\", \"12345\")\n\nprint(olle)\nandra_namn(olle)\nprint(olle)

    Olle Elev (12345)\nOlle Studerande (12345)

    Det är också möjligt att skapa objekt inom funktioner. Om en funktion returnerar en referens till det nyskapade objektet är det också åtkomligt inom huvudfunktionen:

    from random import randint, choice\n\nclass Studerande:\n    def __init__(self, namn: str, studerandenummer: str):\n        self.namn = namn\n        self.studerandenummer = studerandenummer\n\n    def __str__(self):\n        return f\"{self.namn} ({self.studerandenummer})\"\n\n\n# Denna funktion skapar och returnerar ett nytt Studerande-objekt.\n# Den väljer slumpmässigt värden för namnet och studerandenumret.\ndef ny_studerande():\n    fornamn = [\"Atte\",\"Peter\",\"Minna\",\"Maria\"]\n    efternamn = [\"Virtanen\", \"Lahtinen\", \"Leinonen\", \"Pythonson\"]\n\n    # Slumpmässigt namn\n    namn = choice(fornamn) + \" \" + choice(efternamn)\n\n    # Slumpmässigt studerandenummer\n    studerandenummer = str(randint(10000,99999))\n\n    # Skapa och returnera ett Studerande-objekt\n    return Studerande(namn, studerandenummer)\n\nif __name__ == \"__main__\":\n    # Kalla funktionen fem gånger och spara resultatet i en lista\n    studeranden = []\n    for i in range(5):\n        studeranden.append(ny_studerande())\n\n    # Skriv ut resultatet\n    for studerande in studeranden:\n        print(studerande)

    Om du kör ovanstående kan det resultera i följande utskrift (OBS: eftersom slumpen är inblandad kommer resultaten sannolikt att bli annorlunda om du testar koden själv).

    Maria Lahtinen (36213)\nAtte Virtanen (11859)\nMaria Pythonen (77330)\nAtte Pythonson (86451)\nMinna Pythonson (86211)

    Objekt som argument till metoder

    På liknande sätt kan objekt fungera som argument till metoder. Låt oss ta en titt på ett exempel från en nöjespark:

    class Person:\n    def __init__(self, namn: str, langd: int):\n        self.namn = namn\n        self.langd = langd\n\nclass Akattraktion:\n    def __init__(self, namn: str, langdgrans: int):\n        self.besokare = 0\n        self.namn = namn\n        self.langdgrans = langdgrans\n\n    def ta_ombord(self, person: Person):\n        if person.langd >= self.langdgrans:\n            self.besokare += 1\n            print(f\"{person.namn} kom ombord\")\n        else:\n            print(f\"{person.namn} var för kort :(\")\n\n    def __str__(self):\n        return f\"{self.namn} ({self.besokare} besökare)\"

    Attraktionen innehåller en metod motta_besökare, som tar ett objekt av typen Person som argument. Om besökaren är tillräckligt lång släpps denne ombord och antalet besökare ökas. Klasserna kan testas på följande sätt:

    berg_och_dalbana = Akattraktion(\"Berg_och_dalbana\", 120)\njakob = Person(\"Jakob\", 172)\nvilma = Person(\"Vilma\", 105)\n\nberg_och_dalbana.ta_ombord(jakob)\nberg_och_dalbana.ta_ombord(vilma)\n\nprint(berg_och_dalbana)

    Jakob kom ombord\nVenla var för kort :(\nBerg_och_dalbana (1 besökare)

    I uppgiftsbotten finns färdigt redan en klass Person såväl som en ram för klassen BebisCenter. Ett BebisCenter-objekt utför olika handlingar såsom mäter eller matar personer. I denna uppgift implementerar du resten av BebisCenter-klassen. Koden för klassen Person ska inte ändras överhuvudtaget!

    Vägning av person

    I BebisCenter-klassens definitione finns en ram för funktionen vagning

    class BebisCenter:\n    def vagning(self, person: Person):\n        # returnera vikten av personen som passerades som argument\n        return -1

    Metoden tar ett Person-objekt som sitt argument. Den ska returnera personens vikt. Du kan komma åt en persons vikt genom attributet som definieras i Person-klassen. Vänligen fyll i resten av implementationen för metoden vagning.

    Nedan finns ett exempel på en huvudfunktion där ett BebisCenter väger två olika Person-objekt:

    haga_barnvard = BebisCenter()\n\nerik = Person(\"Erik\", 1, 110, 7)\npeter = Person(\"Peter\", 33, 176, 85)\n\nprint(f\"{erik.namn} väger {haga_barnvard.vagning(erik)} kg\")\nprint(f\"{peter.namn} väger {haga_barnvard.vagning(peter)} kg\")

    Erik väger 7 kg\nPeter väger 85 kg

    Matning

    Det är möjligt att ändra tillståndet för ett objekt som skickas som ett argument. Implementera metoden mata(person: Person) som ökar vikten på den person som skickas som argument med ett.

    I följande exempel vägs två personer, och sedan matas en av dem tre gånger. Därefter vägs personerna igen:

    haga_barnvard = BabyCenter()\n\nerik = Person(\"Erik\", 1, 110, 7)\npeter = Person(\"Peter\", 33, 176, 85)\n\nprint(f\"{erik.namn} väger {haga_barnvard.vagning(erik)} kg\")\nprint(f\"{peter.namn} väger {haga_barnvard.vagning(peter)} kg\")\nprint()\n\nhaga_barnvard.mata(erik)\nhaga_barnvard.mata(erik)\nhaga_barnvard.mata(erik)\n\nprint(f\"{erik.namn} väger {haga_barnvard.vagning(erik)} kg\")\nprint(f\"{peter.namn} väger {haga_barnvard.vagning(peter)} kg\")

    Utskriften borde visa att Eriks vikt har stigit med tre:

    Erik väger 7 kg\nPeter väger 85 kg

    Erik väger 10 kg\nPeter väger 85 kg

    Räknande av vägningar

    Implementera metoden vagningar() som returnerar det totala antalet vägningar som ett BabyCenter-objekt har utfört. OBS: Du kommer att behöva ett nytt attribut för att hålla reda på antalet vägningar. Du kan använda följande kod för att testa din metod:

    haga_barnvard = BabyCenter()\n\nerik = Person(\"Erik\", 1, 110, 7)\npeter = Person(\"Peter\", 33, 176, 85)\n\nprint(f\"Vägningar utförda {haga_barnvard.vagningar()}\")\n\nhaga_barnvard.vagning(erik)\nhaga_barnvard.vagning(erik)\n\nprint(f\"Vägningar utförda {haga_barnvard.vagningar()}\")\n\nhaga_barnvard.vagning(erik)\nhaga_barnvard.vagning(erik)\nhaga_barnvard.vagning(erik)\nhaga_barnvard.vagning(erik)\n\nprint(f\"Vägningar utförda {haga_barnvard.vagningar()}\")

    Vägningar utförda 0\nVägningar utförda 2\nVägningar utförda 6

    I föregående del fanns en övning där du implementerade klassen Lunchkort. Kortet hade separata metoder för att äta en vanlig och en speciell lunch, samt en metod för att sätta in pengar på kortet.

    Klassen Lunchkort, så som du ombads implementera den, har dock vissa problem. Kortet självt hade kunskap om priserna på de olika lunchalternativen och visste att subtrahera rätt mängd pengar från saldot baserat på dessa. Men tänk dig att priserna ändrades eller att nya varor infördes i systemet, men att flera kort redan var registrerade i systemet. Detta skulle innebära att alla befintliga kort skulle behöva ersättas med versioner med kunskap om de nya priserna.

    En bättre lösning skulle vara att göra korten ”dumma”, okunniga om priserna på olika produkter. Syftet med kortet skulle vara att helt enkelt hålla reda på det tillgängliga saldot. Alla mer komplicerade funktioner bör rymmas inom en annan klass: betalterminalen.

    Ett simplare Lunchkort

    Vi förverkligar först en dummare version av Lunchkort-klassen. Kortet borde endast ha funktioner för att få reda på det tillfälliga saldot, lägga till pengar på kortet och subtrahera pengar från saldot. Fyll i metoden subtrahera_saldo(mangd) enligt kommentarerna i övningsfältet:

    class Lunchkort:\n    def __init__(self, saldo: float):\n        self.saldo = saldo\n\n    def tillsatt_pengar(self, mangd: float):\n        self.saldo += mangd\n\n    def subtrahera_saldo(self, mangd: float):\n        pass\n        # Metoden ska endast kunna subtrahera från saldot\n        # ifall det finns tillräckligt med pengar på kortet\n        # Lyckad betalning returnerar True, icke-lyckad False.

    Huvudtestprogram:

    if __name__ == \"__main__\":\n    kort = Lunchkort(10)\n    print(\"Saldo\", kort.saldo)\n    resultat = kort.subtrahera_saldo(8)\n    print(\"Betalningen lyckades:\", resultat)\n    print(\"Saldo\", kort.saldo)\n    resultat = kort.subtrahera_saldo(4)\n    print(\"Betalningen lyckads:\", resultat)\n    print(\"Saldo\", kort.saldo)

    Saldo 10\nBetalningen lyckades: True\nSaldo 2\nBetalningen lyckades: False\nSaldo 2

    Betalningsterminalen och hanterandet av kontantbetalning

    I studentkafeterian går det att betala med kontanter eller Lunchkort. En betalterminal används för att hantera både kontant- och korttransaktioner. Låt oss börja med kontanttransaktionerna.

    Här har vi en ram för en Betalterminal-klass. Implementera metoderna enligt beskrivningen i kommentarerna:

    class Betalterminal:\n    def __init__(self):\n        # I kassan finns det ursprungligen 1000 euro i kontanter\n        self.pengar = 1000\n        self.formanliga = 0\n        self.special = 0\n\n    def at_formanligt(self, betalning: float):\n        # En formånlig lunch kostar 2.50 euro\n        # Öka värdet på pengarna som finns i terminalen med en förmånlig lunchs pris,\n        # öka mängden förmånliga luncher och returnera rätt mängd växel.\n        # Ifall betalningen inte är tillräckligt stor säljs ingen lunch och hela summan returneras\n\n    def at_special(self, betalning: float):\n        # En special lunch kostar 4.30 euro\n        # Öka värdet på pengarna som finns i terminalen med en special lunchs pris,\n        # öka mängden special luncher och returnera rätt mängd växel.\n        # Ifall betalningen inte är tillräckligt stor säljs ingen lunch och hela summan returneras

    Exempel på användning:

    exactum = Betalterminal()\n\nvaxel = exactum.at_formanligt(10)\nprint(\"Mängden växel\", vaxel)\n\nvaxel = exactum.at_formanligt(5)\nprint(\"Mängden växel\", vaxel)\n\nvaxel = exactum.at_special(4.3)\nprint(\"Mängden växel\", vaxel)\n\nprint(\"Pengar i kassan\", exactum.pengar)\nprint(\"Förmånliga luncher sålda\", exactum.formanliga)\nprint(\"Special luncher sålda\", exactum.special)

    Mängden växel 7.5\nMängden växel 2.5\nMängden växel 0.0\nPengar i kassan 1009.3\nFörmånliga luncher sålda 2\nSpecial luncher sålda 1

    Betalning med kort

    Låt oss nu implementera korttransaktioner. Vi kommer att behöva metoder som tar ett Lunchkort som argument och minskar saldot på kortet med lunchens pris. Nedan hittar du ramar av dessa funktioner. Vänligen fyll i metoderna enligt beskrivningen i kommentarerna:

    class Betalterminal:\n    # ...\n\n    def at_formanligt_kort(self, kort: Lunchkort):\n        # En förmånlig lunch kostar 2.50 euro.\n        # Om kortet har tillräckligt med pengar, subtrahera lunchens pris och returnera True.\n        # Annars returnera False\n\n\n    def at_special_kort(self, kort: Lunchkort):\n        # En special lunch kostar 4.30 euro.\n        # Om kortet har tillräckligt med pengar, subtrahera lunchens pris och returnera True.\n        # Annars returnera False

    OBS: betalningar med Lunchkort ändrar inte på mängden pengar i terminalen. Luncher säljes däremot fortfarande så länge pengarna på saldot räcker till, alltså kom ihåg att öka mängden luncher som sålts.

    Följande kod kan du använda för att testa din klass:

    exactum = Betalterminal()\n\nvaxel = exactum.at_formanligt(10)\nprint(\"Mängden växel\", vaxel)\n\nkort = Lunchkort(7)\n\nresultat = exactum.at_special_kort(kort)\nprint(\"Betalningen lyckades:\", resultat)\nresultat = exactum.at_special_kort(kort)\nprint(\"Betalningen lyckades:\", resultat)\nresultat = exactum.at_formanligt_kort(kort)\nprint(\"Betalningen lyckades:\", resultat)\n\nprint(\"Pengar i kassan\", exactum.pengar)\nprint(\"Förmånliga luncher sålda\", exactum.formanliga)\nprint(\"special luncher sålda\", exactum.special)

    Mängden växel 7.5\nBetalningen lyckades: True\nBetalningen lyckades: False\nBetalningen lyckades: True\nPengar i kassan 1002.5\nFörmånliga luncher sålda 2\nspecial luncher sålda 1

    Tillsättning av pengar på kortet

    Slutligen lägger vi till en metod som gör att du kan sätta in pengar på kortet. Kortägaren betalar detta kontant, så att den insatta summan läggs till de pengar som finns tillgängliga i terminalen. Här är en ram för metoden:

    def tillsatt_pengar_kortet(self, kort: Lunchkort, summa: float):\n    pass

    Du kan använda följande kod för att testa din metod:

    exactum = Betalterminal()\n\nantons_kort = Lunchkort(2)\nprint(f\"Kortets saldo {antons_kort.saldo} euro\")\n\nresultat = exactum.at_special_kort(antons_kort)\nprint(\"Betalningen lyckades:\", resultat)\n\nexactum.tillsatt_pengar_kortet(antons_kort, 100)\nprint(f\"Kortets saldo {antons_kort.saldo} euro\")\n\nresultat = exactum.at_special_kort(antons_kort)\nprint(\"Betalningen lyckades:\", resultat)\nprint(f\"Kortets saldo {antons_kort.saldo} euro\")\n\nprint(\"Pengar i kassan\", exactum.pengar)\nprint(\"Förmånliga luncher sålda\", exactum.formanliga)\nprint(\"special luncher sålda\", exactum.special)

    Kortets saldo 2 euro\nBetalningen lyckades: False\nKortets saldo 102 euro\nBetalningen lyckades: True\nKortets saldo 97.7 euro\nPengar i kassan 1100\nFörmånliga luncher sålda 0\nspecial luncher sålda 1

    En instans av samma klass som argument till en metod

    Nedan har vi ytterligare en version av klassen Person:

    class Person:\n    def __init__(self, namn: str, fodelsear: int):\n        self.namn = namn\n        self.fodelsear = fodelsear

    Låt oss anta att vi vill skriva ett program som jämför åldern på objekt av typen Person. Vi kan skriva en separat funktion för detta ändamål:

    def aldre_an(person1: Person, person2: Person):\n    if person1.fodelsear < person2.fodelsear:\n        return True\n    else:\n        return False\n\nmuhammad = Person(\"Muhammad ibn Musa al-Khwarizmi\", 780)\npascal = Person(\"Blaise Pascal\", 1623)\ngrace = Person(\"Grace Hopper\", 1906)\n\nif aldre_an(muhammad, pascal):\n    print(f\"{muhammad} är äldre än {pascal}\")\nelse:\n    print(f\"{muhammad} är inte äldre än {pascal}\")\n\nif aldre_an(grace, pascal):\n    print(f\"{grace} är äldre än {pascal}\")\nelse:\n    print(f\"{grace} är inte äldre än {pascal}\")

    Muhammad ibn Musa al-Khwarizmi är äldre än Blaise Pascal\nGrace Hopper är inte äldre än Blaise Pascal

    En av principerna för objektorienterad programmering är att all funktionalitet som hanterar objekt av en viss typ ska inkluderas i klassdefinitionen, som metoder. I stället för en funktion kan vi alltså skriva en metod som gör det möjligt att jämföra åldern på ett Person-objekt med ett annat Person-objekt:

    class Person:\n    def __init__(self, namn: str, fodelsear: int):\n        self.namn = namn\n        self.fodelsear = fodelsear\n\n    # OBS! Typledtrådar måste vara inom citationstecken ifall parametern är av samma typ som klassen självt!\n    def aldre_an(self, annat: \"Person\"):\n        if self.fodelsear < annat.fodelsear:\n            return True\n        else:\n            return False

    Här kallas det objekt som metoden anropas på för self, medan det andra Person-objektet kallas för annat.

    Kom ihåg att anrop av en metod skiljer sig från anrop av en funktion. En metod är kopplad till ett objekt med punktnotationen:

    muhammad = Person(\"Muhammad ibn Musa al-Khwarizmi\", 780)\npascal = Person(\"Blaise Pascal\", 1623)\ngrace = Person(\"Grace Hopper\", 1906)\n\nif muhammad.aldre_an(pascal):\n    print(f\"{muhammad.namn} är äldre än {pascal.namn}\")\nelse:\n    print(f\"{muhammad.namn} är inte äldre än {pascal.namn}\")\n\nif grace.aldre_an(pascal):\n    print(f\"{grace.namn} är äldre än {pascal.namn}\")\nelse:\n    print(f\"{grace.namn} är inte äldre än {pascal.namn}\")

    Till vänster om punkten finns själva objektet, som kallas self i metoddefinitionen. Inom parentes står argumentet till metoden, vilket är det objekt som kallas annat.

    Utskriften från programmet är exakt densamma som med funktionsimplementeringen ovan.

    Till sist, en ganska kosmetisk punkt: if...else-strukturen i metoden aldre_an är i stort sett onödig. Värdet på det booleska uttrycket i villkoret är redan exakt samma sanningsvärde som returneras. Metoden kan alltså förenklas:

    class Person:\n    def __init__(self, namn: str, fodelsear: int):\n        self.namn = namn\n        self.fodelsear = fodelsear\n\n    # OBS! Typledtrådar måste vara inom citationstecken ifall parametern är av samma typ som klassen självt!\n    def aldre_an(self, annat: \"Person\"):\n        return self.fodelsear < annat.fodelsear:

    Liksom det framkommer av kommentarerna i exemplen ovan, så måste typledtråden omslutas av citattecken ifall parametern i en metoddefinition är av samma typ som klassen själv. Om citattecknen utelämnas uppstår ett fel, vilket du kommer att se om du försöker med följande:

    class Person:\n    # ...\n\n    # Detta fungerar inte, Person måste vara innanför citationstecken\n    def aldre_an(self, annat: Person):\n        return self.fodelsear < annat.fodelsear:

    Databasen hos en fastighetsmäklare innehåller register över tillgängliga fastigheter med objekt som definieras av följande klass:

    class Bostad:\n    def __init__(self, rum: int, kvadratmeter: int, kvadratpris: int):\n        self.rum = rum\n        self.kvadratmeter = kvadratmeter\n        self.kvadratpris = kvadratpris

    Din uppgift är att implementera metoder som gör det möjligt att jämföra tillgängliga egenskaper.

    Är den större?

    Skapa metoden storre(self, jamforelse), som returnerar True, ifall Bostad-objektet är större än objektet det jämförs med.

    Exempel på hur funktionen borde fungera:

    eira_etta = Bostad(1, 16, 5500)\nberghall_tvaa = Bostad(2, 38, 4200)\njakobacka_trea = Bostad(3, 78, 2500)\n\nprint(eira_etta.storre(berghall_tvaa))\nprint(jakobacka_trea.storre(berghall_tvaa))

    False\nTrue

    Prisskillnad

    Skapa metoden prisskillnad(self, jamforelse), som returnerar skillnaden i pris mellan Bostad-objektet självt och det som det jämförs med. Prisskillnaden är det absoluta värdet av skillnaden mellan de två fastigheternas totalpriser. Det totala priset för en fastighet är dess kvadratmeterpris multiplicerat med antalet kvadratmeter i fastigheten.

    Exempel på hur funktionen borde fungera:

    eira_etta = Bostad(1, 16, 5500)\nberghall_tvaa = Bostad(2, 38, 4200)\njakobacka_trea = Bostad(3, 78, 2500)\n\nprint(eira_etta.prisskillnad(berghall_tvaa))\nprint(jakobacka_trea.prisskillnad(berghall_tvaa))

    71600\n35400

    Dyrare?

    Skapa metoden dyrare(self, jamforelse) som returnerar True, ifall Bostad-objektet är dyrare än objektet som det jämförs med.

    Exempel på hur funktionen borde fungera:

    eira_etta = Bostad(1, 16, 5500)\nberghall_tvaa = Bostad(2, 38, 4200)\njakobacka_trea = Bostad(3, 78, 2500)\n\nprint(eira_etta.dyrare(berghall_tvaa))\nprint(jakobacka_trea.dyrare(berghall_tvaa))

    False\nTrue

    ","frontmatter":{"path":"/osa-9/1-objekt-och-referenser","title":"Objekt och referenser"},"fileAbsolutePath":"/home/runner/work/ohjelmointi-24-sv/ohjelmointi-24-sv/data/osa-9/1-objekt-och-referenser.md"},"allPages":{"edges":[{"node":{"id":"b5e8ae41-d492-55f7-88a7-1c7292333ab1","frontmatter":{"path":"/arvostelu-ja-kokeet","title":"Arvostelu ja kokeet"}}},{"node":{"id":"af4df6be-211d-5ba1-acea-9edbefa06c49","frontmatter":{"path":"/frontmatter-guide","title":"Frontmatter-guide"}}},{"node":{"id":"56769133-4836-5fbb-a857-8fb0c6803e6d","frontmatter":{"path":"/","title":"Tietoa kurssista"}}},{"node":{"id":"e86762f0-c2a9-5598-aba3-2b8d7db7807c","frontmatter":{"path":"/kaikki-tehtavat","title":"Kaikki tehtävät"}}},{"node":{"id":"5d065309-85e8-5823-9527-ec1c3cf38d4d","frontmatter":{"path":"/tuki","title":"Tukea tehtäviin"}}},{"node":{"id":"ac195ee0-ad04-5cc9-9643-963f93d29ad2","frontmatter":{"path":"/usein-kysytyt-kysymykset","title":"Usein kysytyt kysymykset"}}},{"node":{"id":"51a165d7-8ce5-5d53-9c15-5321b6adef8c","frontmatter":{"path":"/verkkotentti","title":"Verkkotentti 4.6."}}},{"node":{"id":"4d9cf293-01e9-5e6c-a88f-599560e33c9a","frontmatter":{"path":"/verkkotentti-ohja","title":"Ohjelmoinnin jatkokurssin verkkotentti 16.12."}}},{"node":{"id":"279e1cca-fb0b-5d3f-b527-be05243d138d","frontmatter":{"path":"/verkkotentti-ohpe","title":"Ohjelmoinnin perusteiden verkkotentti 09.03."}}},{"node":{"id":"347bdde4-ba21-5f22-8a88-0287dfe29a45","frontmatter":{"path":"/virheilmoitukset","title":"Yleiset virheilmoitukset"}}},{"node":{"id":"3bf12e3a-1542-57f4-812d-dd32cebc99e2","frontmatter":{"path":"/sanasto","title":"Sanasto"}}},{"node":{"id":"9910673b-d62d-5d8d-a756-5267160d891f","frontmatter":{"path":"/osa-1/1-introduktion","title":"Introduktion"}}},{"node":{"id":"0b17a28e-f939-57cc-aa5b-4db407cdf34a","frontmatter":{"path":"/osa-1/2-info-fran-anvandaren","title":"Information från användaren"}}},{"node":{"id":"b95794f2-f3b3-597c-a4ec-6f023b584f81","frontmatter":{"path":"/osa-1/3-mer-om-variabler","title":"Mer om variabler"}}},{"node":{"id":"02cd0849-e7a5-5fd1-bf66-35f0197d3e75","frontmatter":{"path":"/osa-1/4-rakneoperationer","title":"Räkneoperationer"}}},{"node":{"id":"42690a69-3997-5b84-b999-15d9c3212884","frontmatter":{"path":"/osa-1/5-villkorssatser","title":"If-satser"}}},{"node":{"id":"96a0ec65-c0a3-5150-95c5-48c260f88162","frontmatter":{"path":"/osa-1","title":"Modul 1"}}},{"node":{"id":"e7a4d0c8-b8c1-53fa-ab51-9cc06fd417a3","frontmatter":{"path":"/osa-10/1-klasshierarkier","title":"Klasshierarkier"}}},{"node":{"id":"5f6d4b8b-7d05-5c79-9f2f-9e30b397167b","frontmatter":{"path":"/osa-10/2-atkamstmodifierare","title":"Åtkomstmodifierare"}}},{"node":{"id":"bb896c90-aabc-5a9d-8d4b-50839da286db","frontmatter":{"path":"/osa-10/3-objektorienterade-programmeringstekniker","title":"Objektorienterade programmeringstekniker"}}},{"node":{"id":"a2dca4f1-d64d-5e77-a3ca-8b2a208e9afa","frontmatter":{"path":"/osa-10/4-storre-applikation","title":"Att utveckla en större applikation"}}},{"node":{"id":"8c9cf5a7-f02e-5ccf-ab8f-f078c3ccecb6","frontmatter":{"path":"/osa-10","title":"Modul 10"}}},{"node":{"id":"f6688d26-5502-5c17-a8ee-db66f650f1f1","frontmatter":{"path":"/osa-11/1-list-comprehension","title":"List comprehension"}}},{"node":{"id":"1eac8489-72f2-5d53-904b-c960e2622018","frontmatter":{"path":"/osa-11/2-mer-om-comprehensions","title":"Mer om comprehensions"}}},{"node":{"id":"09630fca-7768-53f3-8aca-6e5ac638fc68","frontmatter":{"path":"/osa-11/3-rekursion","title":"Rekursion"}}},{"node":{"id":"70f6008e-a762-574c-a92a-c5c585d9677e","frontmatter":{"path":"/osa-11/4-lisaa-esimerkkeja","title":"Fler exempel på rekursion"}}},{"node":{"id":"eb8ed7d7-c39d-52db-949d-f75649498c67","frontmatter":{"path":"/osa-11","title":"Modul 11"}}},{"node":{"id":"9bba31dc-e14c-5400-a25b-7339107e9ba7","frontmatter":{"path":"/osa-12/1-funktioner-som-argument","title":"Funktioner som argument"}}},{"node":{"id":"5b9e4584-7234-5216-a118-d2a1bc617e13","frontmatter":{"path":"/osa-12/2-generatorer","title":"Generatorer"}}},{"node":{"id":"1d27636e-74f4-5c30-a1d8-08a303684945","frontmatter":{"path":"/osa-12/3-funktionell-programmering","title":"Funktionell programmering"}}},{"node":{"id":"6785750f-f145-5b88-81e9-b52e36ba53c6","frontmatter":{"path":"/osa-12/4-reguljara-uttryck","title":"Reguljära uttryck"}}},{"node":{"id":"d21df33a-4bf4-5ee3-9e2a-431d57561f09","frontmatter":{"path":"/osa-12","title":"Modul 12"}}},{"node":{"id":"14e3c129-50ec-581f-8679-8132248d41c1","frontmatter":{"path":"/osa-13/1-pygame","title":"Pygame"}}},{"node":{"id":"01bc3b9b-4f80-5561-8b56-3a7f09082263","frontmatter":{"path":"/osa-13/2-animation","title":"Animation"}}},{"node":{"id":"dd68786f-e2fc-5957-b47a-52b74c5199ef","frontmatter":{"path":"/osa-13/3-handelser","title":"Händelser"}}},{"node":{"id":"4a1aaa41-d6f7-51cd-8b89-95842cb9e02d","frontmatter":{"path":"/osa-13/4-fler-pygame-tekniker","title":"Fler pygame-tekniker"}}},{"node":{"id":"cdcf0ce1-e881-5ca6-8fa9-d0d343ec4e15","frontmatter":{"path":"/osa-13","title":"Modul 13"}}},{"node":{"id":"0ab28435-7654-5a8e-88d6-daa17d78103b","frontmatter":{"path":"/osa-14/1-spelprojekt","title":"Spelprojekt"}}},{"node":{"id":"b7a0628c-e4ba-583e-a52a-dd0ad78028d8","frontmatter":{"path":"/osa-14/2-robot-och-ladar","title":"Robot och lådor"}}},{"node":{"id":"6ccdbdff-7539-5a23-b23c-2ad48a99386f","frontmatter":{"path":"/osa-14/3-fardigstallande-av-spelet","title":"Färdigställande av spelet"}}},{"node":{"id":"1b505c9f-9b1b-58bd-8df7-553fef49cc8d","frontmatter":{"path":"/osa-14/4-ditt-eget-sepl","title":"Ditt eget spel"}}},{"node":{"id":"55c54859-8c7f-5fd9-8a8d-2c54ee677577","frontmatter":{"path":"/osa-14","title":"Modul 14"}}},{"node":{"id":"b5c346d1-d175-5824-98bb-4a4c3b45204d","frontmatter":{"path":"/osa-2/1-terminologi","title":"Programmeringsterminologi"}}},{"node":{"id":"db7188b0-0253-5c30-b8d2-0e115e235fb3","frontmatter":{"path":"/osa-2/2-else-elif","title":"Mera om if-satser"}}},{"node":{"id":"49d15928-f8b9-5883-9f29-86c307f6929e","frontmatter":{"path":"/osa-2/3-kombinera-villkor","title":"Kombinera villkor"}}},{"node":{"id":"93f1f9c8-6b27-5892-8bd4-7d1d008bf07a","frontmatter":{"path":"/osa-2/4-loopar","title":"Enkla loopar"}}},{"node":{"id":"5523b5b8-61f8-506d-bfe0-c6cc774390ce","frontmatter":{"path":"/osa-2","title":"Modul 2"}}},{"node":{"id":"02012307-c2a6-5cf2-9105-c10933c14b37","frontmatter":{"path":"/osa-3/1-loopar-med-villkor","title":"Loopar med villkor"}}},{"node":{"id":"efb889f4-4a19-515e-a0f6-4297d76a2757","frontmatter":{"path":"/osa-3/2-behandla-strangar","title":"Behandla strängar"}}},{"node":{"id":"a602077d-bbae-5eb7-a354-cc44b29ae96a","frontmatter":{"path":"/osa-3/3-mer-om-loopar","title":"Mera om loopar"}}},{"node":{"id":"6d878692-b9c7-57e6-ae58-044e5a6bef6f","frontmatter":{"path":"/osa-3/4-definiera-funktioner","title":"Definiera funktioner"}}},{"node":{"id":"682b5a18-73c5-56e2-8374-237baccbab40","frontmatter":{"path":"/osa-3","title":"Modul 3"}}},{"node":{"id":"3de95518-6b44-54db-9bcd-0c90a41d2fd5","frontmatter":{"path":"/osa-4/1-vscode","title":"Editorn Visual Studio Code, Pythontolken och det inbyggda debuggningsverktyget"}}},{"node":{"id":"7de9921c-7f94-58fe-84b9-7676dddb3b94","frontmatter":{"path":"/osa-4/2-mer-om-funktioner","title":"Mer om funktioner"}}},{"node":{"id":"29e29c69-360c-5f5c-8f34-5aef22eb327f","frontmatter":{"path":"/osa-4/3-listor","title":"Listor"}}},{"node":{"id":"bfe57880-0cbb-54e4-be9c-8fa180eafe6b","frontmatter":{"path":"/osa-4/4-iteration","title":"Iteration"}}},{"node":{"id":"2eab46f0-5373-5cbe-b2a0-1d071854a053","frontmatter":{"path":"/osa-4/5-utskrift","title":"Formatera utskrift"}}},{"node":{"id":"a5974fee-f2eb-5b89-88a5-6dd3754baaad","frontmatter":{"path":"/osa-4/6-strangar-listor","title":"Mera strängar och listor"}}},{"node":{"id":"e125c469-ee19-505e-9a41-83da6143ecd8","frontmatter":{"path":"/osa-4","title":"Modul 4"}}},{"node":{"id":"2558444a-be1d-5bc6-95ab-e091da2443fc","frontmatter":{"path":"/osa-5/1-mer-om-listor","title":"Mer om listor"}}},{"node":{"id":"b452d9be-0569-56c2-ba89-a040d4cb40dc","frontmatter":{"path":"/osa-5/2-referenser","title":"Referenser"}}},{"node":{"id":"ebe4ca3f-e657-5907-bfcc-ae84d9947aff","frontmatter":{"path":"/osa-5/3-lexikon","title":"Lexikon"}}},{"node":{"id":"f1dd5d66-ac87-5e53-92a0-0b7e3ece6ed8","frontmatter":{"path":"/osa-5/4-tuple","title":"Tuple"}}},{"node":{"id":"161c0109-5c00-5bed-b7af-90dc7ddf5713","frontmatter":{"path":"/osa-5","title":"Modul 5"}}},{"node":{"id":"e6cfa6e1-e99b-50e0-bc6a-3c0f153420e8","frontmatter":{"path":"/osa-6/1-lasa-filer","title":"Läsa filer"}}},{"node":{"id":"ce8d90a4-ca7c-5797-abc1-3fe0094bfa4b","frontmatter":{"path":"/osa-6/2-skriva-filer","title":"Skriva filer"}}},{"node":{"id":"519d5330-277a-59ba-be50-c2f63080df94","frontmatter":{"path":"/osa-6/3-fel","title":"Förbered dig på fel"}}},{"node":{"id":"82393756-3ef8-5d07-a8da-fed818ca43f0","frontmatter":{"path":"/osa-6/4-lokala-globala-variabler","title":"Lokala och globala variabler"}}},{"node":{"id":"007d85ae-a118-5b10-8a7e-18302b15eba8","frontmatter":{"path":"/osa-6","title":"Modul 6"}}},{"node":{"id":"bbb2346d-b1ee-551d-89c1-516f119b0eed","frontmatter":{"path":"/osa-7/1-moduler","title":"Moduler"}}},{"node":{"id":"ecb9af64-49f9-5e28-a544-3934e95233cf","frontmatter":{"path":"/osa-7/2-slumpmassighet","title":"Slumpmässighet"}}},{"node":{"id":"ebe469ef-c486-523a-9621-5dc4040c5cd8","frontmatter":{"path":"/osa-7/3-tid-datum","title":"Tid och datum"}}},{"node":{"id":"b9cf2d99-08f6-5de5-8425-c9b483241567","frontmatter":{"path":"/osa-7/4-behandla-data","title":"Behandla data"}}},{"node":{"id":"27075b37-8a6a-5554-9079-465a36d2da2d","frontmatter":{"path":"/osa-7/5-egna-moduler","title":"Skapa dina egna moduler"}}},{"node":{"id":"69492225-4d69-59ea-b33d-5301d35cf4ed","frontmatter":{"path":"/osa-7/6-funktionaliteter-python","title":"Flera funktionaliteter i Python"}}},{"node":{"id":"70ae841a-e6e9-5252-afae-6329fb67bcad","frontmatter":{"path":"/osa-7","title":"Modul 7"}}},{"node":{"id":"4afc4486-3cfe-53d1-b4c0-6db26484acfa","frontmatter":{"path":"/osa-8/1-objekt-och-metoder","title":"Objekt och metoder"}}},{"node":{"id":"6be37772-e94b-5b36-8a02-fffa7eef9feb","frontmatter":{"path":"/osa-8/2-klasser-och-objekt","title":"Klasser och objekt"}}},{"node":{"id":"8b6aec39-f8b9-525c-9f25-d8e73389fa42","frontmatter":{"path":"/osa-8/3-egna-klasser","title":"Egna klasser"}}},{"node":{"id":"85db460a-77c6-5087-8e97-a3c772186fd9","frontmatter":{"path":"/osa-8/4-metoder-i-egna-klasser","title":"Metoder i egna klasser"}}},{"node":{"id":"0e59dee0-5dd9-5827-83b9-a55e7d585c31","frontmatter":{"path":"/osa-8/5-fler-exempel","title":"Fler exempel"}}},{"node":{"id":"64715d0c-54f1-5aa7-a566-d2c5be6523ea","frontmatter":{"path":"/osa-8","title":"Modul 8"}}},{"node":{"id":"f7457509-a9a6-5420-8d03-ff1c61df8dc4","frontmatter":{"path":"/osa-9/1-objekt-och-referenser","title":"Objekt och referenser"}}},{"node":{"id":"16689ce4-b6aa-5bc4-9a30-44820994d6ea","frontmatter":{"path":"/osa-9/2-objekt-som-attribut","title":"Objekt som attribut "}}},{"node":{"id":"07985959-e85a-5f45-8923-babacb943c04","frontmatter":{"path":"/osa-9/3-inkapsling","title":"Inkapsling"}}},{"node":{"id":"83108600-9a37-5fd1-9a2b-13492879a9d6","frontmatter":{"path":"/osa-9/4-metodernas-rackvidd","title":"Metodernas räckvidd"}}},{"node":{"id":"a553cdc9-d6ac-5a14-ab43-d44811b407a2","frontmatter":{"path":"/osa-9/5-klassattribut","title":"Klassattribut"}}},{"node":{"id":"f7d7c9f1-6b54-5268-a308-995d49dd913d","frontmatter":{"path":"/osa-9/6-fler-exempel-med-klasser","title":"Fler exempel med klasser"}}},{"node":{"id":"c1fef3f7-8ca3-5780-9dec-19bd672b4627","frontmatter":{"path":"/osa-9","title":"Modul 9"}}}]}},"pageContext":{}}, + "result": {"data":{"page":{"htmlAst":{"type":"element","tagName":"div","properties":{},"children":[{"type":"element","tagName":"text-box","properties":{"variant":"learningObjectives","name":"Inlärningsmål"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Efter den här delen"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Kommer du att kunna använda olika datastrukturer för att hantera objekt"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Vet du hur objekt kan bli passerade som argument"}]},{"type":"text","value":"\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Varje värde i Python är ett objekt. Alla objekt som du skapar baserat på en klass som du själv har definierat fungerar exakt på samma sätt som alla \"vanliga\" Python-objekt. Objekt kan till exempel lagras i en lista:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"from"}]},{"type":"text","value":" datetime "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"import"}]},{"type":"text","value":" date\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"SlutfordKurs"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kurs"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" studiepoang"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" slutforsdatum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" date"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"kurs "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" kurs\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"studiepoang "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" studiepoang\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"slutforsdatum "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" slutforsdatum\n\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi skapar några slutförda kurser och lägger dessa i en lista"}]},{"type":"text","value":"\n prestationer "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n mat1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" SlutfordKurs"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Matematik 1\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" date"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2020"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"11"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n prg1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" SlutfordKurs"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Programmering 1\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"6"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" date"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2019"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"12"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"17"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n prestationer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"mat1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n prestationer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"prg1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi lägger några till rakt till listan"}]},{"type":"text","value":"\n prestationer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"SlutfordKurs"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Fysik 2\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" date"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2019"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"11"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n prestationer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"SlutfordKurs"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Programmering 2\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" date"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2020"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"19"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi går igenom alla slutförda kurser, skriver ut deras namn och räknar ihop den totala mängden studiepoäng"}]},{"type":"text","value":"\n studiepoang "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" prestation "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" prestationer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"prestation"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"kurs"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n studiepoang "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+="}]},{"type":"text","value":" prestation"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"studiepoang\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Studiepoäng totalt:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" studiepoang"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Matematik 1\nProgrammering 1\nFysik 2\nProgrammering 2\nStudiepoäng totalt: 20"}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Snabbaste bilen","tmcname":"osa09-01_snabbaste_bil"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Uppgiftsbotten har en klass med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bil"}]},{"type":"text","value":" som representerar en bil genom två attribut: "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"marke (str)"}]},{"type":"text","value":" och "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"topphastighet (int)"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa funktionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"snabbaste_bil(bilar: list)"}]},{"type":"text","value":", som får en lista av "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bil"}]},{"type":"text","value":"-objekt som argument."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska returnera märket på den snabbaste bilen. Du kan anta att det alltid kommer att finnas en enda bil med den högsta topphastigheten. Ändra inte listan som ges som argument, gör heller inte några ändringar i klassdefinitionen för "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bil"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Du kan använda följande kod för att testa din funktion:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n bil1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bil"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Mersu\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"195"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n bil2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bil"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Lada\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"110"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n bil3 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bil"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Ferrari\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"280"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n bil4 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bil"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Trabant\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"85"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n bilar "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"bil1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" bil2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" bil3"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" bil4"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"snabbaste_bil"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"bilar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Ferrari"}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Godkända prestationer","tmcname":"osa09-02_godkanda_prestationer"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I uppgiftsbotten hittas klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Provprestation"}]},{"type":"text","value":", som, liksom namnet anger, tar modell av en provtagares prestation i ett prov. Den har två attribut, "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"presterare (str)"}]},{"type":"text","value":" och "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"poang (int)"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa funktionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"godkanda(prestationer: list, poanggrans: int)"}]},{"type":"text","value":", som får som parametrar en lista av provprestationer och ett heltal som representerar det minsta poängantalet för att bli godkänd."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Funktionen ska skapa och returnera en ny lista, som innehåller endast de prov som kom över poänggränsen i den ursprungliga listan. Ändra inte listan som ges som argument, ändra heller inte definitionen för klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Provprestation"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Du kan använda följande kod för att testa funktionen:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n s1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Provprestation"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"12"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n s2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Provprestation"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Pernilla\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"19"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n s3 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Provprestation"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Per\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"15"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n s4 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Provprestation"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Pia\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"9"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n s5 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Provprestation"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Petra\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"17"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n klarade "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" godkanda"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"s1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" s2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" s3"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" s4"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" s5"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"15"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" godkand "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" klarade"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"klarade"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Provprestation (presterare: Pernilla, poang: 19)\nProvprestation (presterare: Per, poang: 15)\nProvprestation (presterare: Petra, poang: 17)"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Du kanske minns att listor inte innehåller några objekt i sig själva. De innehåller referenser till objekt. Exakt samma objekt kan förekomma flera gånger i en och samma lista, och det kan refereras till flera gånger i listan eller utanför den. Låt oss ta en titt på ett exempel:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Produkt"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" enhet"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"enhet "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" enhet\n\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n affarslista "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n mjolk "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Produkt"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Mjölk\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"liter\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n affarslista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"mjolk"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n affarslista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"mjolk"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n affarslista"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"Produkt"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Gurka\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"st\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-wrapper"],"style":"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 313px; margin-bottom: 1rem;"},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"a","properties":{"className":["gatsby-resp-image-link"],"href":"/ohjelmointi-24-sv/static/a3722ba9326d57861bd87ed8593aab50/80977/9_1_1.png","style":"display: block","target":"_blank","rel":["noopener"]},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-background-image"],"style":"padding-bottom: 64.34782608695653%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAYAAACpUE5eAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABi0lEQVQ4y22TfW+CQAzG+f7faokhbH9MBgOdC5NXMcZ35VX0WZ5m5w60CTnu2v7aa3sG/uR2u8ma5zm22y0OhwP2+718u90Oq9VKmaKqKiyXSxyPx7u+LEt4ngdjCKTBM6GTEjrzG0qapo/AxSLHp+MiTlJMPA/j8QfquukBm6bBTxDAdT4RhhHs9zGSJEWSJE+AWYrRy4sYv1oWoiiWc5ZBBwbfXzBHJmazGdJsIedRFD0CN5uNXKdtWlRVjev1KjodSD1r3HUd2rYVG0ocx0+AmqMuDKQDT6fTg00Yho9A1orO6/Uavu8jCAJZ2Vkll8tF9OzydDoVm/P53M9Qh/43aCFOXNW50imhrq7r+95QRjpM/bP4Us+2FfBQeO2iKHp+PeAwQxadg84MuNKZQbjnvxp23c8YRtXBzGA+n4sjC84a8YWwztxnWdYDypXfrFd82A58f4KyrCQ6R4QQ27Z7s6c6rCCq03oSRlkUYsQudt21F5GDSijfqGma0lHLsuA4DlzXlaEeZvgL31rp5spmjHgAAAAASUVORK5CYII='); background-size: cover; display: block;"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"picture","properties":{},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/a3722ba9326d57861bd87ed8593aab50/a0b58/9_1_1.webp 230w","/ohjelmointi-24-sv/static/a3722ba9326d57861bd87ed8593aab50/12766/9_1_1.webp 313w"],"sizes":"(max-width: 313px) 100vw, 313px","type":"image/webp"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/a3722ba9326d57861bd87ed8593aab50/81c8e/9_1_1.png 230w","/ohjelmointi-24-sv/static/a3722ba9326d57861bd87ed8593aab50/80977/9_1_1.png 313w"],"sizes":"(max-width: 313px) 100vw, 313px","type":"image/png"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"img","properties":{"className":["gatsby-resp-image-image"],"src":"/ohjelmointi-24-sv/static/a3722ba9326d57861bd87ed8593aab50/80977/9_1_1.png","alt":"9 1 1","title":"9 1 1","loading":"lazy","decoding":"async","style":"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"},"children":[]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Om det finns mer än en referens till samma objekt spelar det ingen roll vilken av referenserna som används:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Hund"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__str__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn\n\nhundar "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\nmolly "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Hund"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Molly\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhundar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"molly"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhundar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"molly"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhundar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"Hund"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Molly\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Hundar i början:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" hund "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" hundar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"hund"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Hunden på index 0 får ett nytt namn:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhundar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Rex\""}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" hund "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" hundar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"hund"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Hunden på index 2 får ett nytt namn:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhundar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Fifi\""}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" hund "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" hundar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"hund"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Koirat alussa:\nMolly\nMolly\nMolly\nHunden på index 0 får ett nytt namn::\nRex\nRex\nMolly\nHunden på index 2 får ett nytt namn:\nRex\nRex\nFifi"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Referenserna på index 0 och 1 i listan hänvisar till samma objekt. Var och en av referenserna kan användas för att komma åt objektet. Referensen på index 2 hänvisar till ett annat objekt, men med till synes samma innehåll. Om innehållet i det senare objektet ändras påverkas inte det andra."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Operatorn "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"is"}]},{"type":"text","value":" används för att kontrollera om de två referenserna hänvisar till exakt samma objekt, medan operatorn "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" talar om för dig om innehållet i objekten är detsamma. Följande exempel gör förhoppningsvis skillnaden tydlig:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"lista1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\nlista2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\nlista3 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" lista1\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista1 "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"is"}]},{"type":"text","value":" lista2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista1 "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"is"}]},{"type":"text","value":" lista3"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista2 "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"is"}]},{"type":"text","value":" lista3"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" lista2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista1 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" lista3"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"lista2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" lista3"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"False\nTrue\nFalse"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"True\nTrue\nTrue"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Alla Python-objekt kan också lagras i en ordlista eller någon annan datastruktur. Detta gäller även objekt som är av en klass som du själv har definierat."}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Studerande"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" sp"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"sp "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" sp\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Vi använder studerandenummer som nyckel och värdet som fås är ett objekt av typen Studerande"}]},{"type":"text","value":"\n studeranden "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n studeranden"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"12345\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Studerande"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Olle Studerande\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n studeranden"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"54321\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Studerande"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Ove Studerande\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"67"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"http://www.pythontutor.com/visualize.html#mode=edit","target":"_blank","rel":["noopener","noreferrer"]},"children":[{"type":"text","value":"Visualiseringsverktyget"}]},{"type":"text","value":" kan hjälpa dig att förstå exemplet ovan:"}]},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-wrapper"],"style":"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 920px; margin-bottom: 1rem;"},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"a","properties":{"className":["gatsby-resp-image-link"],"href":"/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/15171/9_1_2.png","style":"display: block","target":"_blank","rel":["noopener"]},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["gatsby-resp-image-background-image"],"style":"padding-bottom: 43.04347826086957%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAIAAAC9o5sfAAAACXBIWXMAABYlAAAWJQFJUiTwAAABPklEQVQoz2WR20rEMBBA/f+/8k0RFUVExdVda7ubtnHbSSfN3FLtVlHWA4E85DBnyEkYUow44Oj36PexB4wRpx9yzvPJ2cymf5xQSuM4ElHre1fvmSX/IGqA4xBHFgkBzPRYHgZ0BwIAMxFRSslynqbJeTi9uC9cr6ptceHr8zBcxXiNeKXazzIz9wcAYMkzs3yQY6Jy14ZILAJ+ReNONIqgCJrJLHddt1q9FEVRVVXT1AAQQmDmpXzJU5WuOuu7x3nv/CcbADabTVG873aurhvnnPfeOdc0zSHh9+lIXL7ddPvbMNwzl7OMiCmlnKcwUB+Sqi3xfycvmJl3dxHvRB5Ui28ZIxIRM5uZqorIcjn6HjMt15feX0K4IXqb5cQWQ6jK8nW93m63bdsy8zLnaPI05fDxHOOTyLNq9SV/Av8dBuHbnwNlAAAAAElFTkSuQmCC'); background-size: cover; display: block;"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"picture","properties":{},"children":[{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/a0b58/9_1_2.webp 230w","/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/bc10c/9_1_2.webp 460w","/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/966d8/9_1_2.webp 920w","/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/445df/9_1_2.webp 1380w","/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/78de1/9_1_2.webp 1840w","/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/995bd/9_1_2.webp 2230w"],"sizes":"(max-width: 920px) 100vw, 920px","type":"image/webp"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"source","properties":{"srcSet":["/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/81c8e/9_1_2.png 230w","/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/08a84/9_1_2.png 460w","/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/c0255/9_1_2.png 920w","/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/b1001/9_1_2.png 1380w","/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/161ec/9_1_2.png 1840w","/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/15171/9_1_2.png 2230w"],"sizes":"(max-width: 920px) 100vw, 920px","type":"image/png"},"children":[]},{"type":"text","value":"\n "},{"type":"element","tagName":"img","properties":{"className":["gatsby-resp-image-image"],"src":"/ohjelmointi-24-sv/static/d20c7f9a5570bf04d75c3836868a8870/c0255/9_1_2.png","alt":"9 1 2","title":"9 1 2","loading":"lazy","decoding":"async","style":"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"},"children":[]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"text","value":"\n "}]},{"type":"element","tagName":"h2","properties":{"id":"self-eller-inget-self","style":"position:relative;"},"children":[{"type":"text","value":"Self eller inget self?"},{"type":"element","tagName":"a","properties":{"href":"#self-eller-inget-self","ariaLabel":"self eller inget self permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Hittills har vi bara snuddat vid ytan när det gäller att använda parameternamnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":". Låt oss titta närmare på när det bör eller inte bör användas."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Nedan har vi en enkel klass som låter oss skapa ett ordförråd-objekt som innehåller några ord:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Ordforrad"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"tillsatt_ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"not"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"utskrift"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"sorted"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nordforrad "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Ordforrad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nordforrad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_ord"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nordforrad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_ord"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"objekt\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nordforrad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_ord"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"objekt-orienterad programmering\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nordforrad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_ord"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"objekt\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nordforrad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_ord"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"nörd\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nordforrad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"utskrift"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"nörd\nobjekt\nobjekt-orienterad programmering\npython"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Listan med ord lagras i ett attribut med namnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self.ord"}]},{"type":"text","value":". I det här fallet är parameternamnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":" obligatoriskt både i klassens konstruktormetod och i alla andra metoder som använder variabeln. Om "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":" utelämnas kommer de olika metoderna inte att få tillgång till samma lista med ord."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss lägga till en ny metod i vår klassdefinition. Metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"langsta_ord(self)"}]},{"type":"text","value":" returnerar (ett av) de längsta orden i ordförrådet."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Följande är ett sätt att utföra denna uppgift, men vi kommer snart att se att det inte är ett särskilt bra sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Ordforrad"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# ..."}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"langsta_ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# vi definierar två hjälpvariabler"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"langsta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"\""}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"langsta_langd "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"langsta_langd"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"langsta_langd "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"langsta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"langsta"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Den här metoden använder två hjälpvariabler som deklareras med parameternamnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":". Kom ihåg att namnen på variablerna inte spelar någon roll i funktionell mening, så dessa variabler kan också namnges mer förvirrande som till exempel "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"hjalpare"}]},{"type":"text","value":" och "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"hjalpare2"}]},{"type":"text","value":". Koden börjar se lite kryptisk ut:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Ordforrad"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# ..."}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"langsta_ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# vi definierar två hjälpvariabler"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"\""}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"När en variabel deklareras med parameternamnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":" blir den ett attribut till objektet. Detta innebär att variabeln kommer att existera så länge objektet existerar. Specifikt kommer variabeln att fortsätta existera även efter att metoden som deklarerar den har avslutat sin exekvering (engelska “Execution”). I exemplet ovan är detta helt onödigt, eftersom hjälpvariablerna endast är avsedda att användas inom metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"longest_word(self)"}]},{"type":"text","value":". Så att deklarera hjälpvariabler med parameternamnet "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":" är inte en särskilt bra idé här."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Förutom att variabler kan existera efter sitt \"utgångsdatum\" kan användning av "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":" för att skapa nya attribut där de inte är nödvändiga orsaka svåra buggar i din kod. Särskilt generiskt namngivna attribut som "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self.hjalpare"}]},{"type":"text","value":", som sedan används i flera olika metoder, kan orsaka oväntade beteenden som är svåra att spåra."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Om t.ex. en hjälpvariabel deklareras som ett attribut och tilldelas ett ursprungligt värde i konstruktorn, men variabeln sedan används i ett orelaterat sammanhang i en annan metod, blir resultatet ofta oförutsägbart:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Ordforrad"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# vi definierar hjälparvariabler"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"\""}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"\""}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare3 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"\""}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare4 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"\""}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# ..."}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"langsta_ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# detta fungerar inte eftersom hjalpare2 har fel typ"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare2 "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"hjalpare"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Man skulle kunna tro att detta skulle lösas genom att bara deklarera attributen där de används, utanför konstruktorn, men detta resulterar i en situation där de attribut som är tillgängliga via ett objekt är beroende av vilka metoder som har utförts. I föregående del såg vi att fördelen med att deklarera attribut i konstruktorn är att alla instanser av klassen då kommer att ha exakt samma attribut. Om så inte är fallet kan det lätt leda till fel om man använder olika instanser av klassen."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Sammanfattningsvis, om du behöver hjälpvariabler för användning inom en enda metod, är det korrekta sättet att göra det utan "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":". För att göra din kod lättare att förstå, använd också informativa variabelnamn:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Ordforrad"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# ..."}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"langsta_ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# detta är det korrekta sättet att definiera"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# hjälpvariabler för användning i en enda metod"}]},{"type":"text","value":"\n langsta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"\""}]},{"type":"text","value":"\n langsta_langd "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">"}]},{"type":"text","value":" langsta_langd"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n langsta_langd "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n langsta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"ord"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" langsta"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I implementeringen ovan är hjälpvariablerna endast tillgängliga när metoden utförs. De värden som lagras i dem kan inte orsaka komplikationer i andra delar av programmet."}]},{"type":"element","tagName":"h2","properties":{"id":"objekt-som-argument-till-funktioner","style":"position:relative;"},"children":[{"type":"text","value":"Objekt som argument till funktioner"},{"type":"element","tagName":"a","properties":{"href":"#objekt-som-argument-till-funktioner","ariaLabel":"objekt som argument till funktioner permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"De objekt som skapas baserat på våra egna klasser är vanligtvis mutabla. Du kanske kommer ihåg att till exempel Python-listor är föränderliga: när de passeras som argument till funktioner kan deras innehåll ändras som ett resultat av exekveringen."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss titta på ett enkelt exempel där en funktion får en referens till ett objekt av typen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Studerande"}]},{"type":"text","value":" som sitt argument. Funktionen ändrar sedan namnet på studenten. Både funktionen och huvudfunktionen som anropar den har åtkomst till samma objekt, så ändringen syns även i huvudfunktionen."}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Studerande"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" studerandenummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"studerandenummer "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" studerandenummer\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__str__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" ("}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"studerandenummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":")\""}]}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# observera att typledtråden använder namnet på klassen definierad ovan"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"andra_namn"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"studerande"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" Studerande"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n studerande"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Olle Studerande\""}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# skapa ett Studerande-objekt"}]},{"type":"text","value":"\nolle "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Studerande"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Olle Elev\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"12345\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"olle"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nandra_namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"olle"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"olle"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Olle Elev (12345)\nOlle Studerande (12345)"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Det är också möjligt att skapa objekt inom funktioner. Om en funktion returnerar en referens till det nyskapade objektet är det också åtkomligt inom huvudfunktionen:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"from"}]},{"type":"text","value":" random "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"import"}]},{"type":"text","value":" randint"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" choice\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Studerande"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" studerandenummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"studerandenummer "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" studerandenummer\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__str__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" ("}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"studerandenummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":")\""}]}]},{"type":"text","value":"\n\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Denna funktion skapar och returnerar ett nytt Studerande-objekt."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Den väljer slumpmässigt värden för namnet och studerandenumret."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"ny_studerande"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n fornamn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Atte\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Minna\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Maria\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n efternamn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Virtanen\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Lahtinen\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Leinonen\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Pythonson\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Slumpmässigt namn"}]},{"type":"text","value":"\n namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" choice"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"fornamn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\" \""}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+"}]},{"type":"text","value":" choice"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"efternamn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Slumpmässigt studerandenummer"}]},{"type":"text","value":"\n studerandenummer "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"randint"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10000"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"99999"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Skapa och returnera ett Studerande-objekt"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" Studerande"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" studerandenummer"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Kalla funktionen fem gånger och spara resultatet i en lista"}]},{"type":"text","value":"\n studeranden "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" i "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"range"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n studeranden"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"ny_studerande"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Skriv ut resultatet"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" studerande "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" studeranden"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"studerande"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Om du kör ovanstående kan det resultera i följande utskrift (OBS: eftersom slumpen är inblandad kommer resultaten sannolikt att bli annorlunda om du testar koden själv)."}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Maria Lahtinen (36213)\nAtte Virtanen (11859)\nMaria Pythonen (77330)\nAtte Pythonson (86451)\nMinna Pythonson (86211)"}]}]},{"type":"element","tagName":"h2","properties":{"id":"objekt-som-argument-till-metoder","style":"position:relative;"},"children":[{"type":"text","value":"Objekt som argument till metoder"},{"type":"element","tagName":"a","properties":{"href":"#objekt-som-argument-till-metoder","ariaLabel":"objekt som argument till metoder permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"På liknande sätt kan objekt fungera som argument till metoder. Låt oss ta en titt på ett exempel från en nöjespark:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Person"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" langd"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"langd "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" langd\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Akattraktion"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" langdgrans"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"besokare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"langdgrans "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" langdgrans\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"ta_ombord"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"langd "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">="}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"langdgrans"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"besokare "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" kom ombord\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" var för kort :(\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__str__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" ("}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"besokare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" besökare)\""}]}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Attraktionen innehåller en metod "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"motta_besökare"}]},{"type":"text","value":", som tar ett objekt av typen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Person"}]},{"type":"text","value":" som argument. Om besökaren är tillräckligt lång släpps denne ombord och antalet besökare ökas. Klasserna kan testas på följande sätt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"berg_och_dalbana "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Akattraktion"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Berg_och_dalbana\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"120"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\njakob "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Jakob\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"172"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nvilma "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Vilma\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"105"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nberg_och_dalbana"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"ta_ombord"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"jakob"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nberg_och_dalbana"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"ta_ombord"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"vilma"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"berg_och_dalbana"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Jakob kom ombord\nVenla var för kort :(\nBerg_och_dalbana (1 besökare)"}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Bebiscenter","tmcname":"osa09-03_bebiscenter"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I uppgiftsbotten finns färdigt redan en klass "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Person"}]},{"type":"text","value":" såväl som en ram för klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"BebisCenter"}]},{"type":"text","value":". Ett "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"BebisCenter"}]},{"type":"text","value":"-objekt utför olika handlingar såsom mäter eller matar personer. I denna uppgift implementerar du resten av "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"BebisCenter"}]},{"type":"text","value":"-klassen. Koden för klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Person"}]},{"type":"text","value":" ska inte ändras överhuvudtaget!"}]},{"type":"element","tagName":"h2","properties":{"id":"vagning-av-person","style":"position:relative;"},"children":[{"type":"text","value":"Vägning av person"},{"type":"element","tagName":"a","properties":{"href":"#vagning-av-person","ariaLabel":"vagning av person permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"BebisCenter"}]},{"type":"text","value":"-klassens definitione finns en ram för funktionen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"vagning"}]}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"BebisCenter"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"vagning"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# returnera vikten av personen som passerades som argument"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Metoden tar ett "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Person"}]},{"type":"text","value":"-objekt som sitt argument. Den ska returnera personens vikt. Du kan komma åt en persons vikt genom attributet som definieras i "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Person"}]},{"type":"text","value":"-klassen. Vänligen fyll i resten av implementationen för metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"vagning"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Nedan finns ett exempel på en huvudfunktion där ett "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"BebisCenter"}]},{"type":"text","value":" väger två olika "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Person"}]},{"type":"text","value":"-objekt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"haga_barnvard "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" BebisCenter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nerik "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Erik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"110"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\npeter "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"33"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"176"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"85"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" väger "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"haga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" kg\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"peter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" väger "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"haga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"peter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" kg\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Erik väger 7 kg\nPeter väger 85 kg"}]}]},{"type":"element","tagName":"h2","properties":{"id":"matning","style":"position:relative;"},"children":[{"type":"text","value":"Matning"},{"type":"element","tagName":"a","properties":{"href":"#matning","ariaLabel":"matning permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Det är möjligt att ändra tillståndet för ett objekt som skickas som ett argument. Implementera metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"mata(person: Person)"}]},{"type":"text","value":" som ökar vikten på den person som skickas som argument med ett."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I följande exempel vägs två personer, och sedan matas en av dem tre gånger. Därefter vägs personerna igen:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"haga_barnvard "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" BabyCenter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nerik "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Erik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"110"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\npeter "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"33"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"176"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"85"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" väger "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"haga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" kg\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"peter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" väger "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"haga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"peter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" kg\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nhaga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"mata"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhaga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"mata"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhaga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"mata"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" väger "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"haga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" kg\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"peter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" väger "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"haga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"peter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" kg\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Utskriften borde visa att Eriks vikt har stigit med tre:"}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Erik väger 7 kg\nPeter väger 85 kg"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Erik väger 10 kg\nPeter väger 85 kg"}]}]},{"type":"element","tagName":"h2","properties":{"id":"raknande-av-vagningar","style":"position:relative;"},"children":[{"type":"text","value":"Räknande av vägningar"},{"type":"element","tagName":"a","properties":{"href":"#raknande-av-vagningar","ariaLabel":"raknande av vagningar permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Implementera metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"vagningar"}]},{"type":"text","value":"() som returnerar det totala antalet vägningar som ett "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"BabyCenter"}]},{"type":"text","value":"-objekt har utfört. OBS: Du kommer att behöva ett nytt attribut för att hålla reda på antalet vägningar. Du kan använda följande kod för att testa din metod:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"haga_barnvard "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" BabyCenter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nerik "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Erik\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"110"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\npeter "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Peter\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"33"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"176"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"85"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\"Vägningar utförda "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"haga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nhaga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhaga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\"Vägningar utförda "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"haga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nhaga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhaga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhaga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nhaga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"erik"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\"Vägningar utförda "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"haga_barnvard"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"vagningar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Vägningar utförda 0\nVägningar utförda 2\nVägningar utförda 6"}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Lunchkort och betalterminal","tmcname":"osa09-04_lunchkort_och_betalterminal"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I föregående del fanns en "},{"type":"element","tagName":"a","properties":{"href":"/ohjelmointi-24-sv/osa-8/5-lisaa-esimerkkeja#programming-exercise-maksukortti"},"children":[{"type":"text","value":"övning"}]},{"type":"text","value":" där du implementerade klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Lunchkort"}]},{"type":"text","value":". Kortet hade separata metoder för att äta en vanlig och en speciell lunch, samt en metod för att sätta in pengar på kortet."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Lunchkort"}]},{"type":"text","value":", så som du ombads implementera den, har dock vissa problem. Kortet självt hade kunskap om priserna på de olika lunchalternativen och visste att subtrahera rätt mängd pengar från saldot baserat på dessa. Men tänk dig att priserna ändrades eller att nya varor infördes i systemet, men att flera kort redan var registrerade i systemet. Detta skulle innebära att alla befintliga kort skulle behöva ersättas med versioner med kunskap om de nya priserna."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"En bättre lösning skulle vara att göra korten ”dumma”, okunniga om priserna på olika produkter. Syftet med kortet skulle vara att helt enkelt hålla reda på det tillgängliga saldot. Alla mer komplicerade funktioner bör rymmas inom en annan klass: betalterminalen."}]},{"type":"element","tagName":"h2","properties":{"id":"ett-simplare-lunchkort","style":"position:relative;"},"children":[{"type":"text","value":"Ett simplare Lunchkort"},{"type":"element","tagName":"a","properties":{"href":"#ett-simplare-lunchkort","ariaLabel":"ett simplare lunchkort permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Vi förverkligar först en dummare version av "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Lunchkort"}]},{"type":"text","value":"-klassen. Kortet borde endast ha funktioner för att få reda på det tillfälliga saldot, lägga till pengar på kortet och subtrahera pengar från saldot. Fyll i metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"subtrahera_saldo(mangd)"}]},{"type":"text","value":" enligt kommentarerna i övningsfältet:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Lunchkort"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" saldo\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"tillsatt_pengar"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" mangd"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+="}]},{"type":"text","value":" mangd\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"subtrahera_saldo"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" mangd"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"pass"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Metoden ska endast kunna subtrahera från saldot"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# ifall det finns tillräckligt med pengar på kortet"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Lyckad betalning returnerar True, icke-lyckad False."}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Huvudtestprogram:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" __name__ "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"__main__\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n kort "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Lunchkort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Saldo\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n resultat "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"subtrahera_saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"8"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Betalningen lyckades:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" resultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Saldo\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n resultat "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"subtrahera_saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Betalningen lyckads:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" resultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Saldo\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Saldo 10\nBetalningen lyckades: True\nSaldo 2\nBetalningen lyckades: False\nSaldo 2"}]}]},{"type":"element","tagName":"h2","properties":{"id":"betalningsterminalen-och-hanterandet-av-kontantbetalning","style":"position:relative;"},"children":[{"type":"text","value":"Betalningsterminalen och hanterandet av kontantbetalning"},{"type":"element","tagName":"a","properties":{"href":"#betalningsterminalen-och-hanterandet-av-kontantbetalning","ariaLabel":"betalningsterminalen och hanterandet av kontantbetalning permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I studentkafeterian går det att betala med kontanter eller Lunchkort. En betalterminal används för att hantera både kontant- och korttransaktioner. Låt oss börja med kontanttransaktionerna."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Här har vi en ram för en "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Betalterminal"}]},{"type":"text","value":"-klass. Implementera metoderna enligt beskrivningen i kommentarerna:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Betalterminal"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# I kassan finns det ursprungligen 1000 euro i kontanter"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"pengar "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1000"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"formanliga "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"special "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"at_formanligt"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" betalning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# En formånlig lunch kostar 2.50 euro"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Öka värdet på pengarna som finns i terminalen med en förmånlig lunchs pris,"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# öka mängden förmånliga luncher och returnera rätt mängd växel."}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Ifall betalningen inte är tillräckligt stor säljs ingen lunch och hela summan returneras"}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"at_special"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" betalning"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# En special lunch kostar 4.30 euro"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Öka värdet på pengarna som finns i terminalen med en special lunchs pris,"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# öka mängden special luncher och returnera rätt mängd växel."}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Ifall betalningen inte är tillräckligt stor säljs ingen lunch och hela summan returneras"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Exempel på användning:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"exactum "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Betalterminal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nvaxel "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"at_formanligt"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Mängden växel\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" vaxel"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nvaxel "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"at_formanligt"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Mängden växel\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" vaxel"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nvaxel "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"at_special"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4.3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Mängden växel\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" vaxel"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Pengar i kassan\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"pengar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Förmånliga luncher sålda\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"formanliga"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Special luncher sålda\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"special"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Mängden växel 7.5\nMängden växel 2.5\nMängden växel 0.0\nPengar i kassan 1009.3\nFörmånliga luncher sålda 2\nSpecial luncher sålda 1"}]}]},{"type":"element","tagName":"h2","properties":{"id":"betalning-med-kort","style":"position:relative;"},"children":[{"type":"text","value":"Betalning med kort"},{"type":"element","tagName":"a","properties":{"href":"#betalning-med-kort","ariaLabel":"betalning med kort permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss nu implementera korttransaktioner. Vi kommer att behöva metoder som tar ett "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Lunchkort"}]},{"type":"text","value":" som argument och minskar saldot på kortet med lunchens pris. Nedan hittar du ramar av dessa funktioner. Vänligen fyll i metoderna enligt beskrivningen i kommentarerna:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Betalterminal"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# ..."}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"at_formanligt_kort"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" Lunchkort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# En förmånlig lunch kostar 2.50 euro."}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Om kortet har tillräckligt med pengar, subtrahera lunchens pris och returnera True."}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Annars returnera False"}]},{"type":"text","value":"\n\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"at_special_kort"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" Lunchkort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# En special lunch kostar 4.30 euro."}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Om kortet har tillräckligt med pengar, subtrahera lunchens pris och returnera True."}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Annars returnera False"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"OBS:"}]},{"type":"text","value":" betalningar med Lunchkort ändrar inte på mängden pengar i terminalen. Luncher säljes däremot fortfarande så länge pengarna på saldot räcker till, alltså kom ihåg att öka mängden luncher som sålts."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Följande kod kan du använda för att testa din klass:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"exactum "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Betalterminal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nvaxel "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"at_formanligt"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"10"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Mängden växel\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" vaxel"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nkort "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Lunchkort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"7"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nresultat "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"at_special_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Betalningen lyckades:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" resultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nresultat "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"at_special_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Betalningen lyckades:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" resultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nresultat "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"at_formanligt_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Betalningen lyckades:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" resultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Pengar i kassan\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"pengar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Förmånliga luncher sålda\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"formanliga"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"special luncher sålda\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"special"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Mängden växel 7.5\nBetalningen lyckades: True\nBetalningen lyckades: False\nBetalningen lyckades: True\nPengar i kassan 1002.5\nFörmånliga luncher sålda 2\nspecial luncher sålda 1"}]}]},{"type":"element","tagName":"h2","properties":{"id":"tillsattning-av-pengar-pa-kortet","style":"position:relative;"},"children":[{"type":"text","value":"Tillsättning av pengar på kortet"},{"type":"element","tagName":"a","properties":{"href":"#tillsattning-av-pengar-pa-kortet","ariaLabel":"tillsattning av pengar pa kortet permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Slutligen lägger vi till en metod som gör att du kan sätta in pengar på kortet. Kortägaren betalar detta kontant, så att den insatta summan läggs till de pengar som finns tillgängliga i terminalen. Här är en ram för metoden:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"tillsatt_pengar_kortet"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" Lunchkort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" summa"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"pass"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Du kan använda följande kod för att testa din metod:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"exactum "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Betalterminal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nantons_kort "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Lunchkort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\"Kortets saldo "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"antons_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" euro\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nresultat "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"at_special_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"antons_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Betalningen lyckades:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" resultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nexactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"tillsatt_pengar_kortet"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"antons_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"100"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\"Kortets saldo "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"antons_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" euro\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\nresultat "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"at_special_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"antons_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Betalningen lyckades:\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" resultat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\"Kortets saldo "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"antons_kort"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"saldo"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" euro\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Pengar i kassan\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"pengar"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Förmånliga luncher sålda\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"formanliga"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"special luncher sålda\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" exactum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"special"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Kortets saldo 2 euro\nBetalningen lyckades: False\nKortets saldo 102 euro\nBetalningen lyckades: True\nKortets saldo 97.7 euro\nPengar i kassan 1100\nFörmånliga luncher sålda 0\nspecial luncher sålda 1"}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"en-instans-av-samma-klass-som-argument-till-en-metod","style":"position:relative;"},"children":[{"type":"text","value":"En instans av samma klass som argument till en metod"},{"type":"element","tagName":"a","properties":{"href":"#en-instans-av-samma-klass-som-argument-till-en-metod","ariaLabel":"en instans av samma klass som argument till en metod permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Nedan har vi ytterligare en version av klassen "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Person"}]},{"type":"text","value":":"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Person"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" fodelsear"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" fodelsear"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Låt oss anta att vi vill skriva ett program som jämför åldern på objekt av typen Person. Vi kan skriva en separat funktion för detta ändamål:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"aldre_an"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"person1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" person2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" person1"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"<"}]},{"type":"text","value":" person2"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"True"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"False"}]},{"type":"text","value":"\n\nmuhammad "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Muhammad ibn Musa al-Khwarizmi\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"780"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\npascal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Blaise Pascal\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1623"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\ngrace "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Grace Hopper\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1906"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" aldre_an"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"muhammad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"muhammad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" är äldre än "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"muhammad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" är inte äldre än "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" aldre_an"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"grace"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"grace"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" är äldre än "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"grace"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" är inte äldre än "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Muhammad ibn Musa al-Khwarizmi är äldre än Blaise Pascal\nGrace Hopper är inte äldre än Blaise Pascal"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"En av principerna för objektorienterad programmering är att all funktionalitet som hanterar objekt av en viss typ ska inkluderas i klassdefinitionen, som metoder. I stället för en funktion kan vi alltså skriva en metod som gör det möjligt att jämföra åldern på ett Person-objekt med ett annat Person-objekt:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Person"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" fodelsear"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" fodelsear\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# OBS! Typledtrådar måste vara inom citationstecken ifall parametern är av samma typ som klassen självt!"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"aldre_an"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" annat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Person\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"<"}]},{"type":"text","value":" annat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"True"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"False"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Här kallas det objekt som metoden anropas på för "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":", medan det andra Person-objektet kallas för "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"annat"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Kom ihåg att anrop av en metod skiljer sig från anrop av en funktion. En metod är kopplad till ett objekt med punktnotationen:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"muhammad "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Muhammad ibn Musa al-Khwarizmi\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"780"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\npascal "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Blaise Pascal\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1623"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\ngrace "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Grace Hopper\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1906"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" muhammad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"aldre_an"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"muhammad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" är äldre än "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"muhammad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" är inte äldre än "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" grace"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"aldre_an"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"grace"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" är äldre än "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"else"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\""}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"grace"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":" är inte äldre än "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"pascal"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Till vänster om punkten finns själva objektet, som kallas "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"self"}]},{"type":"text","value":" i metoddefinitionen. Inom parentes står argumentet till metoden, vilket är det objekt som kallas "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"annat"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Utskriften från programmet är exakt densamma som med funktionsimplementeringen ovan."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Till sist, en ganska kosmetisk punkt: "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"if...else"}]},{"type":"text","value":"-strukturen i metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"aldre_an"}]},{"type":"text","value":" är i stort sett onödig. Värdet på det booleska uttrycket i villkoret är redan exakt samma sanningsvärde som returneras. Metoden kan alltså förenklas:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Person"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" namn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"str"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" fodelsear"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"namn "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" namn\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" fodelsear\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# OBS! Typledtrådar måste vara inom citationstecken ifall parametern är av samma typ som klassen självt!"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"aldre_an"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" annat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Person\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"<"}]},{"type":"text","value":" annat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Liksom det framkommer av kommentarerna i exemplen ovan, så måste typledtråden omslutas av citattecken ifall parametern i en metoddefinition är av samma typ som klassen själv. Om citattecknen utelämnas uppstår ett fel, vilket du kommer att se om du försöker med följande:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Person"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# ..."}]},{"type":"text","value":"\n\n "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Detta fungerar inte, Person måste vara innanför citationstecken"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"aldre_an"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" annat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" Person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"<"}]},{"type":"text","value":" annat"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"fodelsear"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Bostadsjämförelse","tmcname":"osa09-05_bostadsjamforelse"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Databasen hos en fastighetsmäklare innehåller register över tillgängliga fastigheter med objekt som definieras av följande klass:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Bostad"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" rum"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kvadratmeter"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" kvadratpris"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"rum "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" rum\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"kvadratmeter "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" kvadratmeter\n self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"kvadratpris "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" kvadratpris"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Din uppgift är att implementera metoder som gör det möjligt att jämföra tillgängliga egenskaper."}]},{"type":"element","tagName":"h2","properties":{"id":"ar-den-storre","style":"position:relative;"},"children":[{"type":"text","value":"Är den större?"},{"type":"element","tagName":"a","properties":{"href":"#ar-den-storre","ariaLabel":"ar den storre permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"storre(self, jamforelse)"}]},{"type":"text","value":", som returnerar "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"True"}]},{"type":"text","value":", ifall "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bostad"}]},{"type":"text","value":"-objektet är större än objektet det jämförs med."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Exempel på hur funktionen borde fungera:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"eira_etta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bostad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"16"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5500"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nberghall_tvaa "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bostad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"38"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4200"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\njakobacka_trea "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bostad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"78"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2500"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"eira_etta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"storre"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"berghall_tvaa"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"jakobacka_trea"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"storre"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"berghall_tvaa"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"False\nTrue"}]}]},{"type":"element","tagName":"h2","properties":{"id":"prisskillnad","style":"position:relative;"},"children":[{"type":"text","value":"Prisskillnad"},{"type":"element","tagName":"a","properties":{"href":"#prisskillnad","ariaLabel":"prisskillnad permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"prisskillnad(self, jamforelse)"}]},{"type":"text","value":", som returnerar skillnaden i pris mellan "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bostad"}]},{"type":"text","value":"-objektet självt och det som det jämförs med. Prisskillnaden är det absoluta värdet av skillnaden mellan de två fastigheternas totalpriser. Det totala priset för en fastighet är dess kvadratmeterpris multiplicerat med antalet kvadratmeter i fastigheten."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Exempel på hur funktionen borde fungera:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"eira_etta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bostad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"16"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5500"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nberghall_tvaa "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bostad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"38"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4200"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\njakobacka_trea "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bostad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"78"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2500"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"eira_etta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"prisskillnad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"berghall_tvaa"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"jakobacka_trea"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"prisskillnad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"berghall_tvaa"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"71600\n35400"}]}]},{"type":"element","tagName":"h2","properties":{"id":"dyrare","style":"position:relative;"},"children":[{"type":"text","value":"Dyrare?"},{"type":"element","tagName":"a","properties":{"href":"#dyrare","ariaLabel":"dyrare permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Skapa metoden "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"dyrare(self, jamforelse)"}]},{"type":"text","value":" som returnerar "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"True"}]},{"type":"text","value":", ifall "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Bostad"}]},{"type":"text","value":"-objektet är dyrare än objektet som det jämförs med."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Exempel på hur funktionen borde fungera:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"eira_etta "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bostad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"16"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"5500"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nberghall_tvaa "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bostad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"38"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"4200"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\njakobacka_trea "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" Bostad"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"3"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"78"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2500"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"eira_etta"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"dyrare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"berghall_tvaa"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"jakobacka_trea"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"dyrare"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"berghall_tvaa"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"False\nTrue"}]}]}]}]},"html":"

    Efter den här delen

      \n
    • Kommer du att kunna använda olika datastrukturer för att hantera objekt
    • \n
    • Vet du hur objekt kan bli passerade som argument
    • \n

    Varje värde i Python är ett objekt. Alla objekt som du skapar baserat på en klass som du själv har definierat fungerar exakt på samma sätt som alla \"vanliga\" Python-objekt. Objekt kan till exempel lagras i en lista:

    from datetime import date\n\nclass SlutfordKurs:\n\n    def __init__(self, kurs: str, studiepoang: int, slutforsdatum: date):\n        self.kurs = kurs\n        self.studiepoang = studiepoang\n        self.slutforsdatum = slutforsdatum\n\n\nif __name__ == \"__main__\":\n    # Vi skapar några slutförda kurser och lägger dessa i en lista\n    prestationer = []\n\n    mat1 = SlutfordKurs(\"Matematik 1\", 5, date(2020, 3, 11))\n    prg1 = SlutfordKurs(\"Programmering 1\", 6, date(2019, 12, 17))\n\n    prestationer.append(mat1)\n    prestationer.append(prg1)\n\n    # Vi lägger några till rakt till listan\n    prestationer.append(SlutfordKurs(\"Fysik 2\", 4, date(2019, 11, 10)))\n    prestationer.append(SlutfordKurs(\"Programmering 2\", 5, date(2020, 5, 19)))\n\n    # Vi går igenom alla slutförda kurser, skriver ut deras namn och räknar ihop den totala mängden studiepoäng\n    studiepoang = 0\n    for prestation in prestationer:\n        print(prestation.kurs)\n        studiepoang += prestation.studiepoang\n\n    print(\"Studiepoäng totalt:\", studiepoang)

    Matematik 1\nProgrammering 1\nFysik 2\nProgrammering 2\nStudiepoäng totalt: 20

    Uppgiftsbotten har en klass med namnet Bil som representerar en bil genom två attribut: marke (str) och topphastighet (int).

    Skapa funktionen snabbaste_bil(bilar: list), som får en lista av Bil-objekt som argument.

    Funktionen ska returnera märket på den snabbaste bilen. Du kan anta att det alltid kommer att finnas en enda bil med den högsta topphastigheten. Ändra inte listan som ges som argument, gör heller inte några ändringar i klassdefinitionen för Bil.

    Du kan använda följande kod för att testa din funktion:

    if __name__ == \"__main__\":\n    bil1 = Bil(\"Mersu\", 195)\n    bil2 = Bil(\"Lada\", 110)\n    bil3 = Bil(\"Ferrari\", 280)\n    bil4 = Bil(\"Trabant\", 85)\n\n    bilar = [bil1, bil2, bil3, bil4]\n    print(snabbaste_bil(bilar))

    Ferrari

    I uppgiftsbotten hittas klassen Provprestation, som, liksom namnet anger, tar modell av en provtagares prestation i ett prov. Den har två attribut, presterare (str) och poang (int).

    Skapa funktionen godkanda(prestationer: list, poanggrans: int), som får som parametrar en lista av provprestationer och ett heltal som representerar det minsta poängantalet för att bli godkänd.

    Funktionen ska skapa och returnera en ny lista, som innehåller endast de prov som kom över poänggränsen i den ursprungliga listan. Ändra inte listan som ges som argument, ändra heller inte definitionen för klassen Provprestation.

    Du kan använda följande kod för att testa funktionen:

    if __name__ == \"__main__\":\n    s1 = Provprestation(\"Peter\", 12)\n    s2 = Provprestation(\"Pernilla\", 19)\n    s3 = Provprestation(\"Per\", 15)\n    s4 = Provprestation(\"Pia\", 9)\n    s5 = Provprestation(\"Petra\", 17)\n\n    klarade = godkanda([s1, s2, s3, s4, s5], 15)\n    for godkand in klarade:\n        print(klarade)

    Provprestation (presterare: Pernilla, poang: 19)\nProvprestation (presterare: Per, poang: 15)\nProvprestation (presterare: Petra, poang: 17)

    Du kanske minns att listor inte innehåller några objekt i sig själva. De innehåller referenser till objekt. Exakt samma objekt kan förekomma flera gånger i en och samma lista, och det kan refereras till flera gånger i listan eller utanför den. Låt oss ta en titt på ett exempel:

    class Produkt:\n    def __init__(self, namn: int, enhet: str):\n        self.namn = namn\n        self.enhet = enhet\n\n\nif __name__ == \"__main__\":\n    affarslista = []\n    mjolk = Produkt(\"Mjölk\", \"liter\")\n\n    affarslista.append(mjolk)\n    affarslista.append(mjolk)\n    affarslista.append(Produkt(\"Gurka\", \"st\"))
    \n \n \n \n \n \n \"9\n \n \n

    Self eller inget self?

    Hittills har vi bara snuddat vid ytan när det gäller att använda parameternamnet self. Låt oss titta närmare på när det bör eller inte bör användas.

    Nedan har vi en enkel klass som låter oss skapa ett ordförråd-objekt som innehåller några ord:

    class Ordforrad:\n    def __init__(self):\n        self.ord = []\n\n    def tillsatt_ord(self, ord: str):\n        if not ord in self.ord:\n            self.ord.append(ord)\n\n    def utskrift(self):\n        for ord in sorted(self.ord):\n            print(ord)\n\nordforrad = Ordforrad()\nordforrad.tillsatt_ord(\"python\")\nordforrad.tillsatt_ord(\"objekt\")\nordforrad.tillsatt_ord(\"objekt-orienterad programmering\")\nordforrad.tillsatt_ord(\"objekt\")\nordforrad.tillsatt_ord(\"nörd\")\n\nordforrad.utskrift()

    nörd\nobjekt\nobjekt-orienterad programmering\npython

    Listan med ord lagras i ett attribut med namnet self.ord. I det här fallet är parameternamnet self obligatoriskt både i klassens konstruktormetod och i alla andra metoder som använder variabeln. Om self utelämnas kommer de olika metoderna inte att få tillgång till samma lista med ord.

    Låt oss lägga till en ny metod i vår klassdefinition. Metoden langsta_ord(self) returnerar (ett av) de längsta orden i ordförrådet.

    Följande är ett sätt att utföra denna uppgift, men vi kommer snart att se att det inte är ett särskilt bra sätt:

    class Ordforrad:\n    def __init__(self):\n        self.ord = []\n\n    # ...\n\n    def langsta_ord(self):\n        # vi definierar två hjälpvariabler\n        self.langsta = \"\"\n        self.langsta_langd = 0\n\n        for ord in self.ord:\n            if len(ord) > self.langsta_langd:\n                self.langsta_langd = len(ord)\n                self.langsta = ord\n\n        return self.langsta

    Den här metoden använder två hjälpvariabler som deklareras med parameternamnet self. Kom ihåg att namnen på variablerna inte spelar någon roll i funktionell mening, så dessa variabler kan också namnges mer förvirrande som till exempel hjalpare och hjalpare2. Koden börjar se lite kryptisk ut:

    class Ordforrad:\n    def __init__(self):\n        self.ord = []\n\n    # ...\n\n    def langsta_ord(self):\n        # vi definierar två hjälpvariabler\n        self.hjalpare = \"\"\n        self.hjalpare2 = 0\n\n        for ord in self.ord:\n            if len(ord) > self.hjalpare2:\n                self.hjalpare2 = len(ord)\n                self.hjalpare = ord\n\n        return self.hjalpare

    När en variabel deklareras med parameternamnet self blir den ett attribut till objektet. Detta innebär att variabeln kommer att existera så länge objektet existerar. Specifikt kommer variabeln att fortsätta existera även efter att metoden som deklarerar den har avslutat sin exekvering (engelska “Execution”). I exemplet ovan är detta helt onödigt, eftersom hjälpvariablerna endast är avsedda att användas inom metoden longest_word(self). Så att deklarera hjälpvariabler med parameternamnet self är inte en särskilt bra idé här.

    Förutom att variabler kan existera efter sitt \"utgångsdatum\" kan användning av self för att skapa nya attribut där de inte är nödvändiga orsaka svåra buggar i din kod. Särskilt generiskt namngivna attribut som self.hjalpare, som sedan används i flera olika metoder, kan orsaka oväntade beteenden som är svåra att spåra.

    Om t.ex. en hjälpvariabel deklareras som ett attribut och tilldelas ett ursprungligt värde i konstruktorn, men variabeln sedan används i ett orelaterat sammanhang i en annan metod, blir resultatet ofta oförutsägbart:

    class Ordforrad:\n    def __init__(self):\n        self.ord = []\n        # vi definierar hjälparvariabler\n        self.hjalpare = \"\"\n        self.hjalpare2 = \"\"\n        self.hjalpare3 = \"\"\n        self.hjalpare4 = \"\"\n\n    # ...\n\n    def langsta_ord(self):\n        for ord in self.ord:\n            # detta fungerar inte eftersom hjalpare2 har fel typ\n            if len(ord) > self.hjalpare2:\n                self.hjalpare2 = len(ord)\n                self.hjalpare = ord\n\n        return self.hjalpare

    Man skulle kunna tro att detta skulle lösas genom att bara deklarera attributen där de används, utanför konstruktorn, men detta resulterar i en situation där de attribut som är tillgängliga via ett objekt är beroende av vilka metoder som har utförts. I föregående del såg vi att fördelen med att deklarera attribut i konstruktorn är att alla instanser av klassen då kommer att ha exakt samma attribut. Om så inte är fallet kan det lätt leda till fel om man använder olika instanser av klassen.

    Sammanfattningsvis, om du behöver hjälpvariabler för användning inom en enda metod, är det korrekta sättet att göra det utan self. För att göra din kod lättare att förstå, använd också informativa variabelnamn:

    class Ordforrad:\n    def __init__(self):\n        self.ord = []\n\n    # ...\n\n    def langsta_ord(self):\n        # detta är det korrekta sättet att definiera\n        # hjälpvariabler för användning i en enda metod\n        langsta = \"\"\n        langsta_langd = 0\n\n        for ord in self.ord:\n            if len(ord) > langsta_langd:\n                langsta_langd = len(ord)\n                langsta = ord\n\n        return langsta

    I implementeringen ovan är hjälpvariablerna endast tillgängliga när metoden utförs. De värden som lagras i dem kan inte orsaka komplikationer i andra delar av programmet.

    Objekt som argument till funktioner

    De objekt som skapas baserat på våra egna klasser är vanligtvis mutabla. Du kanske kommer ihåg att till exempel Python-listor är föränderliga: när de passeras som argument till funktioner kan deras innehåll ändras som ett resultat av exekveringen.

    Låt oss titta på ett enkelt exempel där en funktion får en referens till ett objekt av typen Studerande som sitt argument. Funktionen ändrar sedan namnet på studenten. Både funktionen och huvudfunktionen som anropar den har åtkomst till samma objekt, så ändringen syns även i huvudfunktionen.

    class Studerande:\n    def __init__(self, namn: str, studerandenummer: str):\n        self.namn = namn\n        self.studerandenummer = studerandenummer\n\n    def __str__(self):\n        return f\"{self.namn} ({self.studerandenummer})\"\n\n# observera att typledtråden använder namnet på klassen definierad ovan\ndef andra_namn(studerande: Studerande):\n    studerande.namn = \"Olle Studerande\"\n\n# skapa ett Studerande-objekt\nolle = Studerande(\"Olle Elev\", \"12345\")\n\nprint(olle)\nandra_namn(olle)\nprint(olle)

    Olle Elev (12345)\nOlle Studerande (12345)

    Det är också möjligt att skapa objekt inom funktioner. Om en funktion returnerar en referens till det nyskapade objektet är det också åtkomligt inom huvudfunktionen:

    from random import randint, choice\n\nclass Studerande:\n    def __init__(self, namn: str, studerandenummer: str):\n        self.namn = namn\n        self.studerandenummer = studerandenummer\n\n    def __str__(self):\n        return f\"{self.namn} ({self.studerandenummer})\"\n\n\n# Denna funktion skapar och returnerar ett nytt Studerande-objekt.\n# Den väljer slumpmässigt värden för namnet och studerandenumret.\ndef ny_studerande():\n    fornamn = [\"Atte\",\"Peter\",\"Minna\",\"Maria\"]\n    efternamn = [\"Virtanen\", \"Lahtinen\", \"Leinonen\", \"Pythonson\"]\n\n    # Slumpmässigt namn\n    namn = choice(fornamn) + \" \" + choice(efternamn)\n\n    # Slumpmässigt studerandenummer\n    studerandenummer = str(randint(10000,99999))\n\n    # Skapa och returnera ett Studerande-objekt\n    return Studerande(namn, studerandenummer)\n\nif __name__ == \"__main__\":\n    # Kalla funktionen fem gånger och spara resultatet i en lista\n    studeranden = []\n    for i in range(5):\n        studeranden.append(ny_studerande())\n\n    # Skriv ut resultatet\n    for studerande in studeranden:\n        print(studerande)

    Om du kör ovanstående kan det resultera i följande utskrift (OBS: eftersom slumpen är inblandad kommer resultaten sannolikt att bli annorlunda om du testar koden själv).

    Maria Lahtinen (36213)\nAtte Virtanen (11859)\nMaria Pythonen (77330)\nAtte Pythonson (86451)\nMinna Pythonson (86211)

    Objekt som argument till metoder

    På liknande sätt kan objekt fungera som argument till metoder. Låt oss ta en titt på ett exempel från en nöjespark:

    class Person:\n    def __init__(self, namn: str, langd: int):\n        self.namn = namn\n        self.langd = langd\n\nclass Akattraktion:\n    def __init__(self, namn: str, langdgrans: int):\n        self.besokare = 0\n        self.namn = namn\n        self.langdgrans = langdgrans\n\n    def ta_ombord(self, person: Person):\n        if person.langd >= self.langdgrans:\n            self.besokare += 1\n            print(f\"{person.namn} kom ombord\")\n        else:\n            print(f\"{person.namn} var för kort :(\")\n\n    def __str__(self):\n        return f\"{self.namn} ({self.besokare} besökare)\"

    Attraktionen innehåller en metod motta_besökare, som tar ett objekt av typen Person som argument. Om besökaren är tillräckligt lång släpps denne ombord och antalet besökare ökas. Klasserna kan testas på följande sätt:

    berg_och_dalbana = Akattraktion(\"Berg_och_dalbana\", 120)\njakob = Person(\"Jakob\", 172)\nvilma = Person(\"Vilma\", 105)\n\nberg_och_dalbana.ta_ombord(jakob)\nberg_och_dalbana.ta_ombord(vilma)\n\nprint(berg_och_dalbana)

    Jakob kom ombord\nVenla var för kort :(\nBerg_och_dalbana (1 besökare)

    I uppgiftsbotten finns färdigt redan en klass Person såväl som en ram för klassen BebisCenter. Ett BebisCenter-objekt utför olika handlingar såsom mäter eller matar personer. I denna uppgift implementerar du resten av BebisCenter-klassen. Koden för klassen Person ska inte ändras överhuvudtaget!

    Vägning av person

    I BebisCenter-klassens definitione finns en ram för funktionen vagning

    class BebisCenter:\n    def vagning(self, person: Person):\n        # returnera vikten av personen som passerades som argument\n        return -1

    Metoden tar ett Person-objekt som sitt argument. Den ska returnera personens vikt. Du kan komma åt en persons vikt genom attributet som definieras i Person-klassen. Vänligen fyll i resten av implementationen för metoden vagning.

    Nedan finns ett exempel på en huvudfunktion där ett BebisCenter väger två olika Person-objekt:

    haga_barnvard = BebisCenter()\n\nerik = Person(\"Erik\", 1, 110, 7)\npeter = Person(\"Peter\", 33, 176, 85)\n\nprint(f\"{erik.namn} väger {haga_barnvard.vagning(erik)} kg\")\nprint(f\"{peter.namn} väger {haga_barnvard.vagning(peter)} kg\")

    Erik väger 7 kg\nPeter väger 85 kg

    Matning

    Det är möjligt att ändra tillståndet för ett objekt som skickas som ett argument. Implementera metoden mata(person: Person) som ökar vikten på den person som skickas som argument med ett.

    I följande exempel vägs två personer, och sedan matas en av dem tre gånger. Därefter vägs personerna igen:

    haga_barnvard = BabyCenter()\n\nerik = Person(\"Erik\", 1, 110, 7)\npeter = Person(\"Peter\", 33, 176, 85)\n\nprint(f\"{erik.namn} väger {haga_barnvard.vagning(erik)} kg\")\nprint(f\"{peter.namn} väger {haga_barnvard.vagning(peter)} kg\")\nprint()\n\nhaga_barnvard.mata(erik)\nhaga_barnvard.mata(erik)\nhaga_barnvard.mata(erik)\n\nprint(f\"{erik.namn} väger {haga_barnvard.vagning(erik)} kg\")\nprint(f\"{peter.namn} väger {haga_barnvard.vagning(peter)} kg\")

    Utskriften borde visa att Eriks vikt har stigit med tre:

    Erik väger 7 kg\nPeter väger 85 kg

    Erik väger 10 kg\nPeter väger 85 kg

    Räknande av vägningar

    Implementera metoden vagningar() som returnerar det totala antalet vägningar som ett BabyCenter-objekt har utfört. OBS: Du kommer att behöva ett nytt attribut för att hålla reda på antalet vägningar. Du kan använda följande kod för att testa din metod:

    haga_barnvard = BabyCenter()\n\nerik = Person(\"Erik\", 1, 110, 7)\npeter = Person(\"Peter\", 33, 176, 85)\n\nprint(f\"Vägningar utförda {haga_barnvard.vagningar()}\")\n\nhaga_barnvard.vagning(erik)\nhaga_barnvard.vagning(erik)\n\nprint(f\"Vägningar utförda {haga_barnvard.vagningar()}\")\n\nhaga_barnvard.vagning(erik)\nhaga_barnvard.vagning(erik)\nhaga_barnvard.vagning(erik)\nhaga_barnvard.vagning(erik)\n\nprint(f\"Vägningar utförda {haga_barnvard.vagningar()}\")

    Vägningar utförda 0\nVägningar utförda 2\nVägningar utförda 6

    I föregående del fanns en övning där du implementerade klassen Lunchkort. Kortet hade separata metoder för att äta en vanlig och en speciell lunch, samt en metod för att sätta in pengar på kortet.

    Klassen Lunchkort, så som du ombads implementera den, har dock vissa problem. Kortet självt hade kunskap om priserna på de olika lunchalternativen och visste att subtrahera rätt mängd pengar från saldot baserat på dessa. Men tänk dig att priserna ändrades eller att nya varor infördes i systemet, men att flera kort redan var registrerade i systemet. Detta skulle innebära att alla befintliga kort skulle behöva ersättas med versioner med kunskap om de nya priserna.

    En bättre lösning skulle vara att göra korten ”dumma”, okunniga om priserna på olika produkter. Syftet med kortet skulle vara att helt enkelt hålla reda på det tillgängliga saldot. Alla mer komplicerade funktioner bör rymmas inom en annan klass: betalterminalen.

    Ett simplare Lunchkort

    Vi förverkligar först en dummare version av Lunchkort-klassen. Kortet borde endast ha funktioner för att få reda på det tillfälliga saldot, lägga till pengar på kortet och subtrahera pengar från saldot. Fyll i metoden subtrahera_saldo(mangd) enligt kommentarerna i övningsfältet:

    class Lunchkort:\n    def __init__(self, saldo: float):\n        self.saldo = saldo\n\n    def tillsatt_pengar(self, mangd: float):\n        self.saldo += mangd\n\n    def subtrahera_saldo(self, mangd: float):\n        pass\n        # Metoden ska endast kunna subtrahera från saldot\n        # ifall det finns tillräckligt med pengar på kortet\n        # Lyckad betalning returnerar True, icke-lyckad False.

    Huvudtestprogram:

    if __name__ == \"__main__\":\n    kort = Lunchkort(10)\n    print(\"Saldo\", kort.saldo)\n    resultat = kort.subtrahera_saldo(8)\n    print(\"Betalningen lyckades:\", resultat)\n    print(\"Saldo\", kort.saldo)\n    resultat = kort.subtrahera_saldo(4)\n    print(\"Betalningen lyckads:\", resultat)\n    print(\"Saldo\", kort.saldo)

    Saldo 10\nBetalningen lyckades: True\nSaldo 2\nBetalningen lyckades: False\nSaldo 2

    Betalningsterminalen och hanterandet av kontantbetalning

    I studentkafeterian går det att betala med kontanter eller Lunchkort. En betalterminal används för att hantera både kontant- och korttransaktioner. Låt oss börja med kontanttransaktionerna.

    Här har vi en ram för en Betalterminal-klass. Implementera metoderna enligt beskrivningen i kommentarerna:

    class Betalterminal:\n    def __init__(self):\n        # I kassan finns det ursprungligen 1000 euro i kontanter\n        self.pengar = 1000\n        self.formanliga = 0\n        self.special = 0\n\n    def at_formanligt(self, betalning: float):\n        # En formånlig lunch kostar 2.50 euro\n        # Öka värdet på pengarna som finns i terminalen med en förmånlig lunchs pris,\n        # öka mängden förmånliga luncher och returnera rätt mängd växel.\n        # Ifall betalningen inte är tillräckligt stor säljs ingen lunch och hela summan returneras\n\n    def at_special(self, betalning: float):\n        # En special lunch kostar 4.30 euro\n        # Öka värdet på pengarna som finns i terminalen med en special lunchs pris,\n        # öka mängden special luncher och returnera rätt mängd växel.\n        # Ifall betalningen inte är tillräckligt stor säljs ingen lunch och hela summan returneras

    Exempel på användning:

    exactum = Betalterminal()\n\nvaxel = exactum.at_formanligt(10)\nprint(\"Mängden växel\", vaxel)\n\nvaxel = exactum.at_formanligt(5)\nprint(\"Mängden växel\", vaxel)\n\nvaxel = exactum.at_special(4.3)\nprint(\"Mängden växel\", vaxel)\n\nprint(\"Pengar i kassan\", exactum.pengar)\nprint(\"Förmånliga luncher sålda\", exactum.formanliga)\nprint(\"Special luncher sålda\", exactum.special)

    Mängden växel 7.5\nMängden växel 2.5\nMängden växel 0.0\nPengar i kassan 1009.3\nFörmånliga luncher sålda 2\nSpecial luncher sålda 1

    Betalning med kort

    Låt oss nu implementera korttransaktioner. Vi kommer att behöva metoder som tar ett Lunchkort som argument och minskar saldot på kortet med lunchens pris. Nedan hittar du ramar av dessa funktioner. Vänligen fyll i metoderna enligt beskrivningen i kommentarerna:

    class Betalterminal:\n    # ...\n\n    def at_formanligt_kort(self, kort: Lunchkort):\n        # En förmånlig lunch kostar 2.50 euro.\n        # Om kortet har tillräckligt med pengar, subtrahera lunchens pris och returnera True.\n        # Annars returnera False\n\n\n    def at_special_kort(self, kort: Lunchkort):\n        # En special lunch kostar 4.30 euro.\n        # Om kortet har tillräckligt med pengar, subtrahera lunchens pris och returnera True.\n        # Annars returnera False

    OBS: betalningar med Lunchkort ändrar inte på mängden pengar i terminalen. Luncher säljes däremot fortfarande så länge pengarna på saldot räcker till, alltså kom ihåg att öka mängden luncher som sålts.

    Följande kod kan du använda för att testa din klass:

    exactum = Betalterminal()\n\nvaxel = exactum.at_formanligt(10)\nprint(\"Mängden växel\", vaxel)\n\nkort = Lunchkort(7)\n\nresultat = exactum.at_special_kort(kort)\nprint(\"Betalningen lyckades:\", resultat)\nresultat = exactum.at_special_kort(kort)\nprint(\"Betalningen lyckades:\", resultat)\nresultat = exactum.at_formanligt_kort(kort)\nprint(\"Betalningen lyckades:\", resultat)\n\nprint(\"Pengar i kassan\", exactum.pengar)\nprint(\"Förmånliga luncher sålda\", exactum.formanliga)\nprint(\"special luncher sålda\", exactum.special)

    Mängden växel 7.5\nBetalningen lyckades: True\nBetalningen lyckades: False\nBetalningen lyckades: True\nPengar i kassan 1002.5\nFörmånliga luncher sålda 2\nspecial luncher sålda 1

    Tillsättning av pengar på kortet

    Slutligen lägger vi till en metod som gör att du kan sätta in pengar på kortet. Kortägaren betalar detta kontant, så att den insatta summan läggs till de pengar som finns tillgängliga i terminalen. Här är en ram för metoden:

    def tillsatt_pengar_kortet(self, kort: Lunchkort, summa: float):\n    pass

    Du kan använda följande kod för att testa din metod:

    exactum = Betalterminal()\n\nantons_kort = Lunchkort(2)\nprint(f\"Kortets saldo {antons_kort.saldo} euro\")\n\nresultat = exactum.at_special_kort(antons_kort)\nprint(\"Betalningen lyckades:\", resultat)\n\nexactum.tillsatt_pengar_kortet(antons_kort, 100)\nprint(f\"Kortets saldo {antons_kort.saldo} euro\")\n\nresultat = exactum.at_special_kort(antons_kort)\nprint(\"Betalningen lyckades:\", resultat)\nprint(f\"Kortets saldo {antons_kort.saldo} euro\")\n\nprint(\"Pengar i kassan\", exactum.pengar)\nprint(\"Förmånliga luncher sålda\", exactum.formanliga)\nprint(\"special luncher sålda\", exactum.special)

    Kortets saldo 2 euro\nBetalningen lyckades: False\nKortets saldo 102 euro\nBetalningen lyckades: True\nKortets saldo 97.7 euro\nPengar i kassan 1100\nFörmånliga luncher sålda 0\nspecial luncher sålda 1

    En instans av samma klass som argument till en metod

    Nedan har vi ytterligare en version av klassen Person:

    class Person:\n    def __init__(self, namn: str, fodelsear: int):\n        self.namn = namn\n        self.fodelsear = fodelsear

    Låt oss anta att vi vill skriva ett program som jämför åldern på objekt av typen Person. Vi kan skriva en separat funktion för detta ändamål:

    def aldre_an(person1: Person, person2: Person):\n    if person1.fodelsear < person2.fodelsear:\n        return True\n    else:\n        return False\n\nmuhammad = Person(\"Muhammad ibn Musa al-Khwarizmi\", 780)\npascal = Person(\"Blaise Pascal\", 1623)\ngrace = Person(\"Grace Hopper\", 1906)\n\nif aldre_an(muhammad, pascal):\n    print(f\"{muhammad} är äldre än {pascal}\")\nelse:\n    print(f\"{muhammad} är inte äldre än {pascal}\")\n\nif aldre_an(grace, pascal):\n    print(f\"{grace} är äldre än {pascal}\")\nelse:\n    print(f\"{grace} är inte äldre än {pascal}\")

    Muhammad ibn Musa al-Khwarizmi är äldre än Blaise Pascal\nGrace Hopper är inte äldre än Blaise Pascal

    En av principerna för objektorienterad programmering är att all funktionalitet som hanterar objekt av en viss typ ska inkluderas i klassdefinitionen, som metoder. I stället för en funktion kan vi alltså skriva en metod som gör det möjligt att jämföra åldern på ett Person-objekt med ett annat Person-objekt:

    class Person:\n    def __init__(self, namn: str, fodelsear: int):\n        self.namn = namn\n        self.fodelsear = fodelsear\n\n    # OBS! Typledtrådar måste vara inom citationstecken ifall parametern är av samma typ som klassen självt!\n    def aldre_an(self, annat: \"Person\"):\n        if self.fodelsear < annat.fodelsear:\n            return True\n        else:\n            return False

    Här kallas det objekt som metoden anropas på för self, medan det andra Person-objektet kallas för annat.

    Kom ihåg att anrop av en metod skiljer sig från anrop av en funktion. En metod är kopplad till ett objekt med punktnotationen:

    muhammad = Person(\"Muhammad ibn Musa al-Khwarizmi\", 780)\npascal = Person(\"Blaise Pascal\", 1623)\ngrace = Person(\"Grace Hopper\", 1906)\n\nif muhammad.aldre_an(pascal):\n    print(f\"{muhammad.namn} är äldre än {pascal.namn}\")\nelse:\n    print(f\"{muhammad.namn} är inte äldre än {pascal.namn}\")\n\nif grace.aldre_an(pascal):\n    print(f\"{grace.namn} är äldre än {pascal.namn}\")\nelse:\n    print(f\"{grace.namn} är inte äldre än {pascal.namn}\")

    Till vänster om punkten finns själva objektet, som kallas self i metoddefinitionen. Inom parentes står argumentet till metoden, vilket är det objekt som kallas annat.

    Utskriften från programmet är exakt densamma som med funktionsimplementeringen ovan.

    Till sist, en ganska kosmetisk punkt: if...else-strukturen i metoden aldre_an är i stort sett onödig. Värdet på det booleska uttrycket i villkoret är redan exakt samma sanningsvärde som returneras. Metoden kan alltså förenklas:

    class Person:\n    def __init__(self, namn: str, fodelsear: int):\n        self.namn = namn\n        self.fodelsear = fodelsear\n\n    # OBS! Typledtrådar måste vara inom citationstecken ifall parametern är av samma typ som klassen självt!\n    def aldre_an(self, annat: \"Person\"):\n        return self.fodelsear < annat.fodelsear:

    Liksom det framkommer av kommentarerna i exemplen ovan, så måste typledtråden omslutas av citattecken ifall parametern i en metoddefinition är av samma typ som klassen själv. Om citattecknen utelämnas uppstår ett fel, vilket du kommer att se om du försöker med följande:

    class Person:\n    # ...\n\n    # Detta fungerar inte, Person måste vara innanför citationstecken\n    def aldre_an(self, annat: Person):\n        return self.fodelsear < annat.fodelsear:

    Databasen hos en fastighetsmäklare innehåller register över tillgängliga fastigheter med objekt som definieras av följande klass:

    class Bostad:\n    def __init__(self, rum: int, kvadratmeter: int, kvadratpris: int):\n        self.rum = rum\n        self.kvadratmeter = kvadratmeter\n        self.kvadratpris = kvadratpris

    Din uppgift är att implementera metoder som gör det möjligt att jämföra tillgängliga egenskaper.

    Är den större?

    Skapa metoden storre(self, jamforelse), som returnerar True, ifall Bostad-objektet är större än objektet det jämförs med.

    Exempel på hur funktionen borde fungera:

    eira_etta = Bostad(1, 16, 5500)\nberghall_tvaa = Bostad(2, 38, 4200)\njakobacka_trea = Bostad(3, 78, 2500)\n\nprint(eira_etta.storre(berghall_tvaa))\nprint(jakobacka_trea.storre(berghall_tvaa))

    False\nTrue

    Prisskillnad

    Skapa metoden prisskillnad(self, jamforelse), som returnerar skillnaden i pris mellan Bostad-objektet självt och det som det jämförs med. Prisskillnaden är det absoluta värdet av skillnaden mellan de två fastigheternas totalpriser. Det totala priset för en fastighet är dess kvadratmeterpris multiplicerat med antalet kvadratmeter i fastigheten.

    Exempel på hur funktionen borde fungera:

    eira_etta = Bostad(1, 16, 5500)\nberghall_tvaa = Bostad(2, 38, 4200)\njakobacka_trea = Bostad(3, 78, 2500)\n\nprint(eira_etta.prisskillnad(berghall_tvaa))\nprint(jakobacka_trea.prisskillnad(berghall_tvaa))

    71600\n35400

    Dyrare?

    Skapa metoden dyrare(self, jamforelse) som returnerar True, ifall Bostad-objektet är dyrare än objektet som det jämförs med.

    Exempel på hur funktionen borde fungera:

    eira_etta = Bostad(1, 16, 5500)\nberghall_tvaa = Bostad(2, 38, 4200)\njakobacka_trea = Bostad(3, 78, 2500)\n\nprint(eira_etta.dyrare(berghall_tvaa))\nprint(jakobacka_trea.dyrare(berghall_tvaa))

    False\nTrue

    ","frontmatter":{"path":"/osa-9/1-objekt-och-referenser","title":"Objekt och referenser"},"fileAbsolutePath":"/home/runner/work/ohjelmointi-24-sv/ohjelmointi-24-sv/data/osa-9/1-objekt-och-referenser.md"},"allPages":{"edges":[{"node":{"id":"b5e8ae41-d492-55f7-88a7-1c7292333ab1","frontmatter":{"path":"/arvostelu-ja-kokeet","title":"Arvostelu ja kokeet"}}},{"node":{"id":"af4df6be-211d-5ba1-acea-9edbefa06c49","frontmatter":{"path":"/frontmatter-guide","title":"Frontmatter-guide"}}},{"node":{"id":"56769133-4836-5fbb-a857-8fb0c6803e6d","frontmatter":{"path":"/","title":"Tietoa kurssista"}}},{"node":{"id":"e86762f0-c2a9-5598-aba3-2b8d7db7807c","frontmatter":{"path":"/kaikki-tehtavat","title":"Kaikki tehtävät"}}},{"node":{"id":"5d065309-85e8-5823-9527-ec1c3cf38d4d","frontmatter":{"path":"/tuki","title":"Tukea tehtäviin"}}},{"node":{"id":"ac195ee0-ad04-5cc9-9643-963f93d29ad2","frontmatter":{"path":"/usein-kysytyt-kysymykset","title":"Usein kysytyt kysymykset"}}},{"node":{"id":"51a165d7-8ce5-5d53-9c15-5321b6adef8c","frontmatter":{"path":"/verkkotentti","title":"Verkkotentti 4.6."}}},{"node":{"id":"4d9cf293-01e9-5e6c-a88f-599560e33c9a","frontmatter":{"path":"/verkkotentti-ohja","title":"Ohjelmoinnin jatkokurssin verkkotentti 16.12."}}},{"node":{"id":"279e1cca-fb0b-5d3f-b527-be05243d138d","frontmatter":{"path":"/verkkotentti-ohpe","title":"Ohjelmoinnin perusteiden verkkotentti 09.03."}}},{"node":{"id":"347bdde4-ba21-5f22-8a88-0287dfe29a45","frontmatter":{"path":"/virheilmoitukset","title":"Yleiset virheilmoitukset"}}},{"node":{"id":"3bf12e3a-1542-57f4-812d-dd32cebc99e2","frontmatter":{"path":"/sanasto","title":"Sanasto"}}},{"node":{"id":"9910673b-d62d-5d8d-a756-5267160d891f","frontmatter":{"path":"/osa-1/1-introduktion","title":"Introduktion"}}},{"node":{"id":"0b17a28e-f939-57cc-aa5b-4db407cdf34a","frontmatter":{"path":"/osa-1/2-info-fran-anvandaren","title":"Information från användaren"}}},{"node":{"id":"b95794f2-f3b3-597c-a4ec-6f023b584f81","frontmatter":{"path":"/osa-1/3-mer-om-variabler","title":"Mer om variabler"}}},{"node":{"id":"02cd0849-e7a5-5fd1-bf66-35f0197d3e75","frontmatter":{"path":"/osa-1/4-rakneoperationer","title":"Räkneoperationer"}}},{"node":{"id":"42690a69-3997-5b84-b999-15d9c3212884","frontmatter":{"path":"/osa-1/5-villkorssatser","title":"If-satser"}}},{"node":{"id":"96a0ec65-c0a3-5150-95c5-48c260f88162","frontmatter":{"path":"/osa-1","title":"Modul 1"}}},{"node":{"id":"e7a4d0c8-b8c1-53fa-ab51-9cc06fd417a3","frontmatter":{"path":"/osa-10/1-klasshierarkier","title":"Klasshierarkier"}}},{"node":{"id":"5f6d4b8b-7d05-5c79-9f2f-9e30b397167b","frontmatter":{"path":"/osa-10/2-atkamstmodifierare","title":"Åtkomstmodifierare"}}},{"node":{"id":"bb896c90-aabc-5a9d-8d4b-50839da286db","frontmatter":{"path":"/osa-10/3-objektorienterade-programmeringstekniker","title":"Objektorienterade programmeringstekniker"}}},{"node":{"id":"a2dca4f1-d64d-5e77-a3ca-8b2a208e9afa","frontmatter":{"path":"/osa-10/4-storre-applikation","title":"Att utveckla en större applikation"}}},{"node":{"id":"8c9cf5a7-f02e-5ccf-ab8f-f078c3ccecb6","frontmatter":{"path":"/osa-10","title":"Modul 10"}}},{"node":{"id":"f6688d26-5502-5c17-a8ee-db66f650f1f1","frontmatter":{"path":"/osa-11/1-list-comprehension","title":"List comprehension"}}},{"node":{"id":"1eac8489-72f2-5d53-904b-c960e2622018","frontmatter":{"path":"/osa-11/2-mer-om-comprehensions","title":"Mer om comprehensions"}}},{"node":{"id":"09630fca-7768-53f3-8aca-6e5ac638fc68","frontmatter":{"path":"/osa-11/3-rekursion","title":"Rekursion"}}},{"node":{"id":"70f6008e-a762-574c-a92a-c5c585d9677e","frontmatter":{"path":"/osa-11/4-lisaa-esimerkkeja","title":"Fler exempel på rekursion"}}},{"node":{"id":"eb8ed7d7-c39d-52db-949d-f75649498c67","frontmatter":{"path":"/osa-11","title":"Modul 11"}}},{"node":{"id":"9bba31dc-e14c-5400-a25b-7339107e9ba7","frontmatter":{"path":"/osa-12/1-funktioner-som-argument","title":"Funktioner som argument"}}},{"node":{"id":"5b9e4584-7234-5216-a118-d2a1bc617e13","frontmatter":{"path":"/osa-12/2-generatorer","title":"Generatorer"}}},{"node":{"id":"1d27636e-74f4-5c30-a1d8-08a303684945","frontmatter":{"path":"/osa-12/3-funktionell-programmering","title":"Funktionell programmering"}}},{"node":{"id":"6785750f-f145-5b88-81e9-b52e36ba53c6","frontmatter":{"path":"/osa-12/4-reguljara-uttryck","title":"Reguljära uttryck"}}},{"node":{"id":"d21df33a-4bf4-5ee3-9e2a-431d57561f09","frontmatter":{"path":"/osa-12","title":"Modul 12"}}},{"node":{"id":"14e3c129-50ec-581f-8679-8132248d41c1","frontmatter":{"path":"/osa-13/1-pygame","title":"Pygame"}}},{"node":{"id":"01bc3b9b-4f80-5561-8b56-3a7f09082263","frontmatter":{"path":"/osa-13/2-animation","title":"Animation"}}},{"node":{"id":"dd68786f-e2fc-5957-b47a-52b74c5199ef","frontmatter":{"path":"/osa-13/3-handelser","title":"Händelser"}}},{"node":{"id":"4a1aaa41-d6f7-51cd-8b89-95842cb9e02d","frontmatter":{"path":"/osa-13/4-fler-pygame-tekniker","title":"Fler pygame-tekniker"}}},{"node":{"id":"cdcf0ce1-e881-5ca6-8fa9-d0d343ec4e15","frontmatter":{"path":"/osa-13","title":"Modul 13"}}},{"node":{"id":"0ab28435-7654-5a8e-88d6-daa17d78103b","frontmatter":{"path":"/osa-14/1-spelprojekt","title":"Spelprojekt"}}},{"node":{"id":"b7a0628c-e4ba-583e-a52a-dd0ad78028d8","frontmatter":{"path":"/osa-14/2-robot-och-ladar","title":"Robot och lådor"}}},{"node":{"id":"6ccdbdff-7539-5a23-b23c-2ad48a99386f","frontmatter":{"path":"/osa-14/3-fardigstallande-av-spelet","title":"Färdigställande av spelet"}}},{"node":{"id":"1b505c9f-9b1b-58bd-8df7-553fef49cc8d","frontmatter":{"path":"/osa-14/4-ditt-eget-sepl","title":"Ditt eget spel"}}},{"node":{"id":"55c54859-8c7f-5fd9-8a8d-2c54ee677577","frontmatter":{"path":"/osa-14","title":"Modul 14"}}},{"node":{"id":"b5c346d1-d175-5824-98bb-4a4c3b45204d","frontmatter":{"path":"/osa-2/1-terminologi","title":"Programmeringsterminologi"}}},{"node":{"id":"db7188b0-0253-5c30-b8d2-0e115e235fb3","frontmatter":{"path":"/osa-2/2-else-elif","title":"Mera om if-satser"}}},{"node":{"id":"49d15928-f8b9-5883-9f29-86c307f6929e","frontmatter":{"path":"/osa-2/3-kombinera-villkor","title":"Kombinera villkor"}}},{"node":{"id":"93f1f9c8-6b27-5892-8bd4-7d1d008bf07a","frontmatter":{"path":"/osa-2/4-loopar","title":"Enkla loopar"}}},{"node":{"id":"5523b5b8-61f8-506d-bfe0-c6cc774390ce","frontmatter":{"path":"/osa-2","title":"Modul 2"}}},{"node":{"id":"02012307-c2a6-5cf2-9105-c10933c14b37","frontmatter":{"path":"/osa-3/1-loopar-med-villkor","title":"Loopar med villkor"}}},{"node":{"id":"efb889f4-4a19-515e-a0f6-4297d76a2757","frontmatter":{"path":"/osa-3/2-behandla-strangar","title":"Behandla strängar"}}},{"node":{"id":"a602077d-bbae-5eb7-a354-cc44b29ae96a","frontmatter":{"path":"/osa-3/3-mer-om-loopar","title":"Mera om loopar"}}},{"node":{"id":"6d878692-b9c7-57e6-ae58-044e5a6bef6f","frontmatter":{"path":"/osa-3/4-definiera-funktioner","title":"Definiera funktioner"}}},{"node":{"id":"682b5a18-73c5-56e2-8374-237baccbab40","frontmatter":{"path":"/osa-3","title":"Modul 3"}}},{"node":{"id":"3de95518-6b44-54db-9bcd-0c90a41d2fd5","frontmatter":{"path":"/osa-4/1-vscode","title":"Editorn Visual Studio Code, Pythontolken och det inbyggda debuggningsverktyget"}}},{"node":{"id":"7de9921c-7f94-58fe-84b9-7676dddb3b94","frontmatter":{"path":"/osa-4/2-mer-om-funktioner","title":"Mer om funktioner"}}},{"node":{"id":"29e29c69-360c-5f5c-8f34-5aef22eb327f","frontmatter":{"path":"/osa-4/3-listor","title":"Listor"}}},{"node":{"id":"bfe57880-0cbb-54e4-be9c-8fa180eafe6b","frontmatter":{"path":"/osa-4/4-iteration","title":"Iteration"}}},{"node":{"id":"2eab46f0-5373-5cbe-b2a0-1d071854a053","frontmatter":{"path":"/osa-4/5-utskrift","title":"Formatera utskrift"}}},{"node":{"id":"a5974fee-f2eb-5b89-88a5-6dd3754baaad","frontmatter":{"path":"/osa-4/6-strangar-listor","title":"Mera strängar och listor"}}},{"node":{"id":"e125c469-ee19-505e-9a41-83da6143ecd8","frontmatter":{"path":"/osa-4","title":"Modul 4"}}},{"node":{"id":"2558444a-be1d-5bc6-95ab-e091da2443fc","frontmatter":{"path":"/osa-5/1-mer-om-listor","title":"Mer om listor"}}},{"node":{"id":"b452d9be-0569-56c2-ba89-a040d4cb40dc","frontmatter":{"path":"/osa-5/2-referenser","title":"Referenser"}}},{"node":{"id":"ebe4ca3f-e657-5907-bfcc-ae84d9947aff","frontmatter":{"path":"/osa-5/3-lexikon","title":"Lexikon"}}},{"node":{"id":"f1dd5d66-ac87-5e53-92a0-0b7e3ece6ed8","frontmatter":{"path":"/osa-5/4-tuple","title":"Tuple"}}},{"node":{"id":"161c0109-5c00-5bed-b7af-90dc7ddf5713","frontmatter":{"path":"/osa-5","title":"Modul 5"}}},{"node":{"id":"e6cfa6e1-e99b-50e0-bc6a-3c0f153420e8","frontmatter":{"path":"/osa-6/1-lasa-filer","title":"Läsa filer"}}},{"node":{"id":"ce8d90a4-ca7c-5797-abc1-3fe0094bfa4b","frontmatter":{"path":"/osa-6/2-skriva-filer","title":"Skriva filer"}}},{"node":{"id":"519d5330-277a-59ba-be50-c2f63080df94","frontmatter":{"path":"/osa-6/3-fel","title":"Förbered dig på fel"}}},{"node":{"id":"82393756-3ef8-5d07-a8da-fed818ca43f0","frontmatter":{"path":"/osa-6/4-lokala-globala-variabler","title":"Lokala och globala variabler"}}},{"node":{"id":"007d85ae-a118-5b10-8a7e-18302b15eba8","frontmatter":{"path":"/osa-6","title":"Modul 6"}}},{"node":{"id":"bbb2346d-b1ee-551d-89c1-516f119b0eed","frontmatter":{"path":"/osa-7/1-moduler","title":"Moduler"}}},{"node":{"id":"ecb9af64-49f9-5e28-a544-3934e95233cf","frontmatter":{"path":"/osa-7/2-slumpmassighet","title":"Slumpmässighet"}}},{"node":{"id":"ebe469ef-c486-523a-9621-5dc4040c5cd8","frontmatter":{"path":"/osa-7/3-tid-datum","title":"Tid och datum"}}},{"node":{"id":"b9cf2d99-08f6-5de5-8425-c9b483241567","frontmatter":{"path":"/osa-7/4-behandla-data","title":"Behandla data"}}},{"node":{"id":"27075b37-8a6a-5554-9079-465a36d2da2d","frontmatter":{"path":"/osa-7/5-egna-moduler","title":"Skapa dina egna moduler"}}},{"node":{"id":"69492225-4d69-59ea-b33d-5301d35cf4ed","frontmatter":{"path":"/osa-7/6-funktionaliteter-python","title":"Flera funktionaliteter i Python"}}},{"node":{"id":"70ae841a-e6e9-5252-afae-6329fb67bcad","frontmatter":{"path":"/osa-7","title":"Modul 7"}}},{"node":{"id":"4afc4486-3cfe-53d1-b4c0-6db26484acfa","frontmatter":{"path":"/osa-8/1-objekt-och-metoder","title":"Objekt och metoder"}}},{"node":{"id":"6be37772-e94b-5b36-8a02-fffa7eef9feb","frontmatter":{"path":"/osa-8/2-klasser-och-objekt","title":"Klasser och objekt"}}},{"node":{"id":"8b6aec39-f8b9-525c-9f25-d8e73389fa42","frontmatter":{"path":"/osa-8/3-egna-klasser","title":"Egna klasser"}}},{"node":{"id":"85db460a-77c6-5087-8e97-a3c772186fd9","frontmatter":{"path":"/osa-8/4-metoder-i-egna-klasser","title":"Metoder i egna klasser"}}},{"node":{"id":"0e59dee0-5dd9-5827-83b9-a55e7d585c31","frontmatter":{"path":"/osa-8/5-fler-exempel","title":"Fler exempel"}}},{"node":{"id":"64715d0c-54f1-5aa7-a566-d2c5be6523ea","frontmatter":{"path":"/osa-8","title":"Modul 8"}}},{"node":{"id":"f7457509-a9a6-5420-8d03-ff1c61df8dc4","frontmatter":{"path":"/osa-9/1-objekt-och-referenser","title":"Objekt och referenser"}}},{"node":{"id":"16689ce4-b6aa-5bc4-9a30-44820994d6ea","frontmatter":{"path":"/osa-9/2-objekt-som-attribut","title":"Objekt som attribut "}}},{"node":{"id":"07985959-e85a-5f45-8923-babacb943c04","frontmatter":{"path":"/osa-9/3-inkapsling","title":"Inkapsling"}}},{"node":{"id":"83108600-9a37-5fd1-9a2b-13492879a9d6","frontmatter":{"path":"/osa-9/4-metodernas-rackvidd","title":"Metodernas räckvidd"}}},{"node":{"id":"a553cdc9-d6ac-5a14-ab43-d44811b407a2","frontmatter":{"path":"/osa-9/5-klassattribut","title":"Klassattribut"}}},{"node":{"id":"f7d7c9f1-6b54-5268-a308-995d49dd913d","frontmatter":{"path":"/osa-9/6-fler-exempel-med-klasser","title":"Fler exempel med klasser"}}},{"node":{"id":"c1fef3f7-8ca3-5780-9dec-19bd672b4627","frontmatter":{"path":"/osa-9","title":"Modul 9"}}}]}},"pageContext":{}}, "staticQueryHashes": ["1357757885","994120085"]} \ No newline at end of file diff --git a/report-issue/index.html b/report-issue/index.html index 895a83142..14e4b7964 100644 --- a/report-issue/index.html +++ b/report-issue/index.html @@ -134,4 +134,4 @@ } } }) -

    Näin ilmoitat virheen materiaalissa


    Voit ilmoittaa huomaamasi virheen kurssin Github-projekin virheilmoitustaululle. Github on yleinen palvelu, jossa voi hallinnoida ja jakaa muille projekteja, ohjelmistoja ja lähdekoodia.

    Virheiden ilmoittaminen vaatii käyttäjätunnukset Githubiin. Jos sinulla ei ole vielä Github-tunnusta, voit luoda sen täältä

    Ennen kuin avaat uuden virheilmoituksen löytämästäsi virheestä, katsothan täältä ettei siitä ole jo avointa ilmoitusta.


    Luo virheilmoitus näin

    1. Paina yllä olevaa nappia.
    2. Laita ilmoituksen otsikoksi lyhyt ja ytimekäs kuvaus ongelmasta, esimerkiksi "Osan 1 tehtävässä 30 kirjoitusvirhe".
    3. Kirjoita kommenttiosioon tarkempi kuvaus ongelmasta, esimerkiksi "Osan 1 tehtävän 30 esimerkkitulosteessa on kirjoitusvirhe. Esimerkkitulosteen ylläoleva koodi sisältää rivin System.out.println("Syötä liukuluku");, mutta esimerkkitulosteessa lukee "Juota liukuluku"".
    4. Paina lopuksi vihreää nappia "Submit new issue".

    Saatamme kysyä ilmoituksestasi tarkentavia kysymyksiä, jos emme osaa korjata ongelmaa ilman apuasi. Näistä kysymyksistä pitäisi tulla sähköposti-ilmoitus siihen osoitteeseen, jonka liitit Github-tunnukseesi.

    Kiitos kun autat meitä parantamaan materiaaleja!

    \ No newline at end of file +

    Näin ilmoitat virheen materiaalissa


    Voit ilmoittaa huomaamasi virheen kurssin Github-projekin virheilmoitustaululle. Github on yleinen palvelu, jossa voi hallinnoida ja jakaa muille projekteja, ohjelmistoja ja lähdekoodia.

    Virheiden ilmoittaminen vaatii käyttäjätunnukset Githubiin. Jos sinulla ei ole vielä Github-tunnusta, voit luoda sen täältä

    Ennen kuin avaat uuden virheilmoituksen löytämästäsi virheestä, katsothan täältä ettei siitä ole jo avointa ilmoitusta.


    Luo virheilmoitus näin

    1. Paina yllä olevaa nappia.
    2. Laita ilmoituksen otsikoksi lyhyt ja ytimekäs kuvaus ongelmasta, esimerkiksi "Osan 1 tehtävässä 30 kirjoitusvirhe".
    3. Kirjoita kommenttiosioon tarkempi kuvaus ongelmasta, esimerkiksi "Osan 1 tehtävän 30 esimerkkitulosteessa on kirjoitusvirhe. Esimerkkitulosteen ylläoleva koodi sisältää rivin System.out.println("Syötä liukuluku");, mutta esimerkkitulosteessa lukee "Juota liukuluku"".
    4. Paina lopuksi vihreää nappia "Submit new issue".

    Saatamme kysyä ilmoituksestasi tarkentavia kysymyksiä, jos emme osaa korjata ongelmaa ilman apuasi. Näistä kysymyksistä pitäisi tulla sähköposti-ilmoitus siihen osoitteeseen, jonka liitit Github-tunnukseesi.

    Kiitos kun autat meitä parantamaan materiaaleja!

    \ No newline at end of file diff --git a/sanasto/index.html b/sanasto/index.html index 018378133..6654c459d 100644 --- a/sanasto/index.html +++ b/sanasto/index.html @@ -137,4 +137,4 @@ } } }) -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/sign-in/index.html b/sign-in/index.html index d51da6434..a9d291035 100644 --- a/sign-in/index.html +++ b/sign-in/index.html @@ -140,4 +140,4 @@ } } }) -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/sign-up/index.html b/sign-up/index.html index 01bdc58db..36c49019b 100644 --- a/sign-up/index.html +++ b/sign-up/index.html @@ -140,4 +140,4 @@ } } }) -

    Luo käyttäjätunnus

    Tämä kurssi käyttää mooc.fi käyttäjätunnuksia. Jos olet aikaisemmin tehnyt mooc.fi -kursseja, voit käyttää sisäänkirjautumissivulla olemassaolevia tunnuksiasi. Tällä sivulla voit luoda uuden tunnuksen, joka toimii suurimmassa osassa mooc.fi:n kursseissa ja palveluissa.
    \ No newline at end of file +

    Luo käyttäjätunnus

    Tämä kurssi käyttää mooc.fi käyttäjätunnuksia. Jos olet aikaisemmin tehnyt mooc.fi -kursseja, voit käyttää sisäänkirjautumissivulla olemassaolevia tunnuksiasi. Tällä sivulla voit luoda uuden tunnuksen, joka toimii suurimmassa osassa mooc.fi:n kursseissa ja palveluissa.
    \ No newline at end of file diff --git a/static/13e71ea262de820629eb873bb73f2d94/12766/9_1_1.webp b/static/13e71ea262de820629eb873bb73f2d94/12766/9_1_1.webp deleted file mode 100644 index ac588149838636846d6ba4800d9070422cec8797..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2982 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 diff --git a/static/13e71ea262de820629eb873bb73f2d94/80977/9_1_1.png b/static/13e71ea262de820629eb873bb73f2d94/80977/9_1_1.png deleted file mode 100644 index bca3ad34bd478c21db4c1ed57793eba6b6f444f9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1983 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 N002ovPDHLkV1lZqz6byS literal 0 HcmV?d00001 diff --git a/static/32e25a73b5e04b72265ba7ccd2d765b1/81c8e/11_4_2.png b/static/32e25a73b5e04b72265ba7ccd2d765b1/81c8e/11_4_2.png new file mode 100644 index 0000000000000000000000000000000000000000..89d27c9db232d5031dc8154d866181e83935cebf GIT binary patch literal 6816 zcmV;R8eip!P)FMbl8XH$uR{j0``T6()0s>%QVGj-vmzbC*BP8G8;6XPvg@uKBdU@8? z)-EkHLqkQUrly~tpS!!ev9Ynu&CSHb#E*}UY?#CT_Sdf4_p*dsflx4%!{*zyi}c#C zP;{f#_x>wQba_IdM*si-32;bRa{vGi!~g&e!~vBn4jTXf8PQ2ZK~#9!B6ql6iAlQuUfSPLdO6)A{|56bPOQhgC`;2S~JFqj28+gg>S+# zbSk!VNymctACTE!L{0*+ML9mCyMq5Hw2TXV4K*W|FIWO*aVScS#06|?9cEv)Hwk1$zc(AB6Dz3KIu(48+)M)6NffH}7!x>rm)xwKMr=qj z&=Tco{!LmC0X>6W$z#-Hf0s@JUuB`BPWx`5P|N-*3kA@3&@em+3=S|IcjgzF)reNk z)Yp;sfY?qoq3}0Qv-EN&7AO;xp=n_0Tyg&rf)eIEaKU$i!W7qP!-+z0odU?0(37E& z1q2|p9V<6t->@^sDwsS)3V#JX*?u(88$tj~UyrgN%8gPmqJv|61)j|3Q{mzSfeh8U zFPM+o(Z2ytBHVhUa|1C|h;nwz6{P6D?|x@`PnJQi>XF{(#XnLAt-wV4h5V`b$M{gA*QehEdD{|*kl}ln2-FMd29jq zkbg!Kg<{OTm0M^ED%M`40r?lv?AFro8wO__8Gl^6EIv{z-v#bmnH0hx3*T-cf0@T7 z@Iklr7?+W5>&WO6U3X1@)VB2&*P(9PHGpR5xDEvJ;_?XT$ds?-?!V zmbMQ(decA~69x-(Hsl}CgxPEXKzCK8G#ROLVpM3IdRH$XBh80^85BZ*Lg&vN5Bfn> zkd2abJa8poGVY9`d=QBY=qYP}U6)$I|HvUfsy?SDv~@JuOzGLoCL z48@|=ETKXn=OMkMAz);mLNid{v}lG1enrp_HOvtYDP<%|ZZB|JsGYEju~e8ko|r%>SJgsa9X}-`P{-9An!IOXjY*tH#<%{ELs8;zVjZ<4=q|n zxrq|HV?mJSwQuzN$dq6~$YII_fdY+SL5QXS1oRHg$}vAfO?m($RuCvrFHoR1656XV zg@izva9RSU-Yr^<=|ha3DPAjtyXAud#R5td&}==@`$anI0u>fL-ydXRh!G%KzatTP zNbw_`5)W4LzmS_O;O+zMWI64o1ZnSxRF|8$RD~mnz$nk}b9F1KauX$=r%lyQ&c-qc zOKh??$A%bJ{pX_s^*&UEM1U4hHY#SdhH(-yc0?1Np-1F6-pGMjg*`c$E1QhH&1i#r z+Q+;kiWUli)H9&Zz2j5s>fYq!=DUT$5{3@Lmt46`_Fba?lmn9|9olr{J4VmBQ%ahf zQ$KBQh_OP*c~=w zYsH%338v9@BHk>9VrIoI@zGXD{;b%t7)lsQE?O`>f9;XnOo=zQ=gbhJ>7L3;cn5{@ zuc0voLyTD`*807S4R1@8NqqB-)2?FbdViHF^6CL^&#=MvM4H7`GAmz#s9Pu!T)?dRP3jZ=-doGRg9iMH6}z>-T69 z&|*mT%eu)BoZFXk@f!c1XOg&5kpse2tiMPVSx(E6lu8*B1m)bC^|Y8tA}Py^zetsJ zLu^tggTHi{vS=QYvFOyu8c|bsR}8UzrB4S!ep&6Xq8@b7Vjx)dBv@!8=c4Rti|PB@ z!=On0D{6`|=EYIvblURGNivK?q0d6iWr;}uQtvPuXxR|+Q`xR0a-((iz_VI1l`Uw=X$ua_-QCWolf-szvFWJdiSe2#nrwu|a=J!Ynjqj$B%lDa4-9qb&=_!-RGHH z|MB0ZlUthlq8*2EJ6r0l&4#|KwnH?}yJM>~n2tVTL4-<#HpNHx9B6rsMa4f)I7mT#U=h^+ze&>plN&&*|2 z3GV{MjH+E~=608wX`=s;G=i|2Qz+FTm;spD2+b_%G+A)tcof*lwp=NAcixk+Nt&W# zg%s?3{1(R+imC1GcL>;Ya8YCj>>FW;ZG>MaqB&8ggSc<&*p9Nec3deVIw2P`d~>K# zGon$!nvw$(r^AIC)QMdHgoaMLbZkQnO>2T?*yp4%qre`u%gbTQ152@kUa!$r`j9=* z2HJq;tQ2k!O_8%lK*MSoh-FeVuO^3)F(A=&h8@}hHi`#w~BoTo{ zPRmQ-cGjBTCECUZD14fCVaMD6MNT{3Fa6#`rt89}^XlH-wDTS@JA^(3b+$JbQ!F;5 zdJyxz9u(1xb=T`uBE`Kq*>xjMi|f}lMEdhSr^VKKJ*O>ox7*p%iX&cCDp#(_s!KP3Q@#a&uA& zM@DgyQQ-@7U#e(90E=1>A@8MdvYvi2X<7q%q@o4Q4Kb!f(!OYP2)XapnP8q)I9A65 zmYO%wnAIGZ<6hf?vL~Zr?>I15OachQ&Cofi=)Y9rq?I{iW=YBIy8c%P19$I!P@IKrF~Gjko>{WK*0f{Ynp zJd21fm%?p_iFBuUb7mYA+eghaNyyCkf}$YJyhhG@Svh$)@&#!&&&*swbC=VyyM4!X z3_9&gXgH->|HU^4Chz{@d2QM`=vX5_BD26yIqO}5kj9SH%(wYsDct&-qtG}pn@-qG z$HnO+yq&K?5?;9Er_~b2%j~2z(A|0fDTg7~sDr@EY@;>o%=2P8_g^lS!tME&Q0k4Q z!}=1&O6{YTO5yk_qm`RSL9QnaNV`u_2aMTRA5@%O6&g%20kKa(v@AJxMmS0|_NU$`I>Y1d#1)t5UYT zn__{+CZU2oSNKXP+*)+n-dvIbPZy**z9^N#?Fy5!>R^e&nDtUP-cP$ojNCTbv|@SRa-)G+ z#JXb}ZM~s;|3Yr^sm7LPWwsjyo`p>k0fh<3tg!_@EypO;Juiq{J@Y&#gMD*y1eF_l zW_f|Xs(!1M!ii~C!;zC=8#pl+CggXeaNI9oIGHbc-IshC%o}E(0u(QWYgKxAv0MuvGjk%5tM;Ci z!j;0`<4<(~;d0&#!L2}%Whlj7ULvoymjitU25PkQH@&=gcxLGRG~`hnoYiV41{J{M zSeY({vychX2n29=RI{BU=d2C z6b`1T4Q#m$nI?@)cQNu_3WqkMX#Iqmab*r`#g5jgIf4R{05lctqV)?{>Ef`CFPZevo1!D+P&rQFLa?fV7cqq4eB zq|l^No!<;GZ)ZJ&^`euP{Pg=(kmLaGC3LOLx$DObu@R@!4$6h=9$;3$!y z=DZYcloP`8Gc{vq4^~>~I+`2`gV?4El^f@&*x5@^ycAAh(Kc4!%PUO49S#s>DJW{3 zRxDa0AKGRaMv@Gj-?pe}^ug5Bg-Q==mNU(u!bR7qTq#^9t%ki>MTX_}xe1b;+1^Uw z@VMZ9(S`ss0ejzYfw>+zG0z=?jYj?a|(w=DD{?Q1Y9S4J909T>I=MB3P(hn z=H9u-P1t(7iH;i7Vkz9tOd;~Z*^!gEY)6fSQaHY$T;`7$2;4aKuJ=FzN|DoY)|N9D z4Cd{N)DBO!H~B(DOjII7p$O74bFLL3ply%W9LisXQuWhz=VRp!6<1ON`=85YCoGo2 zap4y@ahEKjmD&Emjy!QCa1t4)_fj}HJe$Y~+{7_|f$^t9P+>%Ha8m^VXbtRg1mRUg-#i>+{rUKNjLPb57HA4#0 znI@vPdZm|Fr^tpH0qH_iX(&|(=7^xfkwfxXNb99={W&e5QYbD9B}(CbcQy{0f0Q^M zXIctJ=f}~^4!4mz;%0RoIDp@t?FHMwlOu}w8!mT;+I*lAFq4}=G}FWtPEC#3 z9pWRq%*+6GxxY)(*k#SsG%D^QWE;49#E8@SETw*HDAEt5EeyqgsU)!OGyrC9SvJL{ zi~)PPVFg$~oMr(!c)_;kG}ER z_fa(?mG2iCKMzGf&Vc`4{VW`3H_0|w*A(c4LY?(LRNbg* z9pht5cV_(dXfl5EN*==d)`8_u%b-(3Yf^zMpQIxH(D%$D7#;7q2F|KuQQ9!kLl(9U zOfPk(=RM-{=v#i7^7nkY+|;OPYNp1gLC49$)7kVN;1u6x3!wj#-j6GmC%stN8BW*i zd_7*CV=h&^hE!~ra7;qr;+=dd~pJTFh6aEgAG`3^n>Z+P6`Q8Xb?bpAt_61ZnKijhg68u~=TkeDGm zD1>$6J?S@~^^2(__w0-}L0L5~fKMjPKQ-ZQ)>`RyLG z`5EBuo$uc5l9ksdIT>yeoN1Bdw@c>dw)IT1_NTIqpBG&0I8vh~p*ZhTbc07?=r?${ zuF<|8vHpBSPx}b)u#P9|cn^-3pBLfd-{buF2x8l|e%dJ33&Y57aJQ4|8a08y^$Cv( z?oYTrAJ**@oi9&#oFCEaVV|#79o#exfJQf}-|oTdk-hMH>wI^^>rWG$={=|S;7l(^ z8r&ZGiz=asJL;Obu5F#^^#*q~`t|2z-|o)s`lKeG;N|!TZZtYSe&{JWp6v6*tD_@5 zMdwp+By8>{{S22MvTA)kvR8rhN}?x?&L{nRin1eKz5m2Xfe*)xAKgy+`H{UIKic&M z_%eRt1YZhH4gUv465MdXUY|<-7e-B7w2%CSf;>yJ<2p3{p!6X@MKGBkm&Cc@C90!<_rLlXcVh-S{v zygbSEh8M4j)FcAU6Y@g)e2R^hJThc!*C$I*xE?v0RL6&s>+O*t4`OJZ@!Na;x;zo& z{<9(L@6HY2@yn-C-t%E)IRd~vJKwDv zE}P)^2#(0LLB*SPik@r(!sX{xJmHer`jcEe-9EE*LE!SEU4I%jwMTF}ML+4))7_N4 zZG0k|`_CzQY8UUe9yUD1FMyMAyvMD6Ec9bo8b?YmNAkG-obUSc#omQmAIghfUGyVd z?5e%NL;rbQ^dmhb$BTX>5BGLC!oxlu3aW(W#kOy!#CFf*Vz)1NM0uXy=q0~BY!{_7 zJlv|P3jJ8=Pja`9enC#x{CwAq7hIl|ZM>*)yeF@d@vPd{Rx3_eE|XbNPG-iy!bS2c zEr|VfN>D1DH>W{1RHm(39@3R4QPTUfsc4QvNvFkj-}AqRZ>Ja4PV((elA)9j0W@)w zLn;QRWb4s9L6JdYD1hGv{|U2%0BOplu3ZGu1AL2VMTXPD&_#Q06x)Nr%$LPqar4hT%iCO z32AQpd+QJPKed@3{j@IWzV~JH|B*k*`b_WR?!Vo?XS)0#8;SnJwJ-T6+n?iqY4daa zkAS}rKgRU}{G0j5`5ovTbIc3cub}_J@WlTE(0{UD@qNHQo&RG0i|b$f&jeq(f35wB z_yPV;{mcI^_#bs|=|A*;rvE$Xm-K)1zxw~s`~v?z{^$RL)}R0Xxu4vR|NiSgv;Y6k zo8IT%J80%x3v5^~R;&DcA(X~3jAIzaD~Ty)&e2XYRMoo6ryx0r0Q`g@2tNlxNO#w5 zy^OB;iDNWvD;Y1|K&u7Ekn~TVtNuXK4|j|A`p1k}e0R@#w`6DL)l@|uWQJ__-X%F;{vkCx|Gve5#l6KZ|uB!X!@MTBxMXCWbVQf!tj zuUS#ej9YV3 zAhceWzDWIQ`^WVETm5i;t&UzrmP#zXTq(7WA1v*Ggg{zy8u~qNVId_Qj1W|fZy&om z>w3nrUNm#5Pgkpp6sBl-)K*-5l6t_1%$=ZHScrB{LY1Te^IA|WbhPbguhiRL`9);a z&U{v$hgqMVSbiz&#CLP`BS`8tf_&*)**t|B7jm0KAaGcDQqTBl#)*Mh22+2BK;ZRp? zQOO7P5F$H?(67{4A;`a3CpMDl>kcocO<>QGF9^4IHMhDLDZ(n%*;vxRM~tTCdSeVQ zzaK%B44KUOE=bO$p#UNAUynb=PI6&r>Hx?DsV*CL2n124*OcV;&Jz>#hWviR08h=H?`VQbuH0A-Yyuza((2OEH-t#uCE`d;dq|hEG*jH% zT|)T*t{ny!xm>CT zehW#RN`CvxE@OvYJJ+E)VOy*80-hiNyjy#?G~n=SSzo4W9D^PpjAdNinj^n1;!5#N z10`eMM-O`rsDUP1=>lHPKechputIu+rvHoLfSiPEK9mA3W5|XOfhAz%C^~bDb#YIf zTV>8`ORmHr+G2iOH=Oueh}VE`%ZFO%a+y1?g&s7?bF?Tnw8+!8g-%ubBH3ey1mtVj8@%ggYYs6S%C`>r}HsF1KcU63XaDzjF#wH7k+h03e(|MXP3yJGZV z;IxJ@?BCiwjg3{ zoF@ks*)m16et~G79JtqZ7s3}{`Stilljc{~?y#NQw(!&E>268Vx9?vT^pwLdgxxP_ z3}!qWI~T8Sbbz6RKB@0F}?4)IrMfzlDfcL2?e_dWv{(#L9V=L{(Kg>#$) z9D>*oS?5NpNyyXQE7$@7RJ^k$sk2MT7rX8_-@Ddhcp8Y&BX;cLq$9!H?HoK3C0cl)(`|j=@!OW|{AFr6$8@+RL3RanvRS^Xs!$Skj00 z!Bl1l@Y-f!p9n@i3J97h++bH|1Od(&Y<10w<> z%ZZ!5up(dSH9)YK>_4*dFLmmgqgzL;w#h5t=vWGS_2rF_?z65p{AuNmj+$vr3Pt`T zF`^or#wH@KZ0&kRU5)f9)H|W1S6E8+#9<=q*)*$_*Cv1Y8~)jSPK5vI&Rz_x=9C4l zz+{s%i0DMtgsitOfh-XoHdn(ocu+SnZI);Mr|=O+l30B4{ufQsA3z?1f+Dm-JemDX z$RR__mq5V_^t)Ae%SH4@B>4}CfB{py_8DlOfM?3s8GAA_%nV$yK^$OU-Mlf%;aTYE ze*YnrVKM5!dC$FCKma!C-laMIQp0opF5BMp+1dK0Wcya&3Rl(U^sUAI=_0zdNCKf_Vtn}7rF@74DY)~pqeoMulkGYW2EfxDB6z%Sy zp|;(vX2w80bo*F-5WM>yfkbQ38YZJUN?D$6DbqKjW)lv2%Ms%I|(_!;40 zx2h&UNjI&y*L?vR2W(%0A;ePF11#5S5~qA0AH?5;~6iR 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 S9GJTpt>)7BA4YaCu>S!pNuq!N literal 0 HcmV?d00001 diff --git a/static/33f03fd48c215b216b48b8d09c1f757a/08a84/11_3_1.png b/static/33f03fd48c215b216b48b8d09c1f757a/08a84/11_3_1.png new file mode 100644 index 0000000000000000000000000000000000000000..60fe1c30fdf72370c3b27d9eec314c613c412bcb GIT binary patch literal 4186 zcmai1X*d*Y)E-MCTb4<(q_Rx5nCxqcY&DV;hA=W_j5SR5WC>}C@bb=#q%316ChIVk zNwzVPHEYD6v4pZOpKpDy_t*F1Jm)!o&Nu5;h#B;2`e%F89n1poke&CPDy1pruR z$M=qtY{%!_9~aLYE5|#~d&WmcN2{Bg_BqvK%q74F%ck)k@(J&?lJgG^4pb6zSu5@W zicL)LrMa|W78aIwGZZX^E=6|tDs6gN)%h$kBKv(dnN-|O>$Wu1fjPPh3JTfMunLM- zR(tX}bL|Aje-MrXaXvDG1pol2TK`j6gk*0<0swqD<~Oe23m#q0#D*5>@W)>IbgflJ zGKhcbNWE9nyjISzH+{l;xrAg{rJnbFbylTW6d;&zLo(S+`hV2dret=xJa$e-)?eQ# zQU_21q&f9Nxby+!FTt}UD>Mbt$>oyW-vGA#Vm(W_LMvKiy_Kr|q&p-P>Sar~^9oUWaToXN*8>B+opzej=b`8s6l{Q&=fL zO-lG7W`cxa&OW>U?W3Sw8!Tt6$fsViMfetQ-DX%OzG$|@2V-Rp6Ov&oxGQQf#Y+t8 zzhXADPE0EqEL0@FJ7a7+bVulM|3(p$32vJgQP3$*w{Vc!ZVl|t)r^K+>sKw%`&J|9 zs#+uax7?0a$?6zQ;K}N<=fWeNUYBmWPdjFJLK_@7xK|okd>UagJV+ zSYm@Z-s=gWhXT`NQo8oCdYr?<(SIDi8YI##-k(niRI=2xoPE`)tL-~SNcq1i|GVb@ zSi3d#P4!8?g&LVcr5HcPd;?lAcLX%%-LfNanXWrJB|tx=g;V|*Y)ufv%@-z5lPh;Wv#?4b_iCh|a{0t&bk*!1SyzKZx5fj@A zQa+HeSrIHbf)>CA=bJ+z1{`2x#zn|MP^9_9(ovL1+?M4@#!+lxxbt%B18-HMKL{z( z8OmyT)ti==*&Wl^?8mr3v922Xm_lOHOnK`k;eoE}7La_4DeoT~&G-CLN`Q;v#I963 z?{{~dQV(c5Dkgh=~=$s4o!mmc@&SAK`vc=cw zj(HCC)|VTI5h}(HYQREVWhvQ=RmDXBzwh)~$-P+!$$&foCiq6MelMk-ZoaG+x#5A> zWwrCFj=Z^Vii_Y9JntVq+$IIp<8Qu?N3%orYIShi)&Pm(Yi&HA&QrxNquRqfhXWo# z4s<0|^f`AlpmP=XZ9p{k*`EMiEOZ4FLEXAtB=Ie(52cAA)66 z4#e%?5b44O3o zB`+{!zoCKzbhRWpT59h_a3B8#h12>yNZ{5W3xwJq%L4He8CFPw_+`0FX6QA4Dldkx zxoz6i#@NS*uvb9H+bT2@;W&ZS$J})75!jitp>E~m)>wCkCwx$YcqwtZ^KaqCB{pcRzA+t{^V16*9hR{xA1@ty9~W^-@acvdPQUfWozZOv9Wocd z<{r@BY9QA0?!szRphV(5|bV5^x!kY?wOy~oYypcsgj3mged@qI1$aUf;1>y7hFP_mvmH|gB zWKQ!2vP&BUmv?DNl z(J*xBW0bDVx1ZG#m-I)PH1q*Xu0xAt5n1P*3|H`NxmrNSz;)1t7R`1jH{u-9$7T2J zgWtPSQ0K_g2^~+IrwIdL4^Uj`k4WoRPa=!Sm4l6$BO3MaR4V0}y>KLjRHek1Kr5H# zy;qM{gXHjZJ7@LyQxn;|=*YD8ym?`;jG)c_3))L&as@IlEI#ZieUg4?t*|xlq<}qvY-LLki zbw~sH%3hjG8~nJEyv(mMOer(wGfh(`OFNTwZ)aY0o&?h`(ThtXI_CYlEo|(Wu59`W zkI8FsuKNn$C5IV37qW0jTC9KHC5Gf85Ld%e#b+!I(8)Vi!vKqfKs)>1E^?@qzZJ(y zjdP}O!;is`oGQf9ETw8*Zkylp5Zo)fF?t ziKSDtgD{H}Ou2DH;xA;^t0N`yR`B-2Ak(|ib==mC;T*ORiLDlyN?}3HCt8GkG^B7- z>;W5r4a&{;*i+$$&#R__=O^n0W~R&1+ndE{8Pq)NhH@fp4e79jXs8JcAuR{{67|3; z97eNYNsPK)5;f8T)*Z-?Ye8WnRE|C07qv;2i&} z2b%OcrX5*5O^eJ#LHe>=LaWMJPYaAti%-g^xMW#xdXY(Hk5g)@D z49`lg01W&Pf{XQA@DKFNRB}->{1i`NDbS%~p15mvN6C0iHkCGiG%0bIP<+$-0oZS> z9)}X8%0qwqGO{>QgBHHHEf2l(+Kr|n=!uMws+AWuO*20+9M;prh{YefCpRcxTJ>qx z2=KKffBPu3qTCb9N=1$i+hM%6*k{^tx{jXZ%LpN(3YF^gGIv&{ePp)pu2axl1;l#E z7g%R zncT8v&Ac*i^Ak*ukT)Ta&oAHTelciO8(R1&0)2p*`JwhuNisDf`=lH(#HJl;zy{7N zF5fQkvEdWY=>@4l}RR1S5#Rc>doo zl3O#lHF?5hYxcmKkhR+$;fAPGe!i-)-G!7@Inscpx9M`N2h`eH$?D~|Oa|&j?+m-F z2<=)$1Sa0reL>$@K|YM$*>YK_eZ_t zerJr2%sGver(bQxt zzL++xdL?Ly2*hY!pt`RPyVp$#5XwoO-`K5&VsnrYl zNd}iw9+4mec{li&39sxblE~tDyBw!`uU@vQ@YE(3bZUT39AExk7U;l4_9(>qymsfCV@@cZQ8zo`kY10I1ThUAEqVm$06Np0 zO>uNZE}D}bb*?z_id@*l55(ZWW!N%uLcE$)7Bd_)YBLeei~Qd1Wwq!@0Awoh=zd#x znNOMp;p`aP-P!z5VO-jZ2Ve-}sM(BZ^n@i@K0px8n&2`cM2IZepB!KK5&)d=VdkIc znE72?p-SQ{P_7wdVsDH|k-dqYFX;Un9B45rWIUaIW#TxSXMkJQn-|gW?y9<2Mu<8( zQfN~a{lQFBty)T*gh%S4?~D@D98xJN$j>n3WH^mc%0N~ z7py!%_^MI`c5DOFF8ZX`;zjGfPclJ`AJjxZ%UdCvFip=Y*}Vw9{`?zzpI-#1hA6EP zD6id*TID``@z4@8$#14q)A#MKU(~L8;*_<(k2|IqN!)5*;nQW&ckb30-Y*%y+3+K`$m}|Jo-NXB%ko2 literal 0 HcmV?d00001 diff --git a/static/33f03fd48c215b216b48b8d09c1f757a/108f8/11_3_1.png b/static/33f03fd48c215b216b48b8d09c1f757a/108f8/11_3_1.png new file mode 100644 index 0000000000000000000000000000000000000000..ef14299e5cfe72ccf584c118c1b637bb3d36c885 GIT binary patch literal 3926 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 literal 0 HcmV?d00001 diff --git a/static/33f03fd48c215b216b48b8d09c1f757a/2e4ba/11_3_1.webp b/static/33f03fd48c215b216b48b8d09c1f757a/2e4ba/11_3_1.webp new file mode 100644 index 0000000000000000000000000000000000000000..f6747a2313da7334f765ca0b220ef175309afc6d GIT binary patch literal 6388 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 C31u_@ literal 0 HcmV?d00001 diff --git a/static/33f03fd48c215b216b48b8d09c1f757a/81c8e/11_3_1.png b/static/33f03fd48c215b216b48b8d09c1f757a/81c8e/11_3_1.png new file mode 100644 index 0000000000000000000000000000000000000000..96a1f2fd4eeb2e01870db82609a930e6cfe8ca35 GIT binary patch literal 2281 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 D^^i~S literal 0 HcmV?d00001 diff --git a/static/33f03fd48c215b216b48b8d09c1f757a/a0b58/11_3_1.webp b/static/33f03fd48c215b216b48b8d09c1f757a/a0b58/11_3_1.webp new file mode 100644 index 0000000000000000000000000000000000000000..fb1642f157f999abb07f6534b5f4eb4bc019815b GIT binary patch literal 1668 zcmV-~27CEZNk&F|1^@t8MM6+kP&goP1^@ssBmkWOD&_!W06x)Tt4}B;q#`NOiJ<@* z31e>EUp%w224zp9@16dq)h^uMG5&A5aND`rDjj$2=lt)6b^$nNK%J58X}o9ayv6$a z&kuwL(R`-*9OwP(FJTUmo{9z*2s;Vs&{)3RtfpIxCEX9tc|CvZ+_US7Z@;zj$sTjs zmzmsclGs*UILEYB3b=*Qe`wUl&yd%?^mu?n@--ZScR`kr532vd1iO1bu%V{Pz52>2 zo^A+YtGA&q{T|i4Vc*;NgE4VdZ{9RC^cPc9>(HO=&*8NmI>EprJl?CL2mxNG9N45R@NQ_zMYra?9W~Uo@MJt}7qmm} z|C`Wd*L4(ihklj|273vOIX9U^O7x!@oTBg~QBFAqSuN-j@bR{Sne z!a4BRYs^<7N2rKja_l=axybIg1BlKUuYF(mtBzU5yc(&{P(4Or2AumW1wbBVYu-gsltr5r=A3}h5s+q#b5vlYyy7sOQ)s)kXP!<2-}m_g`CdD4=RR1{#hnyT-gwW9wW&_4FQOqqmBzPBEIt=T+;&nxtB6}rqX$v z9C2IxZUGP-U&HQ}`19|$ry~HsBzxGmSPZ#p74+e$3f6N^1%lQ=9Wn{sAbkKVW+X&~ zKMs5;_rDS9Bd-}LdRvJtNil=Yv7BmNVeKK^5ICYW1})U8*L?H)tM+UTJe{jTjTsBd z@Lf!s6qmfDob@N`9MT)1gIR?Felz&^Mg?y)cv3nEswyp|!M-QJwZXJqwmg;2L)8{@ zKqv3IAKjaarFr_<8f$iVoBE29QtbQIfo6DO4f*3J{M1OabY_1lde*!31m?mIANX3Q z5{TB@#XV^ZaLUXbzx+CIR$X4XX7x;x_I@>6LEN+EL0`n(3HRj)kG&{iv6L5*@&FFJ1;O-ETahFI}5)Mw* zr3V&AAoRfj5k6tW*QUY2%%6f_nOrd&nb~2>#Z7zSRveFBs?OmE7F~5w{iNbDF6G1s zD4>Uy{lz}utk6!2xdKjkPFwQ*9jqyyNVn_QfvKb7MTYR7=!GtYZZaA~3!;(HzHRHu zID6RiNp%$JDf9q%y$ZCN)@8xE_pV#(sEEH)-uPoF3H0Vw-9%If`%|DfYH`)s$Y2Oy+A&L4C(r)Kb9TUJM2z@+l6FVa6woxq0v932E*c+|=6G%*dI ztm1O5W4+j0oWU O;l+xNxBvhE000263`hq6 literal 0 HcmV?d00001 diff --git a/static/33f03fd48c215b216b48b8d09c1f757a/bc10c/11_3_1.webp b/static/33f03fd48c215b216b48b8d09c1f757a/bc10c/11_3_1.webp new file mode 100644 index 0000000000000000000000000000000000000000..02fdf2c75b05657dbe7bf148f4f61f68650c7855 GIT binary patch literal 3668 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 literal 0 HcmV?d00001 diff --git a/static/3f079cde22be6cf33b7be317492aa108/81c8e/11_1_2.png b/static/3f079cde22be6cf33b7be317492aa108/81c8e/11_1_2.png deleted file mode 100644 index 638cd5727406750226879b866a08c14afe753829..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3887 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 AApigX diff --git a/static/3f079cde22be6cf33b7be317492aa108/a0b58/11_1_2.webp b/static/3f079cde22be6cf33b7be317492aa108/a0b58/11_1_2.webp deleted file mode 100644 index c1afa9a865c2a768259a80db20bc4b0324f2fe00..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3800 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 O^?(G+tKoit0001#mvI*W diff --git a/static/3f079cde22be6cf33b7be317492aa108/c4c4c/11_1_2.webp b/static/3f079cde22be6cf33b7be317492aa108/c4c4c/11_1_2.webp deleted file mode 100644 index 4d390b655d584bc18a564c937fe7f93887d5a9ec..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5132 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 diff --git a/static/3f079cde22be6cf33b7be317492aa108/fb933/11_1_2.png b/static/3f079cde22be6cf33b7be317492aa108/fb933/11_1_2.png deleted file mode 100644 index 3df93c06bce9a4f8edce4786edb8ad92fb20457e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3845 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 diff --git a/static/74b678969e8df323e37bea6c8b4fae79/4c0ad/8_1_1.png b/static/74b678969e8df323e37bea6c8b4fae79/4c0ad/8_1_1.png deleted file mode 100644 index 0d6d278f35da68e1fecd9fc7893d2a88c613edeb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1930 zcmZ8i2~d;Q7EVA+gN7&2u!^!ssVpL5P!yCc$QnZUe{cb0R8)c>kOU|JK~RB^RAg}h zA;=p3XdsO&7D1{Km9<2EP|8-QKte!J7DXYA@6B}P_0GBXo;&B<^WC}geRDF2gd-Sb z9c2UpfpK?pAt4Y*Q10LTPEo#oa(dY(-?WHc0A41O$=%`M;j34#K7018s;bJ;(lRV8 zEECnTOCCT+xgDb*5S!G$O(de=t`-7;(sFlk1mXv0i!yU2^f$X0t1QTpA1jSB`DwZL zO^*0A<$Im7E6~(-PA982hfefFE>;5KTwPA8socgDK%x@(TnQ>shB7t*s`ebiT}1ri z)P!>X;Mcy|nUUSnLHfe6Eru}@qi5bozcSVVcPwUgXyLJ+<_k??9V*$IZh45JdJPi} zG-R}GC)J(A!}RwU)Y-zAd<)9_XOpCwt@u+$y6g|USpI5=D7mAvC1nxks1Ap;-S|&u z&cTYUvG2UZ`x4EP>?;RmL9S5ip|cPzjce?6aGsOy+@Zl3nm)fY9AU!mQ#k?pVoyLcpuHPC#~=6X9_mjd@l;JPwP{pL#`tI6SkAKt+z-?Nrk6BAkF$s z3f^fSPX58j5!;(4|6oa5uL-}3$Ndr(a(66f0Q!;2-7vS|{2TF;Wf2E6X;B!tvhVD0 z6doNopoD^67nTNo*(oS8z1)P1+;P)aw_LGA5mqve3euEv7`GdTw#@C_b0eIBd(b)S zf*wLgy#$lQuDYGT=?3%ZisyUtaE|>CkNGN4UML0C`eJsvYF4BN8#Ub~t6q=KCA~(V zAn$>ho&e6O??~Bw^zx$wAGEpNdr4|O`MYw*LSG{;Fw34pj-qR;$d#KaseA4jmIDUu zQ_f$amwr}zLwjuPv=;T0T~;>@!Nx_FbT2Yc;iA(D6_-*Bw~7AEL-ZzFnI z^pbvSF;uu-rw)n2k^6w_d96bW--8~#a7mWyr0kMP)Rr-~I!Qu0F!5l7-%&7zft`(s z2aC%jkD6K`*X4~L;WR|LYKb_Z$c9t)@O^d8CB1B%qu$ejyw<+xB1x+2vTHckJ*9^6 z`N_`96qc05At)q*okWFuycE;%RW$UXNqEiTLa1n*N}HtRYp8(S?G*`e14oln7#Dok zviDb6-nB@R_zTq7mE1M+Jz0cj8ujMCR3u^p%9~GgX#q1oIv5P`;zd-M|H%lzo*xx- z!XTg_`m@7$J@;cK`GHyQ?ZFW$echZxSmtHi&^6wfMX-hzY_K2RvA6NAuG(6g5pqB_ z7clO(0I^HT;Im=}n#Qdi#ye&mIwr^(MUzGjgZk3N$&0)q|0FfAaEe{ug>=%$6Utw` zA^U#6+XE%xgfU_Mf`gOfCy?Le$PHTm1JfQF;nyF(*mHoNCfO_z5Tqr_G$p`sDWX7T z3ejP$n&m5TZG9`Duof(;@4Aq#aAo3393HiKXa;{ioc-Y7fhxBX?m`my-pmgSruOj94<*C|s~ zX87c{#*~ha1X7>E4Ca&&ZYDFkTE1SdK6I4TJJ?7vJ&^S&#?UW4)SAhSqqYiwILInk ziaxB1oW4V5iv2`Ci~ABvyRoAzqgFk=dFj@WHllJP2QRwG>wOJXv!{NpE5-i^&h0b=>VHo()@RSg9#QgOmYY6M>U)kY@wbz?Vp z8n9^ptCaaup)u#sF%~~~)qOy)rb#LpY{-SRisphn@!D2`LDozlPH2vwDrJ^1>ag<8 pC8zHA)_bg;Z}BHZx=7oJl{>fb>|xKjWC diff --git a/static/74b678969e8df323e37bea6c8b4fae79/5af35/8_1_1.webp b/static/74b678969e8df323e37bea6c8b4fae79/5af35/8_1_1.webp deleted file mode 100644 index 2ac2b55f1d9e711b488e5d843bb7802da111b129..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4414 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 KMNUMnLSTaAW=sVD diff --git a/static/74b678969e8df323e37bea6c8b4fae79/a0b58/8_1_1.webp b/static/74b678969e8df323e37bea6c8b4fae79/a0b58/8_1_1.webp deleted file mode 100644 index a01a7d6a7c3ff13860f6e57a42bac98bce71f2f5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2478 zcmV;f2~qY^Nk&Gd2><|BMM6+kP&go(2><{PF94kZD&_!b06x)TrcWp(q#`Ak9ccg> z32AQpd+$7LrSZr34%k1zeU$n~&|^N){;OhF{vUup4z&XIAAv5!&0ow5y1nb) z=z0(Jx1KNYU+sKWzQ6sq{g3$XfDhxp)&JIiYy7nOTmF;wr_RsR{=k2)9+@7-e{#K; ze`ipY%Ul1hB##-)!3$v16NFk+4kAB$)&`5ZY^BBUs_w0;Ts26%>c;oFNCb0Y~c4HWGmMYGpw>c)NUEAy&-o)|JRFrMngK8aJoYo31d`M^>ju%!;WZxv*L+$a4PRIGPu0p7b z<4+v5W0oa-OXVNJ^5NGlFo0nBZxBwE01VB$@(#GIb59!q39Fa>fNy$wI zSETtLo+p1&twwsaZIVJ?-g5l8{@znRQw&js>_ib={e3Nz!i}^@3Xw|h(*RRFXr;QN zDWw|0pYdvT_$Rq?P(VDjR}7V4d3_*_?};wwU%c>K133RUw)$)PQ!@Ku{hHZYobuws zwVA`e0CHe=(W4!>-14ky!vt#8bnSx)>#u1-T>WAkk3F3PZj5Mv64IbiKMf^C-JXT_ z3dOkpQLfmU8zsvRk2U#JK{c@L+S0I-YEGiZd{UQ-kPOyntQlogmY;%R?M&2*ai%58lv(TSYD)n=Qh*sPU>#+~6Nqxc?Bg4ygZzHs6WFq2#Mb+M9N9T|UIzE-o<6j&Do za(WxxTK8mnINUL3x@I>Su@OIMTrglfLj}D@;&}X8)(w}eShZeVKD8wW;nyFL@s_!c z&q&W5eU99R_3sO*iLT4FwXWq7z+d@ma?hj(%!7Mp>;L&?~KlpG6hROSyn9}jV zqnJo9mbi-v4zX%d3|ombKB*A4A6a>|^mOuO<0(MjgpPkIngxz6+jMn%&xf(HwSe!$ zgpK~|)RkN$nwLz@D$@@ zRKYStz&yRhJ;@rfRo1M09#a+hFAXz0WGm(nRBfiPXf3IkuKt6gR__!|r&x*LD2R#t zj|bDao&&@hiHq(KbdlcmTZRf-QXN^qddXLJ9uOcf>;|!H!m)~S0!su_EVqSasxM=6 zOA)uw1^8aPG)7&Q_W`a1Lgzd5vR?QsKEU6UsJ>>^VV8}6FHyG}Cn!FEX@qU3ooE^Q zerLz7v;er1qS;27(D^2f>}~Wt$v+du$g-uPlBu8B8MctD>iffVh_Qyz+gM&>~KDEw$5-~cQgaE zc$E%@UH90L-zcT{G^k}%M@2Z4r38vC(>Hw9znkbKyp`gnx&{=bGdCy>VqZjblqO~P z^{Y|^PIRt7qcYGi8sKUvy+aOt$CnnkQstJj8aWAI&!gZjfv47O znX5me8IIP#J)hr(i`nm1qim>9Ey%jVcuM?XlvJnVr&@8&rt=-;jlcmnO5j z7Q!aq29IU@b04zz>2J%iD#38JFRw zFD1a7``h+(K^{cBrPDHXEW%^+La9&R;g+iS7&!kFD<} zf!7Xwn1(1a&N4A+Gj*3Yw?AeeX?AR5+&JYr~V4Jue^QEZ?8eP9+ zCnC+B5moy*9+1545`)HVXw1gThOO9Nj08^3)vMug+pQKr-FJw@)y4voydBjiWmHF~ zh^=O(M9Xm&Z`c-Fn-C1TWCJVggMi4P>M0JZ^9u9M!8tzIdHXJA4Vd*h1~dB|km^JA zbi;S}z#}6q7-a&`!WORmQ!F7g6VihG%^=x-{49%X_>N32e=A4vP8$P@9zstkICE4S zSMew;$h7xVdc!Q{wvkh!f}{4zvR0ptI{qewms6Rqm%EZhW|d?C$ad5yq#gVFjVW*| zUmPN5E}B5|fT0sqxoPBGIibrQU2t@+hceh-gL!CK?a_7J8ZWTlbY(K){!d9zdRy1E sem_Q8N60*05ohNBI>x|sYIxZ)E{^Tf7>p6?H`prp5MO?HEsOvF0GQU|NB{r; diff --git a/static/876ad26e1b0c7b303582f9e0f2cb0148/10600/11_4_2.png b/static/876ad26e1b0c7b303582f9e0f2cb0148/10600/11_4_2.png deleted file mode 100644 index 51d4d58303767f7d1e5b551dc4b8213e07ba5636..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4201 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 diff --git a/static/876ad26e1b0c7b303582f9e0f2cb0148/81c8e/11_4_2.png b/static/876ad26e1b0c7b303582f9e0f2cb0148/81c8e/11_4_2.png deleted file mode 100644 index f7db24a88c338eca9e50b91eae790a7b4c184a3e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4581 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 P00000NkvXXu0mjfdQG&S diff --git a/static/876ad26e1b0c7b303582f9e0f2cb0148/a0b58/11_4_2.webp b/static/876ad26e1b0c7b303582f9e0f2cb0148/a0b58/11_4_2.webp deleted file mode 100644 index 4f01e4a5d3ae081f59b2085cd2386a3ab16169e8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4858 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 diff --git a/static/876ad26e1b0c7b303582f9e0f2cb0148/c2de8/11_4_2.webp b/static/876ad26e1b0c7b303582f9e0f2cb0148/c2de8/11_4_2.webp deleted file mode 100644 index 49c6b58993b58d2893497beb3cb302a623f09ab6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7848 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 Gpa1|M|0%Qp diff --git a/static/a3722ba9326d57861bd87ed8593aab50/12766/9_1_1.webp b/static/a3722ba9326d57861bd87ed8593aab50/12766/9_1_1.webp new file mode 100644 index 0000000000000000000000000000000000000000..57e2603470362da9a31603e506bb2ef0c3491798 GIT binary patch literal 2956 zcmV;73v={RNk&G53jhFDMM6+kP&goX3jhGnL;#%uDmekk06x)Xs!=E(1z?dRt_jsGLy@5FEAy+FNlx}E?(6#j4illy;#hxPt|eP;i6?g9K)`rrC5 zP(R1`BK@2GU$7VR|LT9||1`c=zjy!9{+G>v=AYre_kW`J2mX8ggZ3ZV`~Uy8|J%R+ z{^q~3|NqItiW*Fet^9#E&+&RUqHZK}(@^s@2Q=gw<>#Ul6e$3u^a}=6S>Ploa>5OhF&dMht~QCsIG??f$%lZ>7Ql=paG{ z=XP184HA()On;|}lZegr1OVkV*P0$J(8He%o_W#7I0{xEXD}+668S5T(bqFd=bu!B z*sO0%q}hJm164|5_PaCzC<2J=rlf38Tw~0wudmQ6Ky+-#fA=~Ye4V`2C4FmA!6b5m z9hvT%vae_RG(kP!Yh?8UWrB_`vJTg1M|93s4_|dXpm&Qw8tGH<v5um8V@<)C0!WktQw;=Li)^ z^{n6jv@YP|zspGXhRF^6Ujt#nr1kLLF1y-n`BjAalhGbvX<_hCL_Ee**a~9OdY?;U z(z^ysE#8`CmI1oddH?|a{0oqer5j=yg1?gtq(CHK4py|_xt|c+6S@*{GD&0f`oS)l zn#j&20@`jC8A*3(q|=-Bge_`m0XCVA-_^k4KG+L|&dB%oy@da)Anr!QX4m|5n{@Mt z+Vooj06qHSwTxGyK9|(lI}a7x9jJ|x6V&f+VgcL-^BuJTfTRTJ#)^(_l7Rch{m{*PG9`bIn1ptr=^-FMO zdLqe{cyM~4kQ;o+8+~X-(X*~3wx7zfLSB_~2{{NB{$^yn9zv?1O0D0~WZjRB=1g{k zKuvKlo=zt>!4RSKm9)Tkah=m^A#y0DKvjh-*W~&7Pt$d zJSIaGThA}O-44ey7#r#_YzTvcM%&&NIEuko2+cix%oYOc9N$-2@BS@je zWovZ$-SC#Sjml;}NA{Np7FOnurISlnNi9iSTEiY#WX2%(9wH_LU*&XY<{7USS_iSM7Mk|6=$Qj%= z8xB7X4qP!l2O4trJqO-79 z{}b40R6j5^_L#H?Qe^%u9COA`&BMLLl}xB`i2AbUm3EwWyf4p-0k1x>ArHU{&Rlv~ zu8adP2yene!zdqfKEGcVvYCU0$Iz0Wp>5(tx(X{V) znQrifsAM6ifnQdNsrx-)6!w^~en=m6aHMTp(^;W>3vIrmo{7+ZKVM}v`7ec6IyH-E zqF(?200ZjZV!!xs8xq}a)~htPkUP_PZ4?LG?-zF>+=XP`$ug`m{YLE7)XIxa>gg~2 zqe>}J8qgtJFow!S@qs3o@a%sNkIv6YKd4gg+$$}PDj!+P0lJc^|buw$k? zQlKcuKIolxIpWir6bN}t*Q(=SjCu!JRcsbu0pT??mZtWF{^Bn^v{0YCq~*U#(GI>M z8M9Lbj7%OmQIlNqe}8;aST8+dygt%4b8*wy#lhKY#SkN372X+Ls=gDAweQ(m^zS~B z^r$5hNgB@X;F@{=cir9K=t`$}{1W{qb(ony#4-m4^Jonucf>EpR#Kz{c`Jco>H?%# z9gh}8y6R5wa<&RrL-A9m>YGFNm%6nYPUr1s*|`8j?T=q-+<78^feM>P*pG1#=mfk^ zK(RQWt#8ih{FFYEstAD<~Dk$jO zu#mCdx|A?q6833)B8CxPHdryW@bWps-MxqzOn^|{R`0{3d(U-0+;{AYW<2BX3?t*2jNL(wp( zQnPs?p-CL-MB_!0G^g6@%%A0;d7+-$(AYddRgM6zLQI)6qK+#j9yatgPZ~VcW%O!JHLU zX3pI-)-TBXcR}KTU21*}W}&ZT4M?P+^iwamVNO3)@J9j;hv*~WO%^>XsN>x4PXAyQs_JEaHk z)WQf|^3^tfZROC2P6u^B*jw@(Z3M`C{w$0Uv%gY{v{oU1nS?abRf(-g__&(JK1nZu zQj`}a>^1im(4r_K^0002s C=Fap0 literal 0 HcmV?d00001 diff --git a/static/a3722ba9326d57861bd87ed8593aab50/80977/9_1_1.png b/static/a3722ba9326d57861bd87ed8593aab50/80977/9_1_1.png new file mode 100644 index 0000000000000000000000000000000000000000..1765d7393d3ffd0a7f98e0d764a59d0395096cce GIT binary patch literal 2226 zcmbtWdpHw}8lNwBxh40x&gF}_PHE&4vJH)9A|jzlma&;z7;mrvAGnB?y z@kK?seoD)fP8N#zNGX<`oj=Z>=bv-_cyG^pdEV#uyzleAWIrTKURFyM0077%;2tOd zKnyC^I^o=t6QeY7sOtxXm5Ogy3&Wtu5snf7Zo$H6WbBYX2Raui)@-^6r!auk07zM!q5xG z{z9Ie>do5w;i$;TKp!VWD7N{=IkkwI8_ibd1LKS!>W|QuI9zET|g7=jig}MYGmbiZ@ zq5gE<#F3cy3xN&pdGF~05a#*mY*{=c%BWwNh}CT#FR2SN4lSx#DP40Rqg9EIwmv(t zLH-^)6kB|xEp7f<*BCC|Adu+9zB_!n0u)&0VOAEh4oZ7P1Z!DvA7s3|DMNy5vTZcU z>dG$lk2*N6jcb)5EAEp)#b@Pr*R`}<#IqKq7+MV3DjtJ4wq&X6pwM?C)ZCm)>MTIE z(yPm-+Qh(r1#i)J7nHt>U{;49Kn#P$!Z78|oiy59$~`haYR)a}q&{@DOdo1wnpTd% z-a;Y`LEax2ZNuzuR|##BIp`TF3Vj%UJ%DJ7WSF*9>0MwsBbU-DQw}u2J$pPiLY_S( zGOE-h5{nxbJ~mwY15m{&?&DW)3L1ubP2vi$=-M&?nxWX*~hg#>TWw+kWTo^t~=oYPj-=+cha+ z@ue@H)10{Rh)IaCy{uti62+G{?uDSpNqOX;Q(IeOVsT2alloax#gHQcz_FvpthbOEwb?V(j0BmQib00$M|r zH`krgo!R@;535nXVjcZ=WmC)FB(+FEwe`O#uKNHxIsvvbrqu)0HI5j`0|!`otEtrH z+u^*+mNsJ=RiReYMQ}?ktVQ)G3NF?>?(^Yl7@vQn?kI$6CS39iY98`}(A^65r~DC& z-#xW_Po?CdJ>THuc}(3gU5f}N{w}(rvYwUC$EP-=_?1;-4oxKhzl=Tft%*UzMg6II z;@B>H3kWLGF|I@~&w1h>Ag=I6oe_2t_MdO5qUm`GV?HC&*Db#0-EFhznNsRa!_=J# zS(9;yjW&sCv|&#j?Z9IqnjEgG#KE@I>1}E!lL?{UK5}xGojm`^xagP1Lj28XI5$CF z;g)MNGJf>h^e-5@)&0^4Y+dkbq0a8m@6+XF>%p(|=D0~iX$IEg`}OTrB_6BVs$Ayb zeIGuR6}6S&iO(oGn~+**G*oCawR(oraEB1G#&+#a#NfNgha%mi)Mk|1czE~z$X4+9 z^e7PTzgT5eS;;+Qb1^rsSK$4XHFv-0`bT`Gm5t0?qIZ-{dzc1Ie8T=tgRRUjQJ(gu z3Go7TbSRfKM_=sqdr~^vNUc8dI-Pt@VidJ7FeaVq9c7Y$(PbN=|DMh7`goH`emCxe zpSGo4clLp0B}3>&Hp+7^lf>l))-RYWiUM%wIZbvjo=-esZabv-`E3>udw9##e!40g zgRw={<6cz4kmc_OM-2fOwL^+(wWLu(`umlkKQAJ^eC}D<*iulDGj6{D-|o z^EWRvVnHJ^-JtN7-!V#>FNvNsl`8YXo!uD2!5a}q&^zo$8i;xwHOL5=1q!!ouQl3i zvWPZ;P9^0I>*+4hccW~5hTg!JOUQiw5WfA%>LCgH^1E9{EL%y{{7 zZ4_0vdY5q;I!p3wx6WV9)%C{57Jr&s!S!xs z(6yfJ|LVnbAy~N0X3-a(l>+-8HQt&o0Lm+X9nzryHOJV@tVNoDs z47Orj@<9I7m{_9BwH_9y?S>ov_baT2K(5ah{7^JB$kRaKTr)&30RV9V>A`dh&-oYO C6&mdT literal 0 HcmV?d00001 diff --git a/static/a3722ba9326d57861bd87ed8593aab50/81c8e/9_1_1.png b/static/a3722ba9326d57861bd87ed8593aab50/81c8e/9_1_1.png new file mode 100644 index 0000000000000000000000000000000000000000..b1915036cc2d6beddc8bac132da90643a8552222 GIT binary patch literal 3626 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 literal 0 HcmV?d00001 diff --git a/static/a9810fa9a13874067832dc3cc67de74e/4c0ad/8_1_1.png b/static/a9810fa9a13874067832dc3cc67de74e/4c0ad/8_1_1.png new file mode 100644 index 0000000000000000000000000000000000000000..dc0fa96ca95e78ea8ae228cc771ed2200ac4bc1b GIT binary patch literal 2232 zcmZ9OdpOf=AHXNa$V5>{qP#?@h~6eSv=J*tznQdAX{$EpnR7^qhhjqWV9sOal*8l@ z@?=suJee6=PdP*y>UCJfWbgFf``*{}yYJt1eZTkTy6)fadw=fx4}^=OvZ9tE2n14g zIuCURfuxX<_k0CuN&nNnZ$vWqA}#Kd+2)=fq-yi2qf~r?Pf8nF)M>ec}M2A$Hf87 zAr60cbo2S-lRwtKONiTp&R-^iK;WLOM=IL{tPKLmi=3c#Km>1*N(gU&>`at4ngl0& z$9??1A@+$J?LUN;*`1-mw5rlAlgmHzz^MU?H6c-8Heqhz&PeMJDI`J`iGZPt6d6S+ zEw<`_oqF(H;}UsfkFX4w<{l3oaEYfd?X>9ijVI0kwRr85!&k?$-12s`ludkoj^Y`7|&g0iD z)oOku&g+wN*^Xk7j{c z9E$}}X(G!%@sSGmDD+=cqqcY983G?i#54vYJ ztusWuP7QH7m3;>ePin-xsdq&hJcbh(i|Z;57K5u_t=S^++}VGy>p8c(M$*;-^(IWZ zG}|IO1@ModQ{@HyR=A?v%+!!O3PecRO25p3AE)0!zFXJohTE?Z2vtAx zT24PhU%Pab73ChW)A*NmE%~P+AgZF7cr-|_d08m}s@C)b!N^=Y`>54XQz~iN%$Ph+ zGUL6Tl+j5wymaPfTUMB%LM-KMJ&akJ)LI~e5UA4wEGxE3WNeeq|JU+0&-B;Q(;+@O zWwPzYFO_^nC%eBXGQvkt%nza2FEX)k;`!`=J}^hcnO$ zgbCW8VnT8!47aAcn%NeN4tvb(xDh`98H&HMR8k7g$mP!IRxkdsQ7s?0@$?R}_3=pm zjGU08o}gPubdXtatD)7zRja>u^|5~U9y&nK8svSjtd_r@(LY{}#}D_#*b7T09JlE0 zz*>RY?Rf*WjF83WUYCBSH!7dv?Keyb4XPgmq$^-Ze48V!^RHcuJu)`YgLH*41g+;B z`>=`s=}=dLs7IAZ0vG|0?!=!wHN=P%>3`06Q_uTg>dq|Zy2)cZoq4)WVfy^wi*3!m z9zQS1+7Jg@6e7|IIp1SQw2;J!B=vb$h1jC?T?x8${V2q*rIu=*Gy`sY*KY4m>EWG2 z<#2EK66ECI>PS+REt7+?0xnnVwzGwHngMH_AWkaaD%1S+gpl*NP%6~A)H1!s(~hY_ ziR`P>Sm&t~A}ofg)Hq z($8N+e?Gm=lDJ8ck*p+f6QH_>o?uMZH$}i!fBWj)J>#h;Gsf6G9oheHGb+1{?%LQ3 z>qRnC+qN{%*7i+&S4R3oIf*uoVK6Yvf#g4Yz0(-Ic>xbw}_R%0fOfyE#Ab* zYP|9Ba6%4>f$cXH(pfVQZC1FsEo%Go?pb$F&1mP!8@$WW98UgT5L7kp={)#KYP>}|)Q4Jt8X7~tiLt0R-bcUA+B%Q7>U$d!s`9&X n_y67j5>p#XWbON{d(%d9y0=)l!RfB#ZUAzExj<{}uO|E#Sa46+ literal 0 HcmV?d00001 diff --git a/static/a9810fa9a13874067832dc3cc67de74e/5af35/8_1_1.webp b/static/a9810fa9a13874067832dc3cc67de74e/5af35/8_1_1.webp new file mode 100644 index 0000000000000000000000000000000000000000..5616e9720bb15dec84e5936d5ffe5d8ee1290aad GIT binary patch literal 4888 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 literal 0 HcmV?d00001 diff --git a/static/bb2be65b36f7fdf4ea48dfde815e9fbf/81c8e/11_1_2.png b/static/bb2be65b36f7fdf4ea48dfde815e9fbf/81c8e/11_1_2.png new file mode 100644 index 0000000000000000000000000000000000000000..8fc29dec11a4cc62f7439f7ca6d8a7a1a4581ff8 GIT binary patch literal 5765 zcmbW5RZtWFyM}25mTswaLApcAr4g2n1*wHa2`MR&?p#uk?(UTC?vRw0?(T-)f9A}& zKWE&3;zuP`vZyu8!X z(_>;{6d(%PT3UU5eIOvavR~Wy-BX4sFD2`zvbpQaKc$}Kv+K3~&sS63KaD-#Q*-LZ zDN*BokR+G-H;rW{uj`0}gxB-mLylv^qe4O=ZGp&0LR}V)V2JNIA^=jwAM?0aZyqK$ zU)t>>t)+EFCg0gWFfuOw^7kMcm9r}vGWayUuLlC9J6@2O9?6-x)~=uIu;0kuixYeE z3SIc$2b=_GJS)C%pVb=!KW&vb6HZPG0y?;tQDmY$I|h6dsclyPTb%M~sLhP?&vsk& z%g@PloM!9CD_Bha2YyvsYr8gFH!0pLmAlEd6L|BjIIGt&A? zIM1E>^T`v(ZR3b3r(@Ev!8UKgf2)xL!*keqdu3Ad=OI3;2zFH)ip|Y4JW@M)>Qa*q zPyk_V3|jaaQ&1RTEw_W5fH>yIF@1m%T0>u@0rzR?+8{ngzVM?w+A!4wH}?|Z6bHb- zPk7FkvXfdp430MoO6(T#|3}^r@4QJ;h_(rk+kfW=2*;1^bOgMhZjbyw0yP%1Q5UQ3 zV;@S{PLy?Jb6?MX-$|{hontBdoTxXvm8jQt(G%3zQ7zkSQqpJMHVL&fJZ(scD2&_r z3(u3?J}0atD>1wHs3$}XYSw)mk9cx=O3v3ltgE<-z&T*Hd+gM!J7Sm!(fhj8_UCqa zA!=DoQ*qdyWR9NUjj|k6kBOc&>vK5awTsMK(Q)a?;}&i|5(=sXy6phzMIj1`zpJz) z7zb-GdcZpT^aEhBWBji|Nj@b!<_D;c7N$aw?fZFh0KSHg%lpc#7|-bD{m9K6+#d+3 ztk-xTAC_1mdtfc2p_ser2O=J#6edo{)op3q;zrIMkbnZg=!z6k8nj!%BjJ~8*}e=Z2CE)GK$4U~+*`!NVl z3gMg$*5D@>Yb=6ZxBf_v0(0upEmD7t#4SmLJkYZ z`f;|1J8#xGu%h9T3uPgNZ|o=Op|2#Dm|_WZ#=A)+wr|9!HH`Z`PL!HE3ZMM@Ppd$fKZTjTh1@5M5o*__BnGs0*z zFPXPfSEdjZSshcxl(ySNAXLj`4{)Fs2Q8Vi-u4)>`f z8fsm`dl$YnpFpGP!*}K97Hj-|4I8}(rqHUg97iH!*h(Psw`#~f!pVs=Ku0LyH%^G} zB)UM>!wjpU?68^TcY=s6Yx6WuNoFo;JI)N(=aLn4((aVqbiJhOR+UD66n!>y1;#5A z&%s8IAe`dYdALQBU^8G$s4?sbR?O)U<9G)kubBip;UAyY5J1v(cRYNTBhD4awp=tEecq!*l9)90OyCsUl8ngWu0tvqKe>OfL8`@rf%?>#jl zJdee;hin|ZZ>qQ|r+j5nCN*Q@SrgX5dq(p&sl%$wARYtcT{}*J^f&WJkt*+^CC!|7 z`JR>vzi|$d-mWE@dvX>gYE3BlzLCg2ORee#u$wmtFlVe9cnzV?B*nn~=-QiT(pQT# zXZ^rdu6GG_yu%7CahBWyIJuufaZq2+l+q{NyNsWa#W~(lVXl;Le#tqKl1?5yV6aFY z6pfjecZ~C``cgu7H_arRkfGKfLJlRMta*gX@QCd*b@L~WSh!aR?3~wUQ^=F^Tip=Z zFX`$9;8sjp@^O`7L=0G#x)u@g9+1aI^_5yTXZHU1h?z$TR3GiH=hP7Y+R~a~$JxH> zmu(i*R2=*TozEv8xLDQ-a!4o0LTKo;tA6Jc&kE65L?@k1S=QXi{gQx|L~s`*TMnh| z%8=2A{xKasmmUQOO!70ld%v$WeLQFLAl0V2!<0JwyD4)#vs_qOSw+EMicKm~z~u`# z&tCABXXl*HZ_z=r>XeI?VQQ6dTJ)2y_iLs_cgZArGXWSDxERDsTDSt~Zl zPq`*U{K_{@abIE!?ffxw$8fnkJyw&2D^iBDhwYlAh6ccCg?jOPMn2BMetJ#IN7$(B z*1ON1pb9Y~H7CxO_tv((=w%xKHXQj}|Ke&f?C&tv*K8^%Ted<886Aye(y!o-@wGmN z6oU949o1=Qw?w31qQi~P0!nX#L%)(jIe~F7+yhZSa`H!|O;<0N#Z&&j7lsuc`~4v` z=TXh%_=_+O+uh|BW9apsg6WVl=L~<=3At$H$=5tf?Ad{OCNjT37(#3i(^{_Bolha z7o}s%h&95_0c=m`K_QCbX(i5PxrUX-klcn}K0Y~gR829TjTYjB50EmZj6YfZojT0b zlo^H2z}TY3QW#LNTkT*71kk3b2`2y;sfXIv{X$_MHGqMQ^!2I5bw5WGekE2SCxW5} zaYej$4ZQxK%f2mfaF$f^{B49p5$lD0sB{I-@{fc0C}=&EISMbtGVOfEg|pE`Kbre9 z!I6eR>nuZ0-*f>?krigp+!ITG2hM_YW7NDmV(Imv=pS`DDQIK0=@R$%CmJ6H^R z4#X53tI)65&FvLCuBUIGGk_guseMKMr|Fs}T+>zo8#0IF+nerfZie3X?N$bkK=(Nu zL`N<);q_-8Dw6XkcV|9y6E5KsNZKPu;vE98H%*L(% zV*Wbk=RSt@TMO`0=GNi^F@P5<+7Li_50CM}?Gk*fIh zfuFF&yXa^G-gQf7>6V7zWm;r3B{$?*6vm%3D(EBEJVA(?QAaPojZb0CPrel33(uG| z`S(#b#1C_}6?dHkx#_Ddb1^P-M&-8I9eWs<9m{|1ZS{RF(pJK0R_IofGs^GQ9NKkn zQpFlOkt;lGJx>?O3?r1$$R=dYkNZFtxqK4-luGPFd>A7V{$dErAW0+2*AMW0ZuQ9L zT#K20ha1D*WR7B|dCXg)K3YTJmFY6@_#^6^#ZjwYupdK2pL0C5VfTvlz-G!AZ6@}+ z+hgl7M@hbv7rGQ;|GlRrjc9TeOV5jfV{q1$GTW{2JO82%nN$Ca`4h=SVN`FBJ3cd6 z!4>ghEbW9rezrgJT=#|G$aqpp(SSAKGUn?1Vg{1iC&p)FrA)Y8)!88x6^|^n&mMJP z&aOy}vx9&EbDl&Ug?jY0eR(h_;)OS3IwE_3j`jOyL5-l$6}@|<14(C3BsYIOt}~hU zUb!E9i&JiEp`*y=)ohuY0D0$^9JBSeSr$Qvgz-N^Spc+KY&i-&4H`4!WS@-(JO+!z zK<>NG0!9?bM;*q-5G*oBwhnOHX`rGvZe_OqKK&Wt;R(wTq&wCTf&n`3d&}D z?Fl{5t(krh8W9@BEB;cPk~Pq2Wkr>C9nxh+Og;~|Wo z(UYCrG**^OA!0nCKpBRLp4fGbK0=L7KWs6JN_)Ror(1nwu0DwzX*!YNAh()OufP~B z#utJK0(nwVMMiwq_66W4S4C-xZ>)dv01aK66Q7dO3wsdo#Pll#|FFplFNvblo;TEi z8i9*HPb33f;tIBVJ71rsb$C;zu?gTOs|cTx8x%`i?{6MSrAZSB;m~*SoC#29oj2+5 zX6X|Q`5<%x2)xjmpa*`6uGy*a`w3y>KMb~P=Y8qH>zE4cpJoyiFIb)Mwe7H1QUPuz zn#ug*d+H;y%a+8T45N%$k9kjpGKR1C+%1a>* zSC}Y59c?9M&2Dm^67c60=Lis{joJvdD^@f7kZquzs_-bxyJ3=}7D#T9ZJn249k9S= zPj&`TYilT?xI7<~-iOfB;KY9EtEF_L#BQZs`Bh1v&=@faTFL`Bq4PkF(WI*6M;oq* zHljUM^1F%(9y_%&wR_yIUnRx&djwpOs6- z{u(HvVoF9?bW>ub7#RIGb`~WsZ?va!Ja=4zo9syE3S?jg_EBMJY&RcQybhN#tcv($ zT32X-)&$DIsy|-oLMS*`Ox}=>fS@XQl_gczpXdzg{?^H>`ZP`J+h>a26|HH48)6L} zbr}y-Og|F{@Du5qF^%u^PBDyWIV>tkFWbp_hfjRkV#>laX4}BYn#Qa-9var!))~JF zbHXXu=jtN9m#mf#T34zLjV_m*7u(SaP@Y^;-+r8Ul=-&vPQ`TGoW+CQ_d{JR;4 z(8=6j2i95x>{uFM$&h#&cVUvRZVAp(0o!Y&Gw^z2UOj@lQ`I&yLn9Ohyvf^KcTSA`&@|OZu944m z7^73fQA~K}v_WEndn`|i>n~(sGx!p(o4b8KS{H3d`8kv!Vmyri9O7PQPKE_{o9vTI zM^+Madk=8C&f^Sq;D8CmZ4IeXH+gb9=5ev$QA9KjmakvnVU(ZTPm}ZzP@Cqw&e;TK@s-n|9QS3K%Lz^ za~iSiJmhk`JuH?uyfoT4YZFpJu>a0E)5<3TS^i=R*fkzg?GZT9@t@L zyx-pbO6jea@p1ZkA7yoPoj!FW1!e`67F=DE1KhbS8s)h->R9jSDoDb8y%F&_lRfP7tY_bpZDXQF< zMi{8hGMSdbYdi)e@kbSo1XV3Owc*jD-n2@O;_xx+|9ezO8Sy@#kZ=cEA#j)dYn2>( z=x6%Qvh?}}wxd1~V=*eJe({B`GrzlF;vC}Y;t4y4@S3TM8N9bw7YkmZ(M;F1GI6!+ zUKMA#H6ls;Un}-Mf-ISdK`Nft#o0D122O%}20jD*5(>D4_OyE7#I8Rw^D>(K_|g=_ z`||?VV`&!~%dREQ5q5ZWK@j`$Q8JK4)CsbFm;Z^NonJ*pC|~`T@eWXEZ6<4a5rpL& zlF$+UxBxIQKbM1e1)thZ4ZQ*Q<_=(q_V@!Nct(_vy?`}#2qo1A%t6thedq8@>tC0}Kk=I@p? zQ;D9$jkj^9*xjubYersDPeGqfA$O>duE^|tzMH*vm z+2g@I;*Si^aYca_q4#fHQ?%9jss)8#m#t<3eD^Ew2k37mEkY$IoB&bj?oyO5vI}18 mhi$h==NIm|v&k4nFG%igwLuM+wg03p5)wpKMW$Q|?)M*n8bK@o literal 0 HcmV?d00001 diff --git a/static/bb2be65b36f7fdf4ea48dfde815e9fbf/a0b58/11_1_2.webp b/static/bb2be65b36f7fdf4ea48dfde815e9fbf/a0b58/11_1_2.webp new file mode 100644 index 0000000000000000000000000000000000000000..d527a21914c47b837348ae7cbaf4502e5909dbac GIT binary patch literal 3690 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 I8c)Cg0Qx#9uK)l5 literal 0 HcmV?d00001 diff --git a/static/bb2be65b36f7fdf4ea48dfde815e9fbf/c4c4c/11_1_2.webp b/static/bb2be65b36f7fdf4ea48dfde815e9fbf/c4c4c/11_1_2.webp new file mode 100644 index 0000000000000000000000000000000000000000..fe202f668a44bbafb2defed512a74223b7a8a43b GIT binary patch literal 5214 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 Yfwl1Z&5&RbhRoVw0lJ4EWq<$x03v56zyJUM literal 0 HcmV?d00001 diff --git a/static/bb2be65b36f7fdf4ea48dfde815e9fbf/fb933/11_1_2.png b/static/bb2be65b36f7fdf4ea48dfde815e9fbf/fb933/11_1_2.png new file mode 100644 index 0000000000000000000000000000000000000000..d96475ce232c946a2b3c751fff94cab7dfb470e7 GIT binary patch literal 4306 zcmb_gc{CJW|F#rmuPh~7wu+Gu*#}vYHQC3KrD2Q_V_!zu*C?9NU=Si<7|htBWZxx> z#`d+$*hvg!o7eZ>_xJnrJ?HtHd+u}ZdG3AgKcDm5By&>(b{2jXIyyRb!-u*SbaeDG zXZ7j=;~C?BgD8JCfX$69^=LF&adEMjm>79!vA(`uPe(5^GxKbbmy65B#wIQAFwN(~AM8YljMctQxYQ)W6a9?VHQ>}RnmN>rtPKSew3i!h8CqN7utdaVkkqa&4r z=~TgB0xgIzMTidIQ2(@XCVJ8Lp`AY+9Y@E%MURx`xK2mMb=go?+cJc-iDAz9q|Oy5 z)_L*P)3(;lQyTCuf}T~U&z+AoYzX1wA86wwpQ#`wuA{|uPJ0AX=P*D|UnjC+XoZDX zZNzfrXS6DbI^0R7N*!Ciu>~?HDvX)F?MHGYI9f*nC{PkD;*KUn4yeJP`|3S)M@F~t z$}@Go1+BU6<5q`(;dCvVsE>s(BV-Vt{jxy;6IP;ZqfR4kI*vEmywumwOB_)TxpATS zf%IVPq^T09k#@;-Dz)Q>n7P>VP5Jl7-?SylPD&i4?Z@-G4ZeQVhSoU}v7g{JVJ*UAJOVt2u0~c_3vhGbD4_huvU>rJ~T0g z9chWOW!BN@-Sf4$Z4iHGtH{C0MTlr*+4KPtx9ltM_mmDj^M_fy@ef}A%AER2@V&U@ zkLl`e8gE-tYABY-wt&2ZC_Qz0mDv4q2S?K^>Xg0_Hr3~3f;H#~ z8AGA>F2;jU01ZC#<7lzP<%Kr}nr!M6#%*}R!9woyroX$n37NaS@!H}(h0)2UW?QL< zr^k<1giy5l!HQP5+?=M#gs${Ekz(Q|9VVUmz=pDv>rcHC z2CBwrqXTPGId{W98}oJgz;W zR!F(F|M?;&vq`xP`4L+>Js1;Ccv{YWq!XxUreN%@ejmO4b$^x@8^S z6IikJy<4OWceUOdEH|jI=-o(>;$zc?raaM4W7zSPlaDG-AlDqHc69X=Kt%JjQti6l zpdA?7SBsPhd;5ccysI2tnyLa~?HW^Z#}tihJ9W8f9DaV`D*sUKQl9+w*uX;X%1U4p5x;UoyVRq- ztp{9;VjiluY?z2=*2ne(qVwu7C!O(lt$3sJWhi><%0RVKbmr;Jv z*^!mx4`z-fALZ4Y*6}LCqi1G$nGc)NBbNJ?4qCTY-FHVw5L00reIT?F=_$n|3F=Ro zjCxj)2>38st5_Q%PdsfB|L_V>WKbobm=L^BnXwQEsS?_Fj@;mG4BTGnm=wn`Z{&Si9tojSV0>?YN- z0x6V&O9JM)cF$SYm*TN8qxU6KHI5@BowQ0aDg~7USwFyF*IaNMf}9_y z$0ZY{TuFRy-j9#*t6_3YBS5Ne!MtXN3NH{VFuo7|2TY(tmcJ(~#%tL99+gx!zG(Kc zvxgv%17SeWkmI5^^#HUee-=r5^C)AlX8?LCX2ZKQNAl0vDiX@Z` zPh^~=bl^r7AzgLgjLGJRlHYJsE&Wi)kX;Y%8Clv$APp>(ZD~qWKGN?i6uoR9_DMcS zq^dn_G)=~&qu|VFS)2LDpD@B(xVWyCpFn>TIfLu`;?7SUZVLj?*BB`%2vOU%j z!-?*%Q`;r|lbPoRT(2eR<`v|2T^f&(xly=xHB9$+MyaIYXqS05S8s6$!d6?++uaWt z-H#A#IxGL)Jp3@T>Dm=db6Oa_NMnanzI$ytZhp#gX ziG&tbH6CX2?wZAI>}B{izLQ;ro@&;Q-jED3#e<$^=jc|I{gAO&#A{8s)CyKDN$}XeX z=iZg}b^AFoi2I&_qPU%m;G#eQVE>HD^RnF5vvwVx+OZk=V+gdI^;xj8(gCJRX5}b8 z#nY^5qN0k+R&|~?HOZeQ0erhJ-iNImXRKW$cT0tfeZfn{8NRA~{H)eA(g>l=UN3=w zp^h+hWt2i^|#D)YyUFA`F*zD^MMA zQpuSgNhdn-dbzP*UGEyfErYpM{($0L#h<+Ve*XPH`X{$#5dfPSU-V0 z>*Xrcn<|@QYt|^Db2LBM5jni>Xj{{iV!r*vyfR1Vyb2d4(AczF2AY=gTR01cwb8M< z&HhQG6VIu!x$QqaJYV-G@|CpF0>j7Hcjp6N`9}vj1=8wLdi*dmkh>4K^4N|-tD<*B zbC-F@X5qNh)s}WYRdf<>MSqu67UJ#@&;AAmy4m06{8W+frNMjUN62h*yqj1xKPdj5 zbvvx0BmCNvZ9C}w%pm_4$Sw|pK^X}DjgV~KSp%E+0z>jzCWTTu!=8Mzf5((s%R51> z8M8@oyqWZ(F#GTu{9Dn;E=6iXtzhvy4R|6SK z@Qt=m#Gi@7J!1H@o~&@%X6%pI7qw)~si{DMQbEL~ee(}xpY}EH$k|q=ia6y2KpQl5Y|__;!9ZcIbo$BCdLem=m#r*lJU zFC825iYI&=&lNt|h{zv$X6W#~=PQ*h3tha`>^ohZ8@0mGIYhnLvV(i@;-{{KgkRjI@HR=M_g^V8oH?ON;cuBxb4CIF@(g5WgaJeRzZ_lJp^hs zD3*5x95_7@a=^7Ev}f;M>(9^dS9d#4K+Xg9(FYZY^;bdao9skKD9i`b2N(u_-d3Ur zif|HVykPsG^G;S0p^6TYdif1o7SLT;8P<2hDGlYKUB*?G#$lS9FD~e8MSP13Y-Gok zng=Ly=IkDtw100euXgccd?TDJ)X=d3#uJ7+u2&2CcR1(WOFQfiET70qFI#Mf2mA9! zwGS(}e5GOUf5f-2Fl{weLqhELqXd&(NNU(wkn_g+T}iQgy?`ryqWOW*i?_tLNL9!K zVY5RGb?X{%JLm0vJ3nQKN27_26tHUAXl$aO5(_a_r)mVv^dd^Js7JcGTlZMS6ycF! zA-_BSPy?x+;c-i00Te4GW3b1}s)U3uDMHSPYy5uw?vd!}PWmU0@Uix5hS|UJF&&)` z`{syK8MpR(U%nU5c&mHdej~rlV%{}B^_CVPH!pk*b3YtC|79QJKk)jomxqB?S8QNQND8}Kg>4(3?jJO*actc`c5nsRL2#w>y zF&J~EGUv(gs&LHVcdM^DRXx7HBoeEf0o|uVRdg~V4F7BVE;%1MeZ=zL0r1}x8)JD2 z8t8<}F<(q0jFnJ1mj=Aj%VoN*8e_;d0KS#Lvef_Rq-KX_lyz(7%oEQs5@# zt~S^tPdS?xh!zFB;%4wqYpiag(=(m7I}~-o+BE(O8E%!1|Lta_K^=U6b*Qp*rSUFQ zL)9y~h~4#Ej?VtGw-ngBnfV~hgTVuB04`w zt<1Lmi?iR-O+jTdo6fSnnJkdt2*6z|eQ2z3gOF)LrENy;QtG6{K1eo)`6>!yUu?_o z*kv9a7^>~uw&|q25Hi+&NUp4$e%^7G*ZWU6?%?^&YuUIa mRiBPkKfd&yJGOvE75?>^$Sw`I_3!TmouQtoE>`Dh^nUt=Yf5D5;1v7a!(oC!5z(bJl^o!JfeUqBqXGhLHRH;`D<NPYptf{Fv+vMfv=hxlcoxVq-FCDv{rj}D*9lz|emrdxlg)^Ry?@-Hsn7~bYA3WZdaD&gSrv93B`JA`iEPS1AnuGop|E=Z= z0(*)6MZfyS^LAy77s!q0&F;Uq{isd4E)lrWH`O0twUVseEpWKd@QS=lO!YPaBI$Y) zSsU9q@m_!|9khEA^d&lA9*)Uph!B00LJcpp7jg9l%MbT6H$85r{hWeth{-yk91}%9 z3Hr2#?m|$Cy|VEqF3gAYd{?7Ms5Tyt!Jn=@pT|85J<$E|0Q_@zGybD`)Vl>ry;z>v zhljU6#YG1yurH^H-g@7-6$L&d)y8kSsAWsV+hfwZl>2(R_sN)A_~+SKdfe2j_te|z zpD~ZmmeD5tF*>{!LcNm8JlV8n^XsG+Hdi>1z@f}p*Bu#|?n{h=O5Vyk`h0&rDmnQQ zaHf6uz81eQ8v4|zlxj6?hW=!R2qHopeJ*qzq}Pudkx+T$iISx@-K`WG>vX0g+||q` zzY?G5r>aCH(28&RK%j_dd|SumSuC%oh@W*378vL)nIV6Pk>Jq?Y@8I(DTSaFiC6=l z3dWRVQ>HZ6+frxiX*6ZFm~NPq=8%8LJNm(=OV@Rd#`Wh>XHm;~twHAZ9vqvUx}20` z+)5GR;|VBF@&9XH|AxH0)dRs_A9A5Ct_!Mz3eP%oUAC_i%X;!h3;X=<_kYYOmSn$a zTbX-+3=c}&ePP!3Q}c6vR;8ZLhx;!XZWg3r-;t>~GX~aVf<^*G zI%D9S5smPjQ$VR+ma{K4)mh&H;&2riWlLhDWP)Xk-yPFCR!-CVFqOc}6V;U8y6E27 zsI$~BB?L-v^J56oF=}WH&F&Z_pFILjrcAeRA?RM&J3B>eNv?^UdtX2*OL}N75=6)h z&36(S>Rvq}0Gztc{$5xxSU2b25ZK(0_CY1hH;f)bC2IJBoLOMUKaoP~Pf{mYR$@H; z)cfHoXJz%|m|u58XoLpO3Y`~Bz#(^qPp7NIIo$u?Gt3nxXbp(IB4~hFzm-$ek>zj- zvK>SAkK)G*x_83hwC#wazSn>b-Tw9NvIzS%$yk?Pq>Ow=#t+*JNO18X^tW$2V?G$?0fv8H1BbAB#%HI=qHy;bWYjRsKx3i(1A0z|F(EUyOp5MZcU?NikdAg3@mCuFB!T~42&R_GQl zs$HqFbx(h_3Ihof(BXwY6%awwFakpL#JSqI@zTH*7VfHyjmM3Okt#+|%<4<}6bv`I zidN-~_oIJcSk`4FxY@ATtpt~9J`K@V;|erK$KVO~Q1^ArY4OK;knxRhMQHWY`4n(j zzRoiVlxlN%HuFk`$_io^hO{$o4I>BKx~}^UMMcHpe0hhBIEBz9pMYHBofPndLF z#<^;w)jy61HMsZFRQ%2goNb@^b1;FtT?=<-gc%n?t#5@LhzMm)-zwZ$FQbWzER5jy zxJzUqEUPw9sG=e7Mi6!S*iI31LuA1jE0JtIF3DvT&Z0YzEtWv{oBi@*VL}yiQzXX5 z-`971Fkvede#PDI_TMdF#&3e=Vg%vieK=t!|N{IO!RpBi0>0!O;We%~`@_Y4L$OseG?$)k3rWAjjywIb&LWV#!G7gm?F2@4A)%4uIYc3QhfvaVQ|Y3! z!})oD$|2J8sN7bd_7diC)Z5ABn5rkR8HBu?iN1KGHCsavD3!l^4!>k?x}d-J*+3V& zD#R89a2P&zF6cB~$}a$<%}B*KTn^(-QIv`!5W{~d zU0dQ4q77NvxelEbDYe5Ug<~MZr3vUO_rMJc@GyGWWfj%cD5Oqe!$-e zYjg9bp$*Aa$gLje_!;z?@;q18^kN7Deg=yqnSD{rz|HR9R(+I4=1)hnIx(hfef=h~ zo5-?fFctD7L0-rC`}aJxnMzoMz^Njs>QWsQ3>)4Jbi6v9ArB!vvk1%oxWwrsmN7KX zU4Radzt4UP!&V#M7;rb=v^JZXEWGhZQQeIvNOww9RR z!O(lc+=_o;c7+qkm|yyBXe}?ASS78{q8Ge!OSvzDi-ph|khlvqC!iZ9UW+dB3otyT zvtRqyHLWkw-!x4Pu99$xe(UD+#1#C17|BL6G2>eXrdRj%SALIk_{7VLcQNi#XRtlY z*Bn=EH%DJZ6!yo1f$Se!9wQac7h}{(0*w^FmgW@@DjfJFR%vw5*4hPw|AlHiqIScvBI=LEoZMQEbv(EhX^pnB{f9zpqJ+(XLjWf%9n^edp+M?TyS3ztQI1$`A5ux=bgM+O;nT#!lS$qQ7c_o)iMK&A zEgKbJ{@PxuXm^BGIBIb2vX<4*ncJ*FK&nMvG{!x~l60)yb#*JLbj@geoS+VU(r~qd z;h3&c@As}MH`CjB6vdyZ-Q4n0R661Gs8-u|XAjq|Wyg}2o;UPNuw?7TufnKP(12!7 zuxNhJH}cP?Ivn?6AR#Qt0S!~1zf1KFDrIiwUCdV2SAZ^@>HBi+fvRFk_J&VZWiSK`_WpDxb(U|HDHjGvgn?$Tjb4%R2MwLY@fvI z#jT{rt4KCbH9wHWMUSmT8r_s@NNe0+jB z*RPoH@$Clq`1p4ReITXjDIm$dJk`#9~2EUq96D1-69W{(H*8mNXUC_8EZoHBy6!?I4ujr=L)#ppE@z_$w`mmZ3zg~~oGw%Hljs=mp z{tAZjAL5?)737FiFWBky#@El%R$7{Bp}|{w?Ka&T)B8^9K2vf>i+0PhZn^Cgu{h3E zTp`9zNx;I{&%LHKoTRnz-nH<%Ta57$aLsAKxh1#K!%y`TmzH4fr(JaORCirsX@DE0 zr@zzL4$Yw6t|i*4^~seS;L_Fc|A_N4c=sKud9Ttm>m{f+RmeA~=D6Qc^y_}QZetV2 znYNKo^FDrY?U_g>VOG>FN8*GJc;kYhRd)A*M__K6SAXqGtk)zoV-B?Z5@8M$QiST& zn9BD-&bPo@k3g@X;hyw}OhvZ1rk+En@~?_0^N6u;^%x1?7T!jQaMimt$?C$oE9Y#k^2&gD9N1LG|0{7v1;m0cgA(%sD#z>G2-nT~S>}GLys|YmP}b$$4%Q z5#&pN^S)0LgYF@k0rztrJ*Yg9YL4ONi%DO4VYw#7|IMiRS;Sh4#B%X${0(}^%>LaX z4Rx8%tRr-Bhb)RoCRO*)&=$k>l$Sqnd7ppg`Gc!NO8#*wxiBYu*a~QmGpt57y@`Me zu_sKuzOWC9sD9)Q0o>ZH%xj3o zCgeM_@jq{3EXkT1tj)*+xB|~xv8a*dvpHTAtods>8t3S?@VA85yRokjf7{>*@C-V> z0qxMz5f!G`K4?Ctq z6#Y-k3&mr2)QDci$oXZCQ8QPD@H`9DW9HA^g4)i;wm^LXx~2I?R_54mR1J*_W5Kyd z5hSAmZ07f?fl(`j2X=tOd%QhPyxJM+5U^WcU=Ibw&j?r9H?N69>E;pUS0R^;)jF_F zGjE3h3UOV1NH8k)Cuw1oR|8N~zS152kJ3%FYShAADaHusYHo(v7@WBU`R)wiKZ9ph zK4wZeM&;Txvf5_u4!0D?+oY{>NCDZf4>r%t8UVlRsTaY)A5ozj z#>3+N9?%u5T!}Dl7sBy^uHzQ8zp>;N6&ocO@2#6xrYpbNhN?%Dv!c^2BL-~h-?yjI zY|vc+<@$ww^tNr=P#eGkX?q+e9{sq@6kB8Xt+gQ=9<10Ln#t=tCE^k3kcE3w3&C9} z+biJkx){;7q_QwdgM{e)#mETrOXDFQePER?y9Y|S+Y$|Ss5!qNfd%)d%-z%ec?h5S zIygs_?A$eeJX+bag|^5#-GjHl9MdS@hdnVxJ?qw$jFaz3hP+JzS2(SARPxQubZ$PU zBOM=nUiyvqdqLC~>o9X{qFtX~P(kkt9*bM-TkBk66h`GA&nOcYT4}i?Xe9SgG ze}X$<2KcSmB}aleUD2G~l8tbog|Q`cg>sFy*eT``cFujt7&<3cU62L3clN$5gYj)k zQfyAEfcC6gN75OK;VQ_i_l8T*JM6}A;td^u+;7E3XkKZcHIP6maw~o); z1D18?(?B7gyn||zf$BEJd;LTd6D2EK)SCRSDvDM6{*^h=MJR zhDs!%!I_o$4ZA*yVEGh4>uZUC8_M9@D8fy4Xoz|LJsGz9P=2FXgwANJ|3p${TV>_f zo!?WZb9M8;`40&L1==r&(Y=a1T5HC)z74PV0=mRZ~LUnDWQ$XiJq|@3TkjrE>x^aeG`wC{( z4NqPysGxpteN8-#eFbx^Bj{oxGD4=CAFkoFfH8{*{GE=Cp-}BYRT-(@z_$hPa=Q)9 zV~FD@&719sY>Ger@eDM!TTDtl2fwgoR&H zXE##ZsrICFj+i!w#ADHq;PoT_lJ#7H9y>-oeBT#yhN*?c)6K7kzDq+R?Pdk2kySKw zRO63N*Jm?%_y7OKBOM>_dc1epQQV5YYzf@6DWacsM$VfQbl;dc* z9cNwvJ5!aG;BSm|w*Yd2vF8gdA*{L#p^Pq4Z>a^yAurj8RIK=-)!l0YsYPMGgL*7d zqBSP86kfhrqbWmpkuiAX7EWG+lCBJqNw5U`UdO3ncEWMG$Rv)oxE3{oMiQQe6ig@o zn`e|Sz2KDor|mZj;FP5{P=b;OK~~K-X}TZ($$&197DV;Z2#NvEc%RcmI{v!<%PM_nav8=z>o&qQUUm+$oN zmoyOM!=|4Df_Vh83oMBujWxS?r}UdNN@7lP!;a?5`&9QKlMB ztt75a0WGmZGThOt0sayh_p28Af^kOq8Sh`RKt10fq;Yd-=6PK^z(0hBf&;P<`L&r# zDmXIrnMe1VoAMy4r7J-k><&apP|3Q%&ciD`F9xa)YZGjS6|u#1g9&~*fS zM9hV*yS!MkYMyXzSm5P@cW~prAw_NVpMGo9&?a}GTt!5tvUN+NW4sNq@`+F%1zeca zrKU$rz~YtP3P=?QLE&4;laOiH_rY@ z@PFICb-7ij-ratjTj=?|kDZ&M@JE+4tB=P4K3-1q*MWZt|35=yeV{BPkI8YFCxc82 z99VvFwCHJn8H&L4H&@U!3kc7KyUxV**7+6ETSzqKR=|pZ+ahZ&t=a}}A8}IYyb2V{ z^|Dr@g+59LKU}7pG*7PVG zUql;i=>5)-x_5ItzYZj1*kQP@qs4IZ;8%_G6H`R>YJ^)s*qO7qr9F_M#dl_uhXuv+ z63~gF%LWLJZLEQFj0-kdl8?;+_CT5P22>Bfnyboz69(D>JL>wEgUJZh4*48s`!xs} zWJvR3eqyGv>vxz4c^Pb_4mF1?P+RVXi)uZ-pk2KmJA13jzPa(1(H&4 zcNDarBiPC)Onzj9RUq=E7`7FYhlS(qOJa&8WBc`v{1mJMR0kc_^Da4WsH?3+$`MtU z)RTJxz8%MPcThZofYnS7<&QT^FzclqToOVx6J)Z*XWP_%Gw+iFg+g33!l>HXi^}b; z+ZD1%hDF?+$EXr`M^V>Gv~a2o<*E;iy^Eui*o%JUeOm8nst0Qbik;q*79=nlvQG-h zsIpSaf)m7q^~*=baPoLtSvg1bMEzukXg9g?``C2_fhrw+nL?mkGDBt%`BO3+PX&cd=)5UYw+%c&q(Q} zZ|MfIC?>s#x z60#5vK|U;>6#uLLb^<@7I<=3)u;+sK|CSKO7-IW_&yzcawhsO|U+1d9m12xT#J>QI C=^elT diff --git a/static/ca600c1fe96166b67e6fe37b5f5dcc89/2e4ba/11_3_1.webp b/static/ca600c1fe96166b67e6fe37b5f5dcc89/2e4ba/11_3_1.webp deleted file mode 100644 index 832a17ecfc90765ec66718a2df3ab5c5d471e456..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6528 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 diff --git a/static/ca600c1fe96166b67e6fe37b5f5dcc89/81c8e/11_3_1.png b/static/ca600c1fe96166b67e6fe37b5f5dcc89/81c8e/11_3_1.png deleted file mode 100644 index 3d3391ebf8789bc170abd5969250b68dc513a37c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2169 zcmV-<2!{8GP)-sxr>E4^)V{vH9UUD~$%s)=QHzUpMzez+vRCwC$oC$ZUED(lSWLHFj;Fk3N|I6k)^X{5oB?D83qVm(QBl#KiT@uMG3N+y9=|Zp0&y#TVw_E2J>d7=5j=r;&i{Qr zVSvKc%OUhW{1e{BcD4Y708o!69FRvLpq~5u*>miD2!QvVhk&sEwLv=#9`ttVC+qDz z`+2t3+VwNoImDmBY^N~I*7v{Fwb=F(u)Pn#`f2cfp8GH(JBPma7WX#vv+rjc_k#(8 zU)(nPskeRTr`ZPECrrO$+S&GVB%N&^F~hI*Ciff!Co*iqIU*DUm4mPgRJ!jKD=_Eh-6IOV8*Sh zC1c8sAz{j^F=ICIyUG6^y1ZA)bclp{HL$ZGVy-{0hITdNi+&0w*<(Vo!@O>-UNYA%ld#D<*{UVxS$AByPyFp-l!R^F==%Q^3|4C^wiAcJ2~G8PjPZZ!n#K zP-SEGrW&j2pt3t7CUkUB2r0N?N}}}AIuw6Z#AJ{n)v;Q~izG~_krFjk@F6Du!8T^oaSEmzDMsTZdd%2XX>lyZGC zDV}oB8Vcx1;rp1Fr!;073UeR&7;c>S~GJ?6AUD!@HQux#Jdd=`gLYm`K&N=G~=j8lVi-7{PN-t2Ll64}vygPQ%cH z1RI4WK3V%j(01z5;iR?+Po3&EJ*|YsQFz-nm4Q&xO&4?+tLAvT_OwtN(&h1T?SeEV zLYeH|h^dv*^(kFs#dMkxsvidJ5bOjv4|c|Y0~?UF1G?wVgefIqLT0f}Ga-Z|@+_gH z6mWs!VxaMpFd;}bibKthv!oSq%9M$u89yZTC#yGL<*SB z5#)|HZS-c`8xR2V(0kw?w#^gSYLRrgG1QROw+2GV&hYvvNZy{aP_{RSWoPJa4X5`o zdjxnNz@?|{``H5=9t5qUJE^}gj5|GXihgK#;Gchf;&}Gsbt3r$cA0M$6%`c~6&2lo zI`|ls`}#dXYA5%~aNNl~KINx{Y@CSITR~dyL|-SHm+gLXqV3H^$jN-^qx+L7uXVP3 zokib@HhHp~Cd?_J)iNQZ5bHStQUg~*z63O%?VJ^hKRGX3)6uz#uu03tG=*4G@3gt` zWyFMxq+E2)9207wglir-89o!!V*tFr`q77!(R?O>i49>c11C(0Xsr;=mW1gJ)rin| z#)KN9mendHA0sBw*tIo9pN<)mB=e9{dpKnhV!ErJo=ae!G-x-NnATm(=@kgXgh1Z@orjlun*^D`kRdYzW*o;ZFrsQPeoyeF* zQ3hN3B|RZi9=Px->P~51~Vkg?%DnA}<1gY5>J{|MV?+f1PmEmtx<_bkcMMXtLMMXtLMMdvV z#7ZgX-|;0tdM9-}>~vK7W6&>KWyOJdA$1)KJtS9qPVKla4UOis?#_ph7yXTxxiZA} zO%L455Ur&mD20S9uZ=WgegPpBhSJw);#x{5B!jsWMAXmo=G_HtIe{rm2boFBz9lhf z9d~kRlix)c4Pl*WA?wWg^29e{;t&(hF+scS4}DB&a?kI1Gp3^#m5U1rvl<;fR@H%@ zF(ILd(-Y-+74SD=@@W__K*RP`e-8XwZNT?2x#@T=E@aH6I-qLgIM*{rL!|7m{sEYr zV>Ea$rA6S=GzB|N761(90r=rDCPa?wGiFm&?%22^z67nPH89Ih@FwU7U~R(8f0o0} z(K=Z$&5toj=Muw;dBD|(9T+d(>}sTbLeK&n*SZfWMkl*^GqHzZt$N5tw}GgNtiIlaZD=?&X}ytJ+1ie0fnc^ zP^!#tdfNEsbFLMnH!&9mVGSXvVN(6p<3Y{HLSQ-$LdX{N`<{YCd!x>byV6iI((d*c vp?=+x`ZuN@`0i$zp%fJr6%`c~{dWBau;{+l6f9eO00000NkvXXu0mjfMHw8p diff --git a/static/ca600c1fe96166b67e6fe37b5f5dcc89/a0b58/11_3_1.webp b/static/ca600c1fe96166b67e6fe37b5f5dcc89/a0b58/11_3_1.webp deleted file mode 100644 index 4759d899b81b361ffcda650d6c097d0a64ac989d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1718 zcmV;n21)r+Nk&Gl1^@t8MM6+kP&go>1^@uiBmkWOD&_!W06x)Tt4}B;q#`O2`KbUJ z31e>EUqLpdfe!a7IX|i$xxDYYuU@ZPxj8BxYU%;ueSV%L&+lfx3zPHM-l9GF=a<6A z=$@dTlRXNw67{FBhe;nta~mPCT1vxjrMLHJX!`xNG~h({q&nv_U{C^-&+zo!3VkW> z#b0x@As_8$x}oPjPlZUA94fd()I=I1%p80T;FF@7h>>($ncsuT9ac&lNeIb$&xJv# zVHNFPqY6(7e`pom0An7D?cT$*fdBYR$0PlD12(t$i8<*^&6iDVO!!;mq)O|7whR$aFFl<-ue zVbzD^+ByjT?bb1;kgiO((^{02-$o!Ml07h0tU;>_o7eDv`a?Lu??-@7GRp)Bu zL5UpY)e?L;ZoMn{h2(k1IVw_K2(D!R%;DV%ZK049#7SOWZ;ickfR0}-W-2v1RW*>x zef`+nbf=8j_P|6?arXu+itE|SZEw9ckhA{n=xL>B70AYsy_TXdMy8Xu#Vo(H^Q&Fy%&qTICtd9h%OEj7n_EcAJ!hL0W%y#8UGLE;qiI<4*XFhCxysmSqO z#v!vIS_jS?1X>AB^_>N!A8g2@zX-# zu0}Hc5fJ0-&^s{rrt6FNmG52P4TT*8cDxbMAlT?3;e;Sjt2%jl^WPqN0m!}uZxcHB z{C)U@bhCsbh2u~ z?GkmcDqcm*rMR5xQ7;YW&XXim*S;k-v!$HrNb?;a-SV1gFk@U`L2eLYN=H8Xk>lAV zeg{{~VZheGVSqAS+GzLG=r;2_SQuC8A%n`uwQ@$c;4zs>{9!51RgG<12xr%Om>-j@ zC);_^c4m&N*~NGgZ!EP0g)ij^85ry5WDG?<@DJ(020^#6Jb~4@!^dTl5!w(@{n~c~ zbJGrjJ>_*>Ub%mPnBepWY@)FAmNI{(fL$VQ>WQDjS0M=61?G;Fp~(0J{gWyxgk(i? z*ePX+03B`raS?0eBBcHo{HH54?%nziHJq@tbC#F7jL)+2#GHG_a7)o6GA&zT-4OXn zy)I5KSZwzj^WTIS#+c4mM;CRk13KFGwN-hKmeDX=`bq;x_3k6a7mnR>n|&KRlB&n* z-Ro1+5ijE_Z$-J0#uwJ0pAY+KO=1JKWL{u?oFL3mJhg$!tmyb#G4AY_D^j3 MPL^)^000000M`gyp8x;= diff --git a/static/ca600c1fe96166b67e6fe37b5f5dcc89/bc10c/11_3_1.webp b/static/ca600c1fe96166b67e6fe37b5f5dcc89/bc10c/11_3_1.webp deleted file mode 100644 index c1136b5735c87c91da0a61577e5e72f2017fd12a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3786 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 AA^-pY diff --git a/tuki/index.html b/tuki/index.html index f8e219a8a..a0a5f789b 100644 --- a/tuki/index.html +++ b/tuki/index.html @@ -222,4 +222,4 @@

    Discord on viestintäsovellus, josta saat lisätietoa täältä.

    Löydät kurssin kanavat täältä.

    -

    Ohjausaikana ohjaaja päivystää kurssikanavilla ja vastaa myös yksityisviesteihin. Discordissa käydään keskustelua kurssista myös ohjausaikojen ulkopuolella, joten sinne kannattaa liittyä!

    \ No newline at end of file +

    Ohjausaikana ohjaaja päivystää kurssikanavilla ja vastaa myös yksityisviesteihin. Discordissa käydään keskustelua kurssista myös ohjausaikojen ulkopuolella, joten sinne kannattaa liittyä!

    \ No newline at end of file diff --git a/usein-kysytyt-kysymykset/index.html b/usein-kysytyt-kysymykset/index.html index ff7d097d7..062896ac2 100644 --- a/usein-kysytyt-kysymykset/index.html +++ b/usein-kysytyt-kysymykset/index.html @@ -163,4 +163,4 @@

    Kela haluaa minulta todistuksen opiskelustani

    Ohjaa Kela tälle sivulle:

    Ohjelmoinnin perusteet on kaikille avoin ja ilmainen verkkokurssi. Kurssin käymistä voi verrata kirjan lainaamiseen kirjastosta. Kirjastosta lainattava kirja saattaa liittyä johonkin yliopisto-opintoihin liittyvään kurssiin. Aivan samalla tavalla kuin kirjastosta lainattava kirja, verkkokurssimme on luettavissa huvin ja itsensä sivistämisen vuoksi tai yliopisto-opintojen edistämiseksi.

    -

    Ohjelmoinnin perusteet vastaa Helsingin yliopiston 5 opintopisteen kurssia. Kurssin suorittajat eivät kuitenkaan automaattisesti ole Helsingin yliopiston opiskelijoita, emmekä pakota ketään suorittamaan kurssia opintopisteisiin johtavassa muodossa. Kurssin suorittamisesta voi kuitenkin halutessaan saada opintopisteitä. Kurssille osallistuminen ei oikeuta opintotukeen.

    \ No newline at end of file +

    Ohjelmoinnin perusteet vastaa Helsingin yliopiston 5 opintopisteen kurssia. Kurssin suorittajat eivät kuitenkaan automaattisesti ole Helsingin yliopiston opiskelijoita, emmekä pakota ketään suorittamaan kurssia opintopisteisiin johtavassa muodossa. Kurssin suorittamisesta voi kuitenkin halutessaan saada opintopisteitä. Kurssille osallistuminen ei oikeuta opintotukeen.

    \ No newline at end of file diff --git a/verkkotentti-ohja/index.html b/verkkotentti-ohja/index.html index ac2fc6df8..eb26ea566 100644 --- a/verkkotentti-ohja/index.html +++ b/verkkotentti-ohja/index.html @@ -192,4 +192,4 @@
  • Tenttivastaukset tarkistetaan plagoinnintunnistusohjelmalla. Huijaus johtaa aina vähintään tenttisuorituksen hylkäämiseen, mahdollisesti myös kurssilta poistamiseen.
  • Tenttikysymykset muistuttavat kurssimateriaalin tehtäviä - tenttiin valmistautumiseksi kannattaa siis kertailla materiaalia.
  • Kurssin tulokset tulevat kokeen jälkeen sähköpostitse opintopisteohjeiden kera.
  • -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/verkkotentti-ohpe/index.html b/verkkotentti-ohpe/index.html index 6b3753724..6d973130a 100644 --- a/verkkotentti-ohpe/index.html +++ b/verkkotentti-ohpe/index.html @@ -192,4 +192,4 @@
  • Tenttivastaukset tarkistetaan plagoinnintunnistusohjelmalla. Huijaus johtaa aina vähintään tenttisuorituksen hylkäämiseen, mahdollisesti myös kurssilta poistamiseen.
  • Tenttikysymykset muistuttavat kurssimateriaalin tehtäviä - tenttiin valmistautumiseksi kannattaa siis kertailla materiaalia.
  • Kurssin tulokset tulevat kokeen jälkeen sähköpostitse opintopisteohjeiden kera.
  • -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/verkkotentti/index.html b/verkkotentti/index.html index 744eee96b..2129444c7 100644 --- a/verkkotentti/index.html +++ b/verkkotentti/index.html @@ -192,4 +192,4 @@
  • Tenttivastaukset tarkistetaan plagoinnintunnistusohjelmalla. Huijaus johtaa aina vähintään tenttisuorituksen hylkäämiseen, mahdollisesti myös kurssilta poistamiseen.
  • Tenttikysymykset muistuttavat kurssimateriaalin tehtäviä - tenttiin valmistautumiseksi kannattaa siis kertailla materiaalia.
  • Kurssin tulokset tulevat kokeen jälkeen sähköpostitse opintopisteohjeiden kera.
  • -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/virheilmoitukset/index.html b/virheilmoitukset/index.html index 08ca6e44e..c043155be 100644 --- a/virheilmoitukset/index.html +++ b/virheilmoitukset/index.html @@ -172,4 +172,4 @@

    print(ika//2) # virhe: muuttujaa ika ei ole muutettu kokonaisluvuksi

    TypeError: cannot concatenate 'str' and 'int' objects on line [rivinumero]

    -

    Katso ylempi kohta.

    \ No newline at end of file +

    Katso ylempi kohta.

    \ No newline at end of file

    Discord