From 30fc32f5ba727b11989e29f5d76bf2f762bd183a Mon Sep 17 00:00:00 2001 From: Aubert <sindreaubert@gmail.com> Date: Wed, 26 Aug 2020 14:24:24 +0200 Subject: [PATCH] legg til LF for OF1 --- Ovingsforelesninger/sindre/lecture1.ipynb | 6 +- Ovingsforelesninger/sindre/lecture1_lf.ipynb | 254 +++++++++++++++++++ 2 files changed, 257 insertions(+), 3 deletions(-) create mode 100644 Ovingsforelesninger/sindre/lecture1_lf.ipynb diff --git a/Ovingsforelesninger/sindre/lecture1.ipynb b/Ovingsforelesninger/sindre/lecture1.ipynb index 4c6a72d..af104e1 100644 --- a/Ovingsforelesninger/sindre/lecture1.ipynb +++ b/Ovingsforelesninger/sindre/lecture1.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Øvingsforelesning 1 - Parallel 1" + "# Øvingsforelesning 1 - TDT4110 Parallell 1" ] }, { @@ -38,7 +38,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -181,4 +181,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} +} \ No newline at end of file diff --git a/Ovingsforelesninger/sindre/lecture1_lf.ipynb b/Ovingsforelesninger/sindre/lecture1_lf.ipynb new file mode 100644 index 0000000..230ae74 --- /dev/null +++ b/Ovingsforelesninger/sindre/lecture1_lf.ipynb @@ -0,0 +1,254 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Øvingsforelesning 1 Løsningsforslag- TDT4110 Parallell 1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Læremål**:\n", + "\n", + "* Bli introdusert til hva programmering er\n", + "\n", + "* Grunnleggende syntaks\n", + "\n", + "* Utføre enkle utregninger i Python\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Oppgave 1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Regn ut følgende i Python ved hjelp av kode**\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "-5" + }, + "metadata": {}, + "execution_count": 5 + } + ], + "source": [ + "print(4*-2-(2+-5))" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "-2" + }, + "metadata": {}, + "execution_count": 2 + } + ], + "source": [ + "print(-2--2-2)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "3" + }, + "metadata": {}, + "execution_count": 4 + } + ], + "source": [ + "print(5-2**(-1*-1))" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "240" + }, + "metadata": {}, + "execution_count": 6 + } + ], + "source": [ + "print(-(1*1*2*3*5*-8))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Oppgave 2" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Hva tilsvarer 80 grader celsius i Fahrenheit?**\n", + "$$F = \\frac{9}{5}Celsius + 32$$" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": true, + "tags": [] + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "176.0\n176.0\n80 grader celcius tilsvarer 176.0 grader fahrenheit\n" + } + ], + "source": [ + "#Rett frem\n", + "print(9/5*80+32)\n", + "\n", + "#Ved hjelp av variabel\n", + "degrees_celcius = 80\n", + "F = (9/5)*degrees_celcius + 32\n", + "print(F)\n", + "\n", + "#Bonus: Omregningen kan også skrives ut som en setning\n", + "print(f'{degrees_celcius} grader celcius tilsvarer {F} grader fahrenheit')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Oppgave 3" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Hva returneres ved å regne ut følgende uttrykk i Python?** $$\\frac{7!}{5!-3}$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*Merk at 7! er fakultetet av 7 og kan skrives som $ 7! = 7*6*5*4*3*2*1$*" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": true, + "tags": [] + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "43.07692307692308\n43.07692307692308\n" + } + ], + "source": [ + "# Rett frem\n", + "print((7*6*5*4*3*2*1)/((5*4*3*2*1)-3))\n", + "\n", + "# Bonus: ved hjelp av math-modulen\n", + "import math\n", + "print(math.factorial(7)/(math.factorial(5)-3))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Oppgave 4 " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Er 1000 000 000 større enn $2^{30}$?**" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "False\n" + } + ], + "source": [ + "print(1000000000 > 2**30)" + ] + } + ], + "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" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} \ No newline at end of file -- GitLab