{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Einleitung" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Die Einrückung ist wichtig:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ja, das ist kleiner\n", "basta\n" ] } ], "source": [ "i = 41\n", "if i < 42:\n", " print('ja, das ist kleiner')\n", " print('basta')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Datatypes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Numbers" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Integer Numbers" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "i = 1234" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1234\n" ] } ], "source": [ "print(i)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1234" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "i" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Decimal" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1234" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1234" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1234" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1*10**3+2*10**2+3*10**1+4*10**0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Hexadecimal (Basis 16)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4660" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "0x1234" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4660" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1*16**3+2*16**2+3*16**1+4*16**0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Binär (Basis 2)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "38" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "0b100110" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "38" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1*2**5 + 0*2**4 + 0*2**3 + 1*2**2 + 1*2**1 + 0*2**0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Integer Numbers: Arithmetic" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.5" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "3/2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Man will Python 2 behaviour erzwingen: 3/2 == 1 -> Floor division" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "3//2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Module: Restklassen, Rest der Division" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "3%2" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "3%1" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "9%5" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Operator Precedence" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "9" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "4 * 2 + 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "IMplizite Klammerung durch Präzedenz" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "9" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(4 * 2) + 1" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "12" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "4 * (2 + 1)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2.6666666666666665" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "4 * 2 / 3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Frage: warum 6665 und nicht 6667 -> IEEE Floatingpoint Representaion" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2/3 == 4/6" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Floatingpoint Zahlen nicht mit == vergleichen!" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "abs(2/3 - 4/6) < 0.0001" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Integers sind aber unendlich lang (in Python)" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1000000" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "10**6" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4294967295" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2**32 - 1" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "18446744073709551615" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2**64 - 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Overflow, wenn nicht Python verwendet wird. Der Wert wäre dort 0!!!" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "18446744073709551616" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2**64 # overflow, but not in Python" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2**1000" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "19950631168807583848837421626835850838234968318861924548520089498529438830221946631919961684036194597899331129423209124271556491349413781117593785932096323957855730046793794526765246551266059895520550086918193311542508608460618104685509074866089624888090489894838009253941633257850621568309473902556912388065225096643874441046759871626985453222868538161694315775629640762836880760732228535091641476183956381458969463899410840960536267821064621427333394036525565649530603142680234969400335934316651459297773279665775606172582031407994198179607378245683762280037302885487251900834464581454650557929601414833921615734588139257095379769119277800826957735674444123062018757836325502728323789270710373802866393031428133241401624195671690574061419654342324638801248856147305207431992259611796250130992860241708340807605932320161268492288496255841312844061536738951487114256315111089745514203313820202931640957596464756010405845841566072044962867016515061920631004186422275908670900574606417856951911456055068251250406007519842261898059237118054444788072906395242548339221982707404473162376760846613033778706039803413197133493654622700563169937455508241780972810983291314403571877524768509857276937926433221599399876886660808368837838027643282775172273657572744784112294389733810861607423253291974813120197604178281965697475898164531258434135959862784130128185406283476649088690521047580882615823961985770122407044330583075869039319604603404973156583208672105913300903752823415539745394397715257455290510212310947321610753474825740775273986348298498340756937955646638621874569499279016572103701364433135817214311791398222983845847334440270964182851005072927748364550578634501100852987812389473928699540834346158807043959118985815145779177143619698728131459483783202081474982171858011389071228250905826817436220577475921417653715687725614904582904992461028630081535583308130101987675856234343538955409175623400844887526162643568648833519463720377293240094456246923254350400678027273837755376406726898636241037491410966718557050759098100246789880178271925953381282421954028302759408448955014676668389697996886241636313376393903373455801407636741877711055384225739499110186468219696581651485130494222369947714763069155468217682876200362777257723781365331611196811280792669481887201298643660768551639860534602297871557517947385246369446923087894265948217008051120322365496288169035739121368338393591756418733850510970271613915439590991598154654417336311656936031122249937969999226781732358023111862644575299135758175008199839236284615249881088960232244362173771618086357015468484058622329792853875623486556440536962622018963571028812361567512543338303270029097668650568557157505516727518899194129711337690149916181315171544007728650573189557450920330185304847113818315407324053319038462084036421763703911550639789000742853672196280903477974533320468368795868580237952218629120080742819551317948157624448298518461509704888027274721574688131594750409732115080498190455803416826949787141316063210686391511681774304792596709376" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2**10000" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Strings" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'hallo'" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'hallo'" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'hallo'" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"hallo\"" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'das ist ein eingebettetes \"'" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'das ist ein eingebettetes \"'" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\"das ist ein eingenbettetes '\"" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'das ist ein eingenbettetes \\''" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\"das ist eine eingebettetes '\"" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"das ist eine eingebettetes '\"" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'das ist eine eingebettetes \"'" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"das ist eine eingebettetes \\\"\"" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'mississippi'.count('ss')" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'mississippi'.find('ss')" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'mississippi'.find('ss', 3)" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Mississippi'" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'mississippi'.capitalize()" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "eine zeile\n", "noch eine zeile\n" ] } ], "source": [ "print('eine zeile\\nnoch eine zeile')" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "C:\\some\n", "ame\\of\u0007\\directory\n" ] } ], "source": [ "print(\"C:\\some\\name\\of\\a\\directory\")" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "C:\\some\\name\\of\u0007\\directory\n" ] } ], "source": [ "print(\"C:\\some\\\\name\\of\\a\\directory\")" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "C:\\some\\name\\of\\a\\directory\n" ] } ], "source": [ "print(r\"C:\\some\\name\\of\\a\\directory\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Multiline Strings" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "eine zeile\n", "noch eine zeile\n", "jetzt ist schluss\n" ] } ], "source": [ "print(\"\"\"eine zeile\n", "noch eine zeile\n", "jetzt ist schluss\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Compound Datatypes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Lists (Array in JavaScript, std::vector<> in C++, Array in Java)" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [], "source": [ "l = [1, 'eins', 1.0]" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 'eins', 1.0]" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In Java (und C++ und C#, nicht aber in JavaScript) geht das nicht." ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l[0]" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'eins'" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l[1]" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "list index out of range\n" ] } ], "source": [ "try:\n", " l[3]\n", "except Exception as e:\n", " print(e)" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [], "source": [ "l.append('one')" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 'eins', 1.0, 'one']" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 'eins', 1.0, 'one', 1, 2, 3, 4]" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l.extend([1, 2, 3, 4])\n", "l" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Slice: ``[inclusive:exclusive]``" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1.0, 'one', 1]" ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l[2:5]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Löschen" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [], "source": [ "del l[3]" ] }, { "cell_type": "code", "execution_count": 53, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 'eins', 1.0, 1, 2, 3, 4]" ] }, "execution_count": 53, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Iteration (in Python mittels ``for``)" ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "eins\n", "1.0\n", "1\n", "2\n", "3\n", "4\n" ] } ], "source": [ "for element in l:\n", " print(element)" ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [], "source": [ "def is_integer(elem):\n", " if type(elem) is int:\n", " return True\n", " else:\n", " return False" ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "1\n", "2\n", "3\n", "4\n" ] } ], "source": [ "for x in filter(is_integer, l):\n", " print(x)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Dictionary (Key/Value Map in Javascript)" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [], "source": [ "mapping = {\n", " 'zero': 0,\n", " 'one': 1,\n", " 'two': 2,\n", "}" ] }, { "cell_type": "code", "execution_count": 58, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 58, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mapping['one']" ] }, { "cell_type": "code", "execution_count": 59, "metadata": {}, "outputs": [], "source": [ "mapping['three'] = 3" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'zero': 0, 'one': 1, 'two': 2, 'three': 3}" ] }, "execution_count": 60, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mapping" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [], "source": [ "del mapping['one']" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'zero': 0, 'two': 2, 'three': 3}" ] }, "execution_count": 62, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mapping" ] }, { "cell_type": "code", "execution_count": 63, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "zero\n", "two\n", "three\n" ] } ], "source": [ "for k in mapping.keys():\n", " print(k)" ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "2\n", "3\n" ] } ], "source": [ "for v in mapping.values():\n", " print(v)" ] }, { "cell_type": "code", "execution_count": 65, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "zero 0\n", "two 2\n", "three 3\n" ] } ], "source": [ "for k, v in mapping.items():\n", " print(k, v)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Set: mathematische Mengen" ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [], "source": [ "s = {'rot', 'gruen', 'blau'}" ] }, { "cell_type": "code", "execution_count": 67, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 67, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'rot' in s" ] }, { "cell_type": "code", "execution_count": 69, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 69, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'schwarz' in s" ] }, { "cell_type": "code", "execution_count": 70, "metadata": {}, "outputs": [], "source": [ "s.add('schwarz')" ] }, { "cell_type": "code", "execution_count": 71, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 71, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'schwarz' in s" ] }, { "cell_type": "code", "execution_count": 72, "metadata": {}, "outputs": [], "source": [ "s.remove('rot')" ] }, { "cell_type": "code", "execution_count": 73, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 73, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'rot' in s" ] }, { "cell_type": "code", "execution_count": 74, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "schwarz\n", "gruen\n", "blau\n" ] } ], "source": [ "for element in s:\n", " print(element)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# while" ] }, { "cell_type": "code", "execution_count": 75, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "5050\n" ] } ], "source": [ "sum = 0\n", "i = 1\n", "while i <= 100:\n", " sum += i\n", " i += 1\n", "\n", "print(sum)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Functions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Bestimmen des Maximums von zwei Zahlen ... inline ohne Funktion" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "a = 666\n", "b = 42" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "if a < b:\n", " maximum = b\n", "else:\n", " maximum = a" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "666\n" ] } ], "source": [ "print(maximum)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "var1 = 17\n", "var2 = 6712" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "if var1 < var2:\n", " maximum = var1\n", "else:\n", " maximum = var2" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "17\n" ] } ], "source": [ "print(maximum)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Das isn Fehler!" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "def maximum(links, rechts):\n", " if links < rechts:\n", " return rechts\n", " else:\n", " return links" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "maximum(1, 2)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "666" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "maximum(666, 42)" ] } ], "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.9.2" } }, "nbformat": 4, "nbformat_minor": 4 }