{"id":332,"date":"2018-10-04T12:40:07","date_gmt":"2018-10-04T12:40:07","guid":{"rendered":"http:\/\/iludis.de\/?p=332"},"modified":"2018-12-24T15:16:13","modified_gmt":"2018-12-24T15:16:13","slug":"pythonskripte-inf-4stuender","status":"publish","type":"page","link":"https:\/\/iludis.de\/?page_id=332","title":{"rendered":"Pythonskripte Inf4St. Teil I"},"content":{"rendered":"<p><strong>FizzBuzz: <\/strong><em>Einstieg in Python<\/em><\/p>\n<pre class=\"brush: python; gutter: true\">for k in range (1,100,1):\r\n    if k%3 == 0 or k%5 == 0:\r\n        if k%5 !=0:\r\n            print(&quot;fizz&quot;&quot; &quot;, end=&quot;&quot;)\r\n        if k%3 !=0:\r\n            print(&quot;buzz&quot;&quot; &quot;, end=&quot;&quot;)\r\n        if k%3 == 0 and k%5 == 0:\r\n            print(&quot;fizzbuzz&quot;&quot; &quot;, end=&quot;&quot;)\r\n    else:\r\n        print (k,&quot; &quot;, end=&quot;&quot;)<\/pre>\n<p><strong>Linear Search: <\/strong><em>mit Zufallslisten-Generator und Zeitmessung f\u00fcr die Zeitkomplexit\u00e4t<\/em><\/p>\n<pre class=\"brush: python; gutter: true\">import random\r\nimport time\r\nmeineliste=[]\r\n\r\nfor i in range(0,20):\r\n    zufall = random.randint(1,100)\r\n    meineliste.append(zufall)\r\nprint(meineliste)\r\n\r\nstartzeit = time.monotonic_ns()\r\nmaximum = meineliste[0]\r\nfor i in range(1, len(meineliste)):\r\n    time.sleep(0.01)\r\n    if maximum&lt;meineliste[i]:\r\n        maximum = meineliste[i]\r\n        print(&quot;vorl\u00e4ufiges Maximum: &quot;, maximum)\r\n        time.sleep(0.01)\r\nprint(&quot;-------------------------------------------&quot;)\r\ndauer = (time.monotonic_ns()-startzeit)\/1000000\r\nprint(&quot;zeitdauer in milli-Sekunden: &quot;, dauer)\r\nprint(&quot;endg\u00fcltiges Maximum: &quot;, maximum)<\/pre>\n<p><strong>BubbleSort:<\/strong>\u00a0<em>mit Zufallslisten-Generator und Zeitmessung f\u00fcr die Zeitkomplexit\u00e4t<\/em><\/p>\n<pre class=\"brush: python; gutter: true\">import random\r\nimport time\r\n\r\nmliste = []\r\nfor k in range (0,20):\r\n    mliste.append(random.randint(1,100))\r\n\r\nprint(mliste)\r\n\r\nstartzeit = time.monotonic_ns()\r\n# bubblesort\r\nfor m in range(0,len(mliste)-1):\r\n    time.sleep(0.01)\r\n    for i in range(0,len(mliste)-1-m):\r\n        time.sleep(0.01)\r\n        if mliste[i]&gt;mliste[i+1]:\r\n            time.sleep(0.01)\r\n            temp = mliste[i+1]\r\n            mliste[i+1]= mliste[i]\r\n            mliste[i]=temp\r\n    print(mliste)\r\nendzeit = time.monotonic_ns()\r\nzeitdifferenz= (endzeit - startzeit)\/1000000\r\nprint(&quot;vergangene Zeit: &quot;, zeitdifferenz)<\/pre>\n<p><strong>Quicksort-Simulation:<\/strong><em>\u00a0Die Simulation aus dem Unterricht:<br \/>\n<\/em><a style=\"background-color: #ffffff;\" href=\"https:\/\/www.hackerearth.com\/practice\/algorithms\/sorting\/quick-sort\/visualize\/\">https:\/\/www.hackerearth.com\/practice\/algorithms\/sorting\/quick-sort\/visualize\/<\/a><em><br \/>\n<\/em><\/p>\n<p><strong>Prinzip von Funktionen:<\/strong> mit Parameter\u00fcbergabe, Returnwert und globaler Variable f\u00fcr die R\u00fcckgabe<\/p>\n<pre class=\"brush: python; gutter: true\">import random\r\nimport time\r\n\r\ndef macheZufallsliste(listenlaenge, obergrenze):\r\n    print(&quot;\u00fcbergebener Parameter: &quot; + str(listenlaenge))\r\n    meineListe = []\r\n    for i in range(0,listenlaenge):\r\n        meineListe.append(random.randint(1,obergrenze))\r\n    print (&quot;noch im Stack:           &quot;, meineListe)\r\n    return meineListe\r\n\r\nauffangVariable= macheZufallsliste(10,10)\r\n\r\nprint(&quot;aufgefangen \u00fcber Return: &quot;, auffangVariable)\r\ntime.sleep(2)\r\nprint(&quot;aufgefangen \u00fcber Return: &quot;, auffangVariable)<\/pre>\n<p><strong>Selection-Sort:<\/strong> mit Linear-Search-Funktion und Python &#8222;append()&#8220; bzw. &#8222;insert()&#8220;<\/p>\n<pre class=\"brush: python; gutter: true\">import random\r\n\r\ndef sucheLinear(testliste, modus):\r\n    if modus==&quot;max&quot;:\r\n        maximum = testliste[0]\r\n        for num in testliste:\r\n            if num&gt;maximum:\r\n                maximum = num\r\n        return maximum\r\n\r\n    if modus==&quot;min&quot;:\r\n        minimum = testliste[0]\r\n        for num in testliste:\r\n            if num&lt;minimum:\r\n                minimum = num\r\n        return minimum\r\n\r\nmliste = []\r\nfor k in range (20):\r\n    mliste.append(random.randint(1, 100))\r\n\r\nfor j in range (0, len(mliste)):\r\n    groesstesElement = sucheLinear(mliste[0:len(mliste)-j], &quot;max&quot;)\r\n    print(&quot;aktuell gr\u00f6sstes Element:&quot;, groesstesElement)\r\n    mliste.remove(groesstesElement)\r\n    mliste.append(groesstesElement)\r\n    print(&quot;Sortier-Schritt &quot;,j+1, &quot;: &quot;, mliste)\r\nprint(&quot;endg\u00fcltig sortierte Liste: &quot;, mliste)<\/pre>\n<p><strong>Stack-Simulation:<\/strong> <em>Wie Funktionen im Speicher verwaltet werden, wichtig f\u00fcr Rekursion<\/em><br \/>\n<a href=\"https:\/\/visualgo.net\/en\/list\">https:\/\/visualgo.net\/en\/list<\/a><\/p>\n<p><strong>Rekursion: <\/strong>Skripte f\u00fcr das grundlegende Verst\u00e4ndnis. Stack Auf- und Abbau.<\/p>\n<pre class=\"brush: python; gutter: true\">def rek1(n):\r\n    if n&gt;1:\r\n        print(&quot;lokales n: &quot;, n)\r\n        n-= 1\r\n        rek1(n)\r\n    else:\r\n        print(&quot;lokales n: &quot;, n, &quot;, fertig: Basisfall, bzw. Abbruchbedingung&quot;)\r\n        n-= 1\r\n    print(&quot;lokales n: &quot;, n)\r\n\r\nrek1(4)\r\nprint(&quot;------------------------------------------------------&quot;)\r\n\r\nsumme=0\r\ndef rek2(n):\r\n    global summe\r\n    if n&gt;1:\r\n        summe=summe+n\r\n        print(&quot;Hin ...     lokales n: &quot;, n, &quot;summe: &quot;, summe)\r\n        n-= 1\r\n        rek2(n)\r\n    else:\r\n        summe=summe+n\r\n        print(&quot;fertig.     lokales n: &quot;, n, &quot;summe: &quot;, summe)\r\n        n-= 1\r\n    print(&quot;...&amp; zur\u00fcck lokales n: &quot;, n, &quot;summe: &quot;, summe)\r\n\r\nrek2(4)\r\nprint(&quot;------------------------------------------------------&quot;)\r\n\r\nprod=1\r\ndef rek3(n):\r\n    global prod\r\n    if n&gt;1:\r\n        prod=prod*n\r\n        print(&quot;Hin ...     lokales n: &quot;, n, &quot;prod: &quot;, prod)\r\n        n-=1\r\n        rek3(n)\r\n    else:\r\n        prod = prod * n\r\n        print(&quot;fertig.     lokales n: &quot;, n, &quot;prod: &quot;, prod)\r\n        n -= 1\r\n    print(&quot;...&amp; zur\u00fcck lokales n: &quot;, n, &quot;prod: &quot;, prod)\r\n\r\nrek3(5)\r\nprint(&quot;------------------------------------------------------&quot;)\r\n\r\ndef rek4(n):\r\n    if n&gt;1:\r\n        print(&quot;vorher, lokales n: &quot;, n)\r\n        prod = n * rek4(n-1)\r\n        print(&quot;danach, lokales n: &quot;, n, &quot;zwischenergebnis: &quot;, prod)\r\n        return prod\r\n    else:\r\n        print(&quot;fertig. Lokales n: &quot;, n)\r\n        return 1\r\n    print(&quot;...&amp; zur\u00fcck lokales n: &quot;, n)\r\n\r\nrek4(5)\r\nprint(&quot;------------------------------------------------------&quot;)\r\n\r\ndef rek5(n):\r\n    if n&gt;1:\r\n        print(&quot;vorher, lokales n: &quot;, n)\r\n        knoten = rek5(n-1) + rek5(n-1)\r\n        print(&quot;Ast.  Lokales n: &quot;, n, &quot;zwischenknoten: &quot;, knoten)\r\n        return knoten\r\n    else:\r\n        print(&quot;Blatt. Lokales n: &quot;, n)\r\n        return 1\r\n    print(&quot;...&amp; zur\u00fcck lokales n: &quot;, n)\r\n\r\nrek5(3)\r\nprint(&quot;------------------------------------------------------&quot;)<\/pre>\n<p><strong>Programm von F.S.:<\/strong> Quicksort-Implementierung<\/p>\n<pre class=\"brush: python; gutter: true\">import random\r\nlaenge=10\r\nlist=[]\r\n\r\nfor i in range (0,laenge):\r\n    list.append(random.randint(1,100))\r\n\r\nprint(&quot;Die zuf\u00e4llig ausgew\u00e4hlte Liste ist: &quot;)\r\nprint(list)\r\n\r\ndef quicksort(list):\r\n    rekursion(list,0,len(list)-1)\r\n\r\ndef rekursion (list,first,last):\r\n    if first&lt;last:                                 #Abbruchbedingung\r\n        splitpoint=sortieren(list,first,last)\r\n        rekursion(list,first,splitpoint-1)       #Rekursion f\u00fcr erste Listenh\u00e4lfte!\r\n        rekursion(list,splitpoint+1,last)        #Rekursionf\u00fcr zweite Listenh\u00e4lfte!\r\n\r\ndef sortieren(list,first,last):\r\n    pivot=list[last]\r\n    leftmark=first\r\n    rightmark=last-1\r\n    done=False\r\n    while not done:\r\n        while leftmark&lt;=rightmark and list[leftmark]&lt;= pivot:\r\n            leftmark=leftmark+1\r\n\r\n        while leftmark&lt;=rightmark and list[rightmark]&gt;= pivot:\r\n            rightmark=rightmark-1\r\n\r\n        if rightmark&lt;leftmark:\r\n            done=True\r\n        else:\r\n            temp=list[rightmark]\r\n            list[rightmark]=list[leftmark]\r\n            list[leftmark]=temp\r\n\r\n    temp=list[leftmark]\r\n    list[leftmark]=list[last]\r\n    list[last]=temp\r\n\r\n    return leftmark\r\n\r\nquicksort(list)\r\nprint(&quot;--------------------------------------------------------------------------------------&quot;)\r\nprint(&quot;Die Liste ist nun sortiert.&quot;)\r\nprint(list)\r\nprint(&quot;--------------------------------------------------------------------------------------&quot;)<\/pre>\n<p><strong>Programm von M.D.: <\/strong>Palindrompr\u00fcfung<\/p>\n<pre class=\"brush: python; gutter: true\">string_list = input()\r\n\r\ndef palyndrom2(stringarr_):\r\n    if len(stringarr_) &gt; 1:\r\n            return stringarr_[0] == stringarr_[len(stringarr_)-1] and palyndrom2(stringarr_[1:len(stringarr_)-1])\r\n    else:\r\n        return True\r\n\r\nx = palyndrom2(string_list)\r\nprint(x);<\/pre>\n<p><strong>Bin\u00e4rer Baum:<\/strong> Turtle-Grafik <em>&#8222;ohne Schn\u00f6rkel&#8220;<\/em><\/p>\n<pre class=\"brush: python; gutter: true\">import turtle\r\n\r\ndef binbaum(maxtiefe, tiefe):\r\n    turtle.forward(100*pow(0.618,tiefe))\r\n\r\n    if tiefe &lt; maxtiefe:\r\n        turtle.left(60)\r\n        binbaum(maxtiefe, tiefe+1)\r\n        turtle.right(120)\r\n        binbaum(maxtiefe, tiefe+1)\r\n        turtle.left(60)\r\n\r\n    turtle.backward(100*pow(0.618,tiefe))\r\n\r\nbinbaum(6,0)\r\n\r\nturtle.exitonclick()<\/pre>\n<p><strong>Programm von M.M.:<\/strong> Bin\u00e4rer Baum mit Turtle-Grafik<\/p>\n<pre class=\"brush: python; gutter: true\">import turtle\r\ndef tree(x_):\r\n    if x_&lt;=rek:\r\n        turtle.down()\r\n        turtle.forward(int(200\/(x_*1.675)))\r\n        leftfunk(x_)\r\n        rightfunk(x_)\r\n        turtle.up()\r\n        turtle.backward(int(200\/(x_*1.675)))\r\n\r\ndef leftfunk(x_):\r\n    if x_ &lt;=rek:\r\n        turtle.left(winkel)\r\n        tree(x_+1)\r\n        turtle.right(winkel)\r\n\r\ndef rightfunk(x_):\r\n    if x_ &lt;=rek:\r\n        turtle.right(winkel)\r\n        tree(x_+1)\r\n        turtle.left(winkel)\r\n\r\nglobal rek\r\nglobal winkel\r\nwinkel=30\r\nrek=8\r\nturtle.up()\r\nturtle.goto(0,-200)\r\nturtle.left(90)\r\nturtle.down()\r\ntree(1)\r\nturtle.exitonclick()<\/pre>\n<p><strong>Mini-Datenbank:<\/strong> f\u00fcr die Bin\u00e4re Suche<\/p>\n<pre class=\"brush: python; gutter: true\">dbListe = [[&quot;Staat&quot;, &quot;Lebenserwartung&quot;, &quot;MioEinwohner&quot;, &quot;Fertilitaet&quot;]\r\n,[&quot;aegypten&quot;, 72.7, 97, 3.4]\r\n,[&quot;aequatorialguinea&quot;, 64.2, 1.2, 4.9]\r\n,[&quot;aethiopien&quot;, 62.2, 107.5, 4.4]\r\n,[&quot;afghanistan&quot;, 51.3, 36.5, 4.8]\r\n,[&quot;albanien&quot;, 78.3, 2.9, 1.7]\r\n,[&quot;algerien&quot;, 76.8, 42.7, 3.1]\r\n,[&quot;andorra&quot;, 82.8, 0.07, 1.3]\r\n,[&quot;angola&quot;, 56.0, 25.8, 6.0]\r\n,[&quot;antigua&quot;, 76.5, 0.09, 2.3]\r\n,[&quot;argentinien&quot;, 77.1, 44.5, 2.3]\r\n,[&quot;armenien&quot;, 74.6, 3, 1.6]\r\n,[&quot;aserbaidschan&quot;, 72.5, 9.8, 2.1]\r\n,[&quot;australien&quot;, 82.2, 24.3, 1.8]\r\n,[&quot;bahamas&quot;, 72.4, 0.3, 2.0]\r\n,[&quot;bahrain&quot;, 78.9, 1.3, 2.1]\r\n,[&quot;bangladesch&quot;, 73.2, 166.4, 2.1]\r\n,[&quot;barbados&quot;, 75.3, 0.2, 1.5]\r\n,[&quot;belgien&quot;, 81, 11.3, 1.7]\r\n,[&quot;belize&quot;, 68.7, 0.3, 2.5]\r\n,[&quot;benin&quot;, 61.9, 11.1, 5.3]\r\n,[&quot;bhutan&quot;, 70.1, 0.8, 2.1]\r\n,[&quot;bolivien&quot;, 69.2, 10.8, 3]\r\n,[&quot;bosnien&quot;, 76.7, 3.8, 1.3]\r\n,[&quot;botswana&quot;, 54.5, 2.3, 2.8]\r\n,[&quot;brasilien&quot;, 73.8, 209.4, 1.7]\r\n,[&quot;brunei&quot;, 77.2, 0.4, 1.9]\r\n,[&quot;bulgarien&quot;, 74.5, 7, 1.5]\r\n,[&quot;burkinafaso&quot;, 55.5, 18.6, 5.7]\r\n,[&quot;burundi&quot;, 60.5, 10.5, 6.1]\r\n,[&quot;chile&quot;, 78.8, 18.1, 1.9]\r\n,[&quot;china&quot;, 75.5, 1393.8, 1.8]\r\n,[&quot;costarica&quot;, 78.6, 4.8, 1.8]\r\n,[&quot;daenemark&quot;, 79.4, 5.6, 1.7]\r\n,[&quot;deutschland&quot;, 80.7, 82.8, 1.6]\r\n,[&quot;dominica&quot;, 77, 0.07, 3]\r\n,[&quot;dominikanische&quot;, 78.1, 10.6, 2.4]\r\n,[&quot;dschibuti&quot;, 63.2, 0.9, 3.2]\r\n,[&quot;ecuador&quot;, 76.8, 16.3, 2.5]\r\n,[&quot;elfenbeinkueste&quot;, 58.7, 23.2, 4.9]\r\n,[&quot;elsalvador&quot;, 74.7, 6.1, 2]\r\n,[&quot;emirate&quot;, 77.5, 9.2, 1.8]\r\n,[&quot;eritrea&quot;, 64.9, 5.3, 4.2]\r\n,[&quot;estland&quot;, 76.7, 1.3, 1.7]\r\n,[&quot;fidschi&quot;, 72.7, 0.8, 2.7]\r\n,[&quot;finnland&quot;, 80.9, 5.5, 1.6]\r\n,[&quot;frankreich&quot;, 81.9, 65.1, 1.9]\r\n,[&quot;gabun&quot;, 52.1, 2, 4.1]\r\n,[&quot;gambia&quot;, 64.9, 2, 5.6]\r\n,[&quot;georgien&quot;, 76.2, 3.9, 1.7]\r\n,[&quot;ghana&quot;, 66.6, 28, 4.2]\r\n,[&quot;grenada&quot;, 74.3, 0.1, 2.1]\r\n,[&quot;grenadinen&quot;, 75.3, 0.1, 2]\r\n,[&quot;griechenland&quot;, 80.5, 10.9, 1.3]\r\n,[&quot;grossbritannien&quot;, 80.7, 66.4, 1.8]\r\n,[&quot;guatemala&quot;, 72.3, 16.6, 3.1]\r\n,[&quot;guinea&quot;, 60.6, 12.4, 5.1]\r\n,[&quot;guineabissau&quot;, 50.6, 1.8, 5.6]\r\n,[&quot;guyana&quot;, 68.4, 0.7, 2.3]\r\n,[&quot;haiti&quot;, 63.8, 10.8, 3.2]\r\n,[&quot;honduras&quot;, 71.1, 8.1, 2.5]\r\n,[&quot;hongkong&quot;, 82.9, 7.3, 1.2]\r\n,[&quot;indien&quot;, 68.5, 1371.3, 2.3]\r\n,[&quot;indonesien&quot;, 72.7, 265.2, 2.4]\r\n,[&quot;irak&quot;, 74.9, 40.2, 4.1]\r\n,[&quot;iran&quot;, 71.4, 81.6, 2]\r\n,[&quot;irland&quot;, 80.8, 4.7, 1.9]\r\n,[&quot;island&quot;, 83, 0.3, 1.8]\r\n,[&quot;israel&quot;, 82.4, 8.1, 3.1]\r\n,[&quot;italien&quot;, 82.2, 60.6, 1.3]\r\n,[&quot;jamaika&quot;, 73.6, 2.8, 2]\r\n,[&quot;japan&quot;, 85, 126.5, 1.4]\r\n,[&quot;jemen&quot;, 65.5, 27.4, 4.2]\r\n,[&quot;jordanien&quot;, 74.6, 7.7, 3.5]\r\n,[&quot;kambodscha&quot;, 64.5, 15.8, 2.6]\r\n,[&quot;kamerun&quot;, 58.5, 23.9, 4.9]\r\n,[&quot;kanada&quot;, 81.9, 37.2, 1.5]\r\n,[&quot;kapverde&quot;, 72.1, 0.5, 2.3]\r\n,[&quot;kasachstan&quot;, 70.8, 17.8, 2.6]\r\n,[&quot;katar&quot;, 78.7, 2.2, 2]\r\n,[&quot;kenia&quot;, 64, 51, 3.9]\r\n,[&quot;kirgisistan&quot;, 70.7, 6, 2.5]\r\n,[&quot;kiribati&quot;, 66.2, 0.1, 4.2]\r\n,[&quot;kolumbien&quot;, 75.7, 49.8, 2]\r\n,[&quot;komoren&quot;, 64.2, 0.8, 3.8]\r\n,[&quot;kongo&quot;, 57.3, 84.3, 6.3]\r\n,[&quot;kroatien&quot;, 75.9, 4.2, 1.5]\r\n,[&quot;kuba&quot;, 78.7, 11.5, 1.5]\r\n,[&quot;kuwait&quot;, 78, 4, 2.1]\r\n,[&quot;laos&quot;, 64.3, 6.9, 3]\r\n,[&quot;lesotho&quot;, 53, 2.1, 3.2]\r\n,[&quot;lettland&quot;, 74.5, 1.9, 1.6]\r\n,[&quot;libanon&quot;, 77.6, 6, 1.7]\r\n,[&quot;liberia&quot;, 59, 4.6, 4.9]\r\n,[&quot;libyen&quot;, 76.5, 6.3, 2.6]\r\n,[&quot;liechtenstein&quot;, 81.9, 0.03, 1.4]\r\n,[&quot;litauen&quot;, 74.9, 2.8, 1.6]\r\n,[&quot;lucia&quot;, 77.8, 0.1, 1.7]\r\n,[&quot;luxemburg&quot;, 82.3, 0.5, 1.7]\r\n,[&quot;macau&quot;, 84.5, 0.5, 0.9]\r\n,[&quot;madagaskar&quot;, 65.9, 24.9, 4.3]\r\n,[&quot;malawi&quot;, 61.2, 17.7, 6.3]\r\n,[&quot;malaysia&quot;, 75, 32.5, 1.9]\r\n,[&quot;malediven&quot;, 75.6, 0.3, 2]\r\n,[&quot;mali&quot;, 55.8, 18.1, 6]\r\n,[&quot;malta&quot;, 80.4, 0.4, 1.3]\r\n,[&quot;marokko&quot;, 76.9, 35.2, 2.2]\r\n,[&quot;marshallinseln&quot;, 73.1, 0.05, 4.9]\r\n,[&quot;mauretanien&quot;, 63, 4.1, 4.3]\r\n,[&quot;mauritius&quot;, 75.6, 1.2, 1.4]\r\n,[&quot;mazedonien&quot;, 76.2, 2, 1.5]\r\n,[&quot;mexiko&quot;, 75.9, 130.8, 2.2]\r\n,[&quot;mikronesien&quot;, 72.9, 0.5, 2.4]\r\n,[&quot;moldau&quot;, 70.7, 4, 1.3]\r\n,[&quot;mongolei&quot;, 69.6, 3, 3.1]\r\n,[&quot;mosambik&quot;, 53.3, 28.7, 5.9]\r\n,[&quot;myanmar&quot;, 66.6, 53.9, 2.3]\r\n,[&quot;namibia&quot;, 63.6, 2.5, 3.6]\r\n,[&quot;nauru&quot;, 67.1, 0.01, 3.4]\r\n,[&quot;nepal&quot;, 70.7, 29.7, 2.3]\r\n,[&quot;neuguinea&quot;, 67.2, 7.7, 4]\r\n,[&quot;neuseeland&quot;, 81.2, 4.5, 2]\r\n,[&quot;nevis&quot;, 75.7, 0.05, 2.3]\r\n,[&quot;nicaragua&quot;, 73.2, 6.1, 2.4]\r\n,[&quot;niederlande&quot;, 81.3, 16.9, 1.7]\r\n,[&quot;niger&quot;, 55.5, 20.7, 7.6]\r\n,[&quot;nigeria&quot;, 53.4, 195.9, 5.5]\r\n,[&quot;nordkorea&quot;, 70.4, 25.2, 2.1]\r\n,[&quot;norwegen&quot;, 81.8, 5.2, 1.7]\r\n,[&quot;oesterreich&quot;, 81.5, 8.5, 1.5]\r\n,[&quot;oman&quot;, 75.5, 4.6, 2.9]\r\n,[&quot;osttimor&quot;, 68.1, 1.2, 5.7]\r\n,[&quot;pakistan&quot;, 67.7, 200.6, 3.1]\r\n,[&quot;palaestina&quot;, 73.9, 4.7, 4.1]\r\n,[&quot;palau&quot;, 73.1, 0.02, 2.1]\r\n,[&quot;panama&quot;, 78.6, 3.9, 2.5]\r\n,[&quot;paraguay&quot;, 77.2, 6.7, 2.6]\r\n,[&quot;peru&quot;, 73.7, 32.2, 2.4]\r\n,[&quot;philippinen&quot;, 69.2, 107, 2.7]\r\n,[&quot;polen&quot;, 77.6, 38.4, 1.4]\r\n,[&quot;polynesien&quot;, 77.2, 0.2, 2.2]\r\n,[&quot;portugal&quot;, 79.3, 10.3, 1.4]\r\n,[&quot;principe&quot;, 64.9, 0.1, 4.4]\r\n,[&quot;ruanda&quot;, 60.1, 11.9, 4.2]\r\n,[&quot;rumaenien&quot;, 75.1, 19.3, 1.3]\r\n,[&quot;russland&quot;, 70.3, 147.3, 1.6]\r\n,[&quot;salomonen\u00a0&quot;, 75.3, 0.5, 3.7]\r\n,[&quot;sambia&quot;, 52.5, 16.7, 5.3]\r\n,[&quot;samoa&quot;, 73.7, 0.1, 3.8]\r\n,[&quot;sanmarino&quot;, 83.3, 0.03, 1.2]\r\n,[&quot;saudiarabien&quot;, 75.3, 33.4, 2.4]\r\n,[&quot;schweden&quot;, 82.1, 9.8, 1.8]\r\n,[&quot;schweiz&quot;, 82.6, 8.3, 1.5]\r\n,[&quot;senegal&quot;, 61.7, 15.5, 5]\r\n,[&quot;serbien&quot;, 75.5, 8.8, 1.6]\r\n,[&quot;seychellen&quot;, 74.7, 0.09, 2.1]\r\n,[&quot;sierraleone&quot;, 58.2, 7.4, 5.1]\r\n,[&quot;simbabwe&quot;, 58, 15.9, 4]\r\n,[&quot;singapur&quot;, 85, 5.6, 1.2]\r\n,[&quot;slowakei&quot;, 77.1, 5.4, 1.4]\r\n,[&quot;slowenien&quot;, 78.1, 2, 1.6]\r\n,[&quot;somalia&quot;, 52.4, 14.3, 6.4]\r\n,[&quot;spanien&quot;, 81.7, 46.7, 1.3]\r\n,[&quot;srilanka&quot;, 76.8, 20.8, 2.1]\r\n,[&quot;sudan&quot;, 64.1, 41.7, 4.7]\r\n,[&quot;suedafrika&quot;, 63.1, 57.7, 2.4]\r\n,[&quot;suedkorea&quot;, 82.4, 51.8, 1.1]\r\n,[&quot;suriname&quot;, 72.2, 0.5, 2.4]\r\n,[&quot;swasiland&quot;, 51.6, 1.3, 3.3]\r\n,[&quot;syrien&quot;, 68.4, 18.5, 2.7]\r\n,[&quot;tadschikistan&quot;, 67.7, 8.6, 3.3]\r\n,[&quot;taiwan&quot;, 80.1, 23.3, 1.1]\r\n,[&quot;tansania&quot;, 62.2, 59.1, 5.2]\r\n,[&quot;thailand&quot;, 74.7, 66.2, 1.5]\r\n,[&quot;togo&quot;, 65, 7.4, 4.1]\r\n,[&quot;tonga&quot;, 76.2, 0.1, 3.6]\r\n,[&quot;trinidad&quot;, 72.9, 1.3, 1.7]\r\n,[&quot;tschad&quot;, 50.2, 14.4, 6.4]\r\n,[&quot;tschechien&quot;, 78.6, 10.5, 1.6]\r\n,[&quot;tuerkei&quot;, 74.8, 81.3, 2.1]\r\n,[&quot;tunesien&quot;, 76.1, 11.3, 2]\r\n,[&quot;turkmenistan&quot;, 70.1, 5.4, 2.4]\r\n,[&quot;tuvalu&quot;, 66.5, 0.01, 3.7]\r\n,[&quot;uganda&quot;, 55.4, 44.1, 5.4]\r\n,[&quot;ukraine&quot;, 71.8, 42.3, 1.3]\r\n,[&quot;ungarn&quot;, 75.9, 9.8, 1.4]\r\n,[&quot;uruguay&quot;, 77.2, 3.4, 1.9]\r\n,[&quot;usa&quot;, 79.8, 328, 1.8]\r\n,[&quot;usbekistan&quot;, 73.8, 32.9, 2.5]\r\n,[&quot;vanuatu&quot;, 73.4, 0.2, 3.8]\r\n,[&quot;venezuela&quot;, 75.8, 31.8, 2.4]\r\n,[&quot;vietnam&quot;, 73.4, 94.7, 2.1]\r\n,[&quot;weissrussland&quot;, 72.7, 9.4, 1.8]\r\n,[&quot;westsahara&quot;, 63, 0.5, 2.9]\r\n,[&quot;zentralafrika&quot;, 52.3, 4.9, 4.4]\r\n,[&quot;zypern&quot;, 78.7, 1.1, 1.5]]<\/pre>\n<p>Binary Search auf der MiniDB:<\/p>\n<pre class=\"brush: python; gutter: true\">import MiniDB\r\ncL = MiniDB.dbListe\r\n\r\nsuchstring = &quot;ruanda&quot;\r\n\r\nstartindex = 0\r\nendindex = len(cL)-1\r\n\r\nwhile startindex &lt; endindex:\r\n    mitte_index = round((endindex+startindex)\/2)\r\n\r\n    if cL[mitte_index][0] &lt; suchstring:\r\n        startindex = mitte_index\r\n\r\n    if cL[mitte_index][0] &gt; suchstring:\r\n        endindex = mitte_index\r\n\r\n    if cL[mitte_index][0] == suchstring:\r\n        print(mitte_index)\r\n        break<\/pre>\n<p>Binary-Tree Klasse:<\/p>\n<pre class=\"brush: python; gutter: true\">import turtle\r\n\r\nclass Node:\r\n    def __init__(self, data, tiefe, xwert, parent):\r\n        self.links = None\r\n        self.rechts = None\r\n        self.wert = data\r\n        self.tiefe = tiefe\r\n        self.xwert = xwert\r\n        self.parent = parent\r\n\r\n# ------------------------------------------------------\r\n    def printNode(self):\r\n        print(self.wert)\r\n        print(self.tiefe)\r\n        print(self.xwert)\r\n\r\n# ------------------------------------------------------\r\n    def printBaum(self):\r\n        if self.links:\r\n            self.links.printBaum()\r\n        print(&quot;wert: &quot;, self.wert, &quot;tiefe: &quot;, self.tiefe, &quot;xwert: &quot;, self.xwert )\r\n        turtle.penup()\r\n        turtle.setpos(self.xwert*900\/pow(2,self.tiefe), -200 + self.tiefe*50)\r\n        if self.parent is not None:\r\n            turtle.pendown()\r\n            turtle.goto(self.parent.xwert*900\/pow(2,self.parent.tiefe), -200 + self.parent.tiefe*50)\r\n        turtle.setpos(self.xwert * 900 \/ pow(2, self.tiefe), -200 + self.tiefe * 50)\r\n        turtle.dot(24, (0,255,0))\r\n        turtle.setpos(self.xwert * 900 \/ pow(2, self.tiefe), -208 + self.tiefe * 50)\r\n        turtle.write(str(self.wert), False, align=&quot;center&quot;)\r\n        turtle.penup()\r\n        if self.rechts:\r\n            self.rechts.printBaum()\r\n\r\n# ------------------------------------------------------\r\n    def insert(self, einfuegewert):\r\n        if self.wert is not None:\r\n            if einfuegewert&lt;self.wert :\r\n                if self.links is None:\r\n                    self.links = Node(einfuegewert, self.tiefe + 1, 2*self.xwert-1, self)\r\n                else:\r\n                    self.links.insert(einfuegewert)\r\n\r\n            if einfuegewert&gt;=self.wert:\r\n                if self.rechts is None:\r\n                    self.rechts = Node(einfuegewert, self.tiefe + 1, 2*self.xwert+1, self)\r\n                else:\r\n                    self.rechts.insert(einfuegewert)\r\n\r\n        if self.wert is None:\r\n            self.wert = einfuegewert\r\n\r\n# ------------------------------------------------------\r\ndef findeWert(self, suchwert):\r\n    if suchwert &lt; self.wert:\r\n        if self.links is None:\r\n            print(&quot;hier is nix&quot;)\r\n        return self.links.findeWert(suchwert)\r\n\r\n    if suchwert &gt; self.wert:\r\n        if self.rechts is None:\r\n            print(&quot;hier is nix&quot;)\r\n        return self.links.findeWert(suchwert)\r\n\r\n    if suchwert == self.wert:\r\n        print(&quot;gefunden! &quot;, self.wert)\r\n\r\n# ------------------------------------------------------\r\n\r\nimport random\r\nroot = Node(random.randint(1,100),1, 0, None)\r\n\r\ntemplist = []\r\nfor i in range(0,21):\r\n    templist.append(i)\r\n\r\nfor i in range(20):\r\n    tempindex = random.randint(0,len(templist)-1)\r\n    root.insert(templist[tempindex])\r\n    del(templist[tempindex])\r\n\r\nturtle.setup(1000,500)\r\nturtle.colormode(255)\r\nturtle.speed(100)\r\nturtle.hideturtle()\r\nroot.printBaum()\r\nturtle.exitonclick()<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>FizzBuzz: Einstieg in Python for k in range (1,100,1): if k%3 == 0 or k%5 == 0: if k%5 !=0: print(&quot;fizz&quot;&quot; &quot;, end=&quot;&quot;) if k%3 !=0: print(&quot;buzz&quot;&quot; &quot;, end=&quot;&quot;) if k%3 == 0 and k%5 == 0: print(&quot;fizzbuzz&quot;&quot; &quot;, end=&quot;&quot;) else: print (k,&quot; &quot;, end=&quot;&quot;) Linear Search: mit Zufallslisten-Generator und Zeitmessung f\u00fcr die Zeitkomplexit\u00e4t import&hellip; <\/p>\n<p class=\"toivo-read-more\"><a href=\"https:\/\/iludis.de\/?page_id=332\" class=\"more-link\">Read more <span class=\"screen-reader-text\">Pythonskripte Inf4St. Teil I<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":{"0":"post-332","1":"page","2":"type-page","3":"status-publish","5":"entry"},"_links":{"self":[{"href":"https:\/\/iludis.de\/index.php?rest_route=\/wp\/v2\/pages\/332","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iludis.de\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/iludis.de\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/iludis.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/iludis.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=332"}],"version-history":[{"count":0,"href":"https:\/\/iludis.de\/index.php?rest_route=\/wp\/v2\/pages\/332\/revisions"}],"wp:attachment":[{"href":"https:\/\/iludis.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}