Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lehrkraefte:sbtsnr:python:logic [2022/09/30 18:15] Karlheinz Schubert |
lehrkraefte:sbtsnr:python:logic [2022/11/04 18:21] (current) Olaf Schnürer [... und nun noch etwas rumgesponnen ...] |
||
---|---|---|---|
Line 22: | Line 22: | ||
</ | </ | ||
- | < | + | < |
<code python wahrheitstabelle-step1.py> | <code python wahrheitstabelle-step1.py> | ||
""" | """ | ||
Line 152: | Line 152: | ||
Erhoehen(Zeile, | Erhoehen(Zeile, | ||
</ | </ | ||
+ | |||
+ | ====== Funktion Erhoehen oben korrigiert ====== | ||
+ | |||
+ | <code python wahrheitstabelle-step3-verbessert.py> | ||
+ | """ | ||
+ | Truth tables | ||
+ | """ | ||
+ | import operator | ||
+ | |||
+ | anzahlVariablen = int(input(" | ||
+ | x = anzahlVariablen * [False] | ||
+ | |||
+ | def Oder(): | ||
+ | Wert = False | ||
+ | for index in range(anzahlVariablen): | ||
+ | Wert = Wert or x[index] | ||
+ | return Wert | ||
+ | |||
+ | def Und(): | ||
+ | Wert = True | ||
+ | for index in range(anzahlVariablen): | ||
+ | Wert = Wert and x[index] | ||
+ | return Wert | ||
+ | |||
+ | def ExOder(): | ||
+ | Wert = False | ||
+ | for index in range(anzahlVariablen): | ||
+ | Wert = Wert ^ x[index] | ||
+ | return Wert | ||
+ | |||
+ | def Erhoehe(nr, feld): | ||
+ | index = anzahlVariablen - 1 | ||
+ | while feld[index] == True: | ||
+ | x[index] = False | ||
+ | index -= 1 | ||
+ | if index >= 0: | ||
+ | x[index] = True | ||
+ | |||
+ | UeberschriftxTeil = "" | ||
+ | for index in range(anzahlVariablen): | ||
+ | UeberschriftxTeil += f" | ||
+ | Ueberschrift = f" | ||
+ | print(Ueberschrift) | ||
+ | print(" | ||
+ | |||
+ | for Zeile in range(2**anzahlVariablen): | ||
+ | xTeil = "" | ||
+ | for index in range(anzahlVariablen): | ||
+ | xTeil += f" | ||
+ | print(f" | ||
+ | Erhoehe(Zeile, | ||
+ | </ | ||
+ | |||
+ | ====== ... und nun noch etwas rumgesponnen ... ====== | ||
+ | |||
+ | <code python wahrheitstabelle-step3-per-binaerdarstellung.py> | ||
+ | """ | ||
+ | Truth tables | ||
+ | """ | ||
+ | leerzeichen = 4 # sollte mindestens 4 sein | ||
+ | |||
+ | # Unicode-Nummern gefunden auf https:// | ||
+ | vertikal = ' | ||
+ | horizontal = ' | ||
+ | kreuzung = ' | ||
+ | |||
+ | anzahlVariablen = int(input(" | ||
+ | |||
+ | UeberschriftVariablenTeil = "" | ||
+ | UeberschriftLogikTeil = f" | ||
+ | print(UeberschriftVariablenTeil + " " + vertikal + UeberschriftLogikTeil) | ||
+ | print(horizontal * (len(UeberschriftVariablenTeil) + 1) + kreuzung + horizontal * len(UeberschriftLogikTeil)) | ||
+ | |||
+ | for index in range(2 ** anzahlVariablen): | ||
+ | binaer = f' | ||
+ | binearMitAbstand = "" | ||
+ | # # ausführlich: | ||
+ | # und = " | ||
+ | # oder = " | ||
+ | # xOder = " | ||
+ | # print(binearMitAbstand + " vertikal" | ||
+ | |||
+ | # kurz: | ||
+ | print(binearMitAbstand + " " + vertikal + f" | ||
+ | </ | ||
+ | |||
+ | |||
+ | ====== Turtle-Test ====== | ||
+ | |||
+ | <code python> | ||
+ | from turtle import * | ||
+ | speed(0) | ||
+ | shape(" | ||
+ | |||
+ | n = 11 | ||
+ | s = 230 | ||
+ | |||
+ | pencolor(" | ||
+ | pensize(4) | ||
+ | fillcolor(" | ||
+ | |||
+ | a = 300 | ||
+ | penup() | ||
+ | goto(0.7*a, 0.5*a) | ||
+ | pendown() | ||
+ | setheading(90) | ||
+ | pendown() | ||
+ | |||
+ | begin_fill() | ||
+ | for i in range(n): | ||
+ | forward(s) | ||
+ | left(180 - 180/n) | ||
+ | end_fill() | ||
+ | |||
+ | </ | ||
+ |