From 41aec0f26e47caf84e662a69c054fa53367cd599 Mon Sep 17 00:00:00 2001 From: Aubert <sindreaubert@gmail.com> Date: Thu, 3 Sep 2020 14:04:48 +0200 Subject: [PATCH] =?UTF-8?q?endre=20overskrift=20p=C3=A5=20notebooks=20for?= =?UTF-8?q?=20of2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ovingsforelesninger/felles/lecture2.ipynb | 378 +++++++++---------- Ovingsforelesninger/felles/lecture2_lf.ipynb | 2 +- 2 files changed, 190 insertions(+), 190 deletions(-) diff --git a/Ovingsforelesninger/felles/lecture2.ipynb b/Ovingsforelesninger/felles/lecture2.ipynb index 31eedc1..10f701b 100644 --- a/Ovingsforelesninger/felles/lecture2.ipynb +++ b/Ovingsforelesninger/felles/lecture2.ipynb @@ -1,91 +1,93 @@ { - "nbformat":4, - "nbformat_minor":0, + "nbformat": 4, + "nbformat_minor": 0, "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 + "kernelspec": { + "display_name": "Python 3.8.3 64-bit", + "language": "python", + "name": "python_defaultSpec_1599133712327" + }, + "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.8.3-final" + } }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.7" - } - }, - - "cells":[ + "cells": [ { - "cell_type":"markdown", - "metadata":{ - "id":"ABwzbFFnFcxI", - "colab_type":"text" + "cell_type": "markdown", + "metadata": { + "id": "ABwzbFFnFcxI", + "colab_type": "text" }, - "source":[ - "# Øvingsforelesning 2 Parallell 3" + "source": [ + "# Øvingsforelesning 2" ] }, { - "cell_type":"markdown", - "metadata":{ - "id":"n_CAYoW3FcxM", - "colab_type":"text" + "cell_type": "markdown", + "metadata": { + "id": "n_CAYoW3FcxM", + "colab_type": "text" }, - "source":[ + "source": [ "## Oppgave 1: Repetisjon" ] }, { - "cell_type":"markdown", - "metadata":{ - "id":"jY0bZrvfFcxN", - "colab_type":"text" + "cell_type": "markdown", + "metadata": { + "id": "jY0bZrvfFcxN", + "colab_type": "text" }, - "source":[ + "source": [ "Hva blir resten når $2^7$ deles på $42$ \n" ] }, { - "cell_type":"code", - "metadata":{ - "id":"Y2LnvdZXFcxO", - "colab_type":"code", - "colab":{ - - } + "cell_type": "code", + "metadata": { + "id": "Y2LnvdZXFcxO", + "colab_type": "code", + "colab": {}, + "tags": [] }, - "source":[ - "# Skriv koden din her" + "source": [ + "print(2**7%42)" ], - "execution_count":null, - "outputs":[ - + "execution_count": 4, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "2\n" + } ] }, { - "cell_type":"markdown", - "metadata":{ - "id":"va7oTh_RFcxV", - "colab_type":"text" + "cell_type": "markdown", + "metadata": { + "id": "va7oTh_RFcxV", + "colab_type": "text" }, - "source":[ + "source": [ "## Oppgave 2: Input" ] }, { - "cell_type":"markdown", - "metadata":{ - "id":"JJysiWeNFcxW", - "colab_type":"text" + "cell_type": "markdown", + "metadata": { + "id": "JJysiWeNFcxW", + "colab_type": "text" }, - "source":[ + "source": [ "**Lag et program som gjør følgende:**\n", "1. Tar inn to tall fra bruker\n", "2. Multipliserer dem \n", @@ -93,39 +95,38 @@ ] }, { - "cell_type":"code", - "metadata":{ - "id":"E6Lw86E_FcxX", - "colab_type":"code", - "colab":{ - - } + "cell_type": "code", + "metadata": { + "id": "E6Lw86E_FcxX", + "colab_type": "code", + "colab": {} }, - "source":[ - "# Skriv koden din her" + "source": [ + "tall1 = int(input('Tall 1: '))\n", + "tall2 = int(input('Tall 2: '))\n", + "resultat = tall1 * tall2\n", + "print(tall1, '*', tall2, '=', resultat)\n" ], - "execution_count":null, - "outputs":[ - - ] + "execution_count": 22, + "outputs": [] }, { - "cell_type":"markdown", - "metadata":{ - "id":"ef0TagFtFcxi", - "colab_type":"text" + "cell_type": "markdown", + "metadata": { + "id": "ef0TagFtFcxi", + "colab_type": "text" }, - "source":[ + "source": [ "## Oppgave 3: Innebygde funksjoner " ] }, { - "cell_type":"markdown", - "metadata":{ - "id":"cDRLg335Fcxj", - "colab_type":"text" + "cell_type": "markdown", + "metadata": { + "id": "cDRLg335Fcxj", + "colab_type": "text" }, - "source":[ + "source": [ "Skriv et program som spør brukeren om to tall og printer absoluttverdien av differansen\n", "<br>\n", "\n", @@ -133,125 +134,117 @@ ] }, { - "cell_type":"code", - "metadata":{ - "id":"8Q6Thg0NFcxk", - "colab_type":"code", - "colab":{ - - } + "cell_type": "code", + "metadata": { + "id": "8Q6Thg0NFcxk", + "colab_type": "code", + "colab": {} }, - "source":[ - "# Skriv koden din her" + "source": [ + "tall1 = float(input('Tall 1: '))\n", + "tall2 = float(input('Tall 2: '))\n", + "print(abs(tall1-tall2))\n" ], - "execution_count":null, - "outputs":[ - - ] + "execution_count": 22, + "outputs": [] }, { - "cell_type":"markdown", - "metadata":{ - - }, - "source":[ + "cell_type": "markdown", + "metadata": {}, + "source": [ "## Oppgave 4: Feilretting og variabeltyper" ] }, { - "cell_type":"markdown", - "metadata":{ - - }, - "source":[ + "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":{ - + "cell_type": "code", + "execution_count": 11, + "metadata": { + "tags": [] }, - "outputs":[ + "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'" - ] + "output_type": "stream", + "name": "stdout", + "text": "Totalsummen for varene er 49.0\n" } ], - "source":[ + "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", + "total_sum = banan_pris + float(melk_pris) + havregryn_pris\n", "\n", - "print('Totalsummen for varene er ' + total_sum)" + "print('Totalsummen for varene er ' + str(total_sum))" ] }, { - "cell_type":"markdown", - "metadata":{ - "id":"Klt9XugLFcxp", - "colab_type":"text" + "cell_type": "markdown", + "metadata": { + "id": "Klt9XugLFcxp", + "colab_type": "text" }, - "source":[ + "source": [ "## Oppgave 5: Moduler " ] }, { - "cell_type":"markdown", - "metadata":{ - "id":"qOrc_5xRFcxq", - "colab_type":"text" + "cell_type": "markdown", + "metadata": { + "id": "qOrc_5xRFcxq", + "colab_type": "text" }, - "source":[ + "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":{ - - } + "cell_type": "code", + "metadata": { + "id": "mWSU4YS0Fcxr", + "colab_type": "code", + "colab": {}, + "tags": [] }, - "source":[ - "# Skriv koden din her" + "source": [ + "import math\n", + "print(round(math.pi,10))" ], - "execution_count":null, - "outputs":[ - + "execution_count": 18, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "3.1415926536\n" + } ] }, { - "cell_type":"markdown", - "metadata":{ - "id":"iSUDNvFEFcxx", - "colab_type":"text" + "cell_type": "markdown", + "metadata": { + "id": "iSUDNvFEFcxx", + "colab_type": "text" }, - "source":[ + "source": [ "## Oppgave 6: Bruk av variabler" ] }, { - "cell_type":"markdown", - "metadata":{ - "id":"VN3hLGTMFcxy", - "colab_type":"text" + "cell_type": "markdown", + "metadata": { + "id": "VN3hLGTMFcxy", + "colab_type": "text" }, - "source":[ + "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", @@ -262,59 +255,66 @@ ] }, { - "cell_type":"code", - "metadata":{ - "id":"uFf7GC9kFcx0", - "colab_type":"code", - "colab":{ - - } + "cell_type": "code", + "metadata": { + "id": "uFf7GC9kFcx0", + "colab_type": "code", + "colab": {}, + "tags": [] }, - "source":[ - "# Skriv koden din her" + "source": [ + "PI = 3.14\n", + "r = 3\n", + "h = 7\n", + "V = (PI*r**2*h)/3\n", + "print(V)" ], - "execution_count":null, - "outputs":[ - + "execution_count": 19, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "65.94000000000001\n" + } ] }, { - "cell_type":"markdown", - "metadata":{ - "id":"0fvSuRO8Fcxb", - "colab_type":"text" + "cell_type": "markdown", + "metadata": { + "id": "0fvSuRO8Fcxb", + "colab_type": "text" }, - "source":[ + "source": [ "## Oppgave 7: Variabler og input " ] }, { - "cell_type":"markdown", - "metadata":{ - "id":"yaeIkT16Fcxc", - "colab_type":"text" + "cell_type": "markdown", + "metadata": { + "id": "yaeIkT16Fcxc", + "colab_type": "text" }, - "source":[ + "source": [ "1. Endre kjegleprogrammet fra oppgave 6 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":{ - - } + "cell_type": "code", + "metadata": { + "id": "HSlztl41Fcxd", + "colab_type": "code", + "colab": {} }, - "source":[ - "# Skriv koden din her" + "source": [ + "PI = 3.14\n", + "r = float(input('Radius: '))\n", + "h = float(input('Høyde: '))\n", + "V = (PI*r**2*h)/3\n", + "print(V)" ], - "execution_count":null, - "outputs":[ - - ] + "execution_count": 21, + "outputs": [] } ] } \ No newline at end of file diff --git a/Ovingsforelesninger/felles/lecture2_lf.ipynb b/Ovingsforelesninger/felles/lecture2_lf.ipynb index 96cdca4..10f701b 100644 --- a/Ovingsforelesninger/felles/lecture2_lf.ipynb +++ b/Ovingsforelesninger/felles/lecture2_lf.ipynb @@ -28,7 +28,7 @@ "colab_type": "text" }, "source": [ - "# Øvingsforelesning 2 Parallell 3" + "# Øvingsforelesning 2" ] }, { -- GitLab