From af0a5fcf392aecdc6200de5a38971bb483ff158f Mon Sep 17 00:00:00 2001 From: Aubert <sindreaubert@gmail.com> Date: Thu, 27 Aug 2020 21:08:48 +0200 Subject: [PATCH] Legg til of2 i felles --- Ovingsforelesninger/felles/lecture2.ipynb | 320 ++++++++++++++++++++++ 1 file changed, 320 insertions(+) create mode 100644 Ovingsforelesninger/felles/lecture2.ipynb diff --git a/Ovingsforelesninger/felles/lecture2.ipynb b/Ovingsforelesninger/felles/lecture2.ipynb new file mode 100644 index 0000000..0ffd3bf --- /dev/null +++ b/Ovingsforelesninger/felles/lecture2.ipynb @@ -0,0 +1,320 @@ +{ + "nbformat":4, + "nbformat_minor":0, + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.7" + } + }, + + "cells":[ + { + "cell_type":"markdown", + "metadata":{ + "id":"ABwzbFFnFcxI", + "colab_type":"text" + }, + "source":[ + "# Øvingsforelesning 2 Parallell 3" + ] + }, + { + "cell_type":"markdown", + "metadata":{ + "id":"n_CAYoW3FcxM", + "colab_type":"text" + }, + "source":[ + "## Oppgave 1: Repetisjon" + ] + }, + { + "cell_type":"markdown", + "metadata":{ + "id":"jY0bZrvfFcxN", + "colab_type":"text" + }, + "source":[ + "Hva blir resten når $2^7$ deles på $42$ \n" + ] + }, + { + "cell_type":"code", + "metadata":{ + "id":"Y2LnvdZXFcxO", + "colab_type":"code", + "colab":{ + + } + }, + "source":[ + "# Skriv koden din her" + ], + "execution_count":null, + "outputs":[ + + ] + }, + { + "cell_type":"markdown", + "metadata":{ + "id":"va7oTh_RFcxV", + "colab_type":"text" + }, + "source":[ + "## Oppgave 2: Input" + ] + }, + { + "cell_type":"markdown", + "metadata":{ + "id":"JJysiWeNFcxW", + "colab_type":"text" + }, + "source":[ + "**Lag et program som gjør følgende:**\n", + "1. Tar inn to tall fra bruker\n", + "2. Multipliserer dem \n", + "3. Skriver ut (tall 1) \\* (tall 2) = (resultat)" + ] + }, + { + "cell_type":"code", + "metadata":{ + "id":"E6Lw86E_FcxX", + "colab_type":"code", + "colab":{ + + } + }, + "source":[ + "# Skriv koden din her" + ], + "execution_count":null, + "outputs":[ + + ] + }, + { + "cell_type":"markdown", + "metadata":{ + "id":"ef0TagFtFcxi", + "colab_type":"text" + }, + "source":[ + "## Oppgave 3: Innebygde funksjoner " + ] + }, + { + "cell_type":"markdown", + "metadata":{ + "id":"cDRLg335Fcxj", + "colab_type":"text" + }, + "source":[ + "Skriv et program som spør brukeren om to tall og printer absoluttverdien av differansen\n", + "<br>\n", + "\n", + "Hint: Bruk den innebygde funksjonen **abs()**" + ] + }, + { + "cell_type":"code", + "metadata":{ + "id":"8Q6Thg0NFcxk", + "colab_type":"code", + "colab":{ + + } + }, + "source":[ + "# Skriv koden din her" + ], + "execution_count":null, + "outputs":[ + + ] + }, + { + "cell_type":"markdown", + "metadata":{ + + }, + "source":[ + "## Oppgave 4: Feilretting og variabeltyper" + ] + }, + { + "cell_type":"markdown", + "metadata":{ + + }, + "source":[ + "Følgende program skal regne ut og printe summen av prisen på tre varer. Prisene er lagret som forskjellige variabeltyper. Undersøk feilmeldingene og rett koden slik at den skriver ut riktig totalsum." + ] + }, + { + "cell_type":"code", + "execution_count":3, + "metadata":{ + + }, + "outputs":[ + { + "output_type":"error", + "ename":"TypeError", + "evalue":"unsupported operand type(s) for +: 'float' and 'str'", + "traceback":[ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m<ipython-input-3-9df7f0deb4bb>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mhavregryn_pris\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m15\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 5\u001b[1;33m \u001b[0mtotal_sum\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mbanan_pris\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mmelk_pris\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mhavregryn_pris\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 6\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'Totalsummen for varene er '\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mtotal_sum\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'float' and 'str'" + ] + } + ], + "source":[ + "banan_pris = 10.50\n", + "melk_pris = '23.50'\n", + "havregryn_pris = 15\n", + "\n", + "total_sum = banan_pris + melk_pris + havregryn_pris\n", + "\n", + "print('Totalsummen for varene er ' + total_sum)" + ] + }, + { + "cell_type":"markdown", + "metadata":{ + "id":"Klt9XugLFcxp", + "colab_type":"text" + }, + "source":[ + "## Oppgave 5: Moduler " + ] + }, + { + "cell_type":"markdown", + "metadata":{ + "id":"qOrc_5xRFcxq", + "colab_type":"text" + }, + "source":[ + "Print pi med 10 desimaler <br>\n", + "\n", + "Hint: import math, math.pi, round()" + ] + }, + { + "cell_type":"code", + "metadata":{ + "id":"mWSU4YS0Fcxr", + "colab_type":"code", + "colab":{ + + } + }, + "source":[ + "# Skriv koden din her" + ], + "execution_count":null, + "outputs":[ + + ] + }, + { + "cell_type":"markdown", + "metadata":{ + "id":"iSUDNvFEFcxx", + "colab_type":"text" + }, + "source":[ + "## Oppgave 6: Bruk av variabler" + ] + }, + { + "cell_type":"markdown", + "metadata":{ + "id":"VN3hLGTMFcxy", + "colab_type":"text" + }, + "source":[ + "1. Regn ut volumet av en kjegle med radius r = 3 og høyde = 7 <br>\n", + "$$ V = \\frac{\\pi r^2h}{3}$$\n", + "\n", + "Hint til variabler:\n", + "* pi = 3.14\n", + "* r = 3\n", + "* h = 7" + ] + }, + { + "cell_type":"code", + "metadata":{ + "id":"uFf7GC9kFcx0", + "colab_type":"code", + "colab":{ + + } + }, + "source":[ + "# Skriv koden din her" + ], + "execution_count":null, + "outputs":[ + + ] + }, + { + "cell_type":"markdown", + "metadata":{ + "id":"0fvSuRO8Fcxb", + "colab_type":"text" + }, + "source":[ + "## Oppgave 7: Variabler og input " + ] + }, + { + "cell_type":"markdown", + "metadata":{ + "id":"yaeIkT16Fcxc", + "colab_type":"text" + }, + "source":[ + "1. Endre kjegleprogrammet fra oppgave 5 til å ta inn radius og høyde fra brukeren\n", + "2. Verdiene skal være av typen float " + ] + }, + { + "cell_type":"code", + "metadata":{ + "id":"HSlztl41Fcxd", + "colab_type":"code", + "colab":{ + + } + }, + "source":[ + "# Skriv koden din her" + ], + "execution_count":null, + "outputs":[ + + ] + } + ] +} \ No newline at end of file -- GitLab