From 5562abd79bda1d9f7d6a951eaf16e939a89051d5 Mon Sep 17 00:00:00 2001 From: dev weycloud Date: Thu, 23 Sep 2021 19:58:44 +0200 Subject: [PATCH] Vorlesung 2 --- README.md | 19 ++++++++++++++++++- Vorlesung 2/Uebung1.py | 14 ++++++++++++++ Vorlesung 2/Uebung2.py | 16 ++++++++++++++++ Vorlesung 2/Uebung3.py | 15 +++++++++++++++ Vorlesung 2/Uebung4.py | 10 ++++++++++ Vorlesung 2/Uebung5.py | 18 ++++++++++++++++++ Vorlesung 2/Uebung6.py | 11 +++++++++++ Vorlesung 2/math.py | 18 ++++++++++++++++++ Vorlesung 2/operatoren.py | 21 +++++++++++++++++++++ Vorlesung 2/variablen.py | 29 +++++++++++++++++++++++++++++ 10 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 Vorlesung 2/Uebung1.py create mode 100644 Vorlesung 2/Uebung2.py create mode 100644 Vorlesung 2/Uebung3.py create mode 100644 Vorlesung 2/Uebung4.py create mode 100644 Vorlesung 2/Uebung5.py create mode 100644 Vorlesung 2/Uebung6.py create mode 100644 Vorlesung 2/math.py create mode 100644 Vorlesung 2/operatoren.py create mode 100644 Vorlesung 2/variablen.py diff --git a/README.md b/README.md index 12d2b9a..1f96a4d 100644 --- a/README.md +++ b/README.md @@ -11,4 +11,21 @@ - _(alternativ z.b. Visual Studio Code: https://code.visualstudio.com/docs/python/python-tutorial)_ - Erste Übungsprogramme - ```HelloWorld.py``` - - ```Uebung1.py``` \ No newline at end of file + - ```Uebung1.py``` + +# Vorlesung 2 +23.09.2021 + +- ```Vorlesung II.pdf``` + - Variablen und Datentypen + - ```variablen.py``` + - Operatoren und das Modul „math“ + - ```operatoren.py``` + - ```math.py``` + - Übungen + - ```Uebung1.py``` + - ```Uebung2.py``` + - ```Uebung3.py``` + - ```Uebung4.py``` + - ```Uebung5.py``` + - ```Uebung6.py``` \ No newline at end of file diff --git a/Vorlesung 2/Uebung1.py b/Vorlesung 2/Uebung1.py new file mode 100644 index 0000000..1b3d370 --- /dev/null +++ b/Vorlesung 2/Uebung1.py @@ -0,0 +1,14 @@ +# 1. Was gibt das folgende Programm am Bildschirm aus? +# Gehen Sie es erst im Kopf durch und notieren Sie Ihre Vermutungen. +# Prüfen Sie dann mit der Kommandozeile. + +x = 2 +y = 3 +z = x + y +print(x) +print(z) +print(x, y, z) +print( "x:", x, "y:", y) +print( "x:", x, "\ny:", y) +print(x == y) +print( (z > x) and (x != y) ) \ No newline at end of file diff --git a/Vorlesung 2/Uebung2.py b/Vorlesung 2/Uebung2.py new file mode 100644 index 0000000..cbdf2dd --- /dev/null +++ b/Vorlesung 2/Uebung2.py @@ -0,0 +1,16 @@ +# + +a = input("Bitte geben Sie die erste Zahl ein: (z.b. 2)") +b = input("Bitte geben Sie die zweite Zahl ein: (z.b. 3)") + +a = int(a) +b = int(b) + +# a = 2 +# b = 3 + +print(a**3) # 8 + +print(5*a**4 + 7*b**3) # 269 + +print( (3*a+9)**3 / (4*b)**(1/2) ) # 974.2785792574936 \ No newline at end of file diff --git a/Vorlesung 2/Uebung3.py b/Vorlesung 2/Uebung3.py new file mode 100644 index 0000000..094be6f --- /dev/null +++ b/Vorlesung 2/Uebung3.py @@ -0,0 +1,15 @@ +print("Ermitteln Sie den Wahrheitswert der angeführten Boolschen Ausdrücke") + +print("(1) (8−2 < 6) and (7! = 3)") +print("(2) (8 > 2) or (7 <= 3)") +print("(3) (8 == 8) and (16 % 2 == 3)") +print("(4) (8 ! = 4) or ( (−1 < 2) and (7 > 3) )") + +input("Enter drücken") + +import math + +#print("(1)", ( (8-2 < 6) and (math.factorial(7) == 3) ) +print("(2)", (8 > 2) or (7 <= 3) ) +print("(3)", (8 == 8) and (16 % 2 == 3)) +#print("(4)", ((math.factorial(8) == 4) or ( (-1 < 2) and (7 > 3) )) \ No newline at end of file diff --git a/Vorlesung 2/Uebung4.py b/Vorlesung 2/Uebung4.py new file mode 100644 index 0000000..20a4b8a --- /dev/null +++ b/Vorlesung 2/Uebung4.py @@ -0,0 +1,10 @@ +celsius = input("Bitte geben Sie eine Temperatur in Celsius an: ") # z.b.: 32 + +celsius = int(celsius) + +fahrenheit = celsius * (9/5) + 32 +kelvin = celsius + 273.15 + +# Bspw. 32° Celsius: +print("Fahrenheit: ", round(fahrenheit,2)) # = 89.6 +print("Kelvin: ", round(kelvin,2)) # = 305.15 \ No newline at end of file diff --git a/Vorlesung 2/Uebung5.py b/Vorlesung 2/Uebung5.py new file mode 100644 index 0000000..0fdab56 --- /dev/null +++ b/Vorlesung 2/Uebung5.py @@ -0,0 +1,18 @@ +# steuerrechner.py + +gehalt = int(input("Bitte geben Sie Ihr Bruttogehalt ein: ")) +familienstand = input("Bitte geben Sie Ihren Familienstand ein (ledig/verheiratet): ") + +if (gehalt > 4000 and familienstand == "ledig"): + steuer = gehalt * 0.26 + +if (gehalt > 4000 and familienstand == "verheiratet"): + steuer = gehalt * 0.22 + +if (gehalt <= 4000 and familienstand == "ledig"): + steuer = gehalt * 0.22 + +if (gehalt <= 4000 and familienstand == "verheiratet"): + steuer = gehalt * 0.18 + +print("Es ergibt sich eine Steuer von ", steuer, "€.") \ No newline at end of file diff --git a/Vorlesung 2/Uebung6.py b/Vorlesung 2/Uebung6.py new file mode 100644 index 0000000..99bbd5c --- /dev/null +++ b/Vorlesung 2/Uebung6.py @@ -0,0 +1,11 @@ +# pq formel + +print("Berechnung mittels pq-Formel.") + +a = input("a =") +b = input("b =") +c = input("c =") + +# pq = a*x**2 + b*x + c = 0 + +print("Ergebnis: ") \ No newline at end of file diff --git a/Vorlesung 2/math.py b/Vorlesung 2/math.py new file mode 100644 index 0000000..6c57d84 --- /dev/null +++ b/Vorlesung 2/math.py @@ -0,0 +1,18 @@ +# Das Modul "math" + +import math as m + +# Einige wichtige Funktionen: +# exp(x) # return e**x +# log(a[,b]) # returns log of x to the base b +# sqrt(x) # Wurzel aus x +# pi # Zahl PI +# e # eulersche Zahl +# comb(n,k) # Binominalkoeffizient +# fabs(x) # returns absolut value of x +# gcd(a,b) # returns GGT +# pow(x,y) # berechnet x hoch y + +# 2³ = 8 +twoPower3 = m.pow(2, 3) +print("2³ =", twoPower3) \ No newline at end of file diff --git a/Vorlesung 2/operatoren.py b/Vorlesung 2/operatoren.py new file mode 100644 index 0000000..01117da --- /dev/null +++ b/Vorlesung 2/operatoren.py @@ -0,0 +1,21 @@ +# Operatoren + +# Positive Zahl +x = 12/7 +print("x: ", x) + +# Rundung und Konvertierung +rx = round(x,3) +print("x gerundet auf drei Stellen: ", rx) +rx = round(x) +print("x gerundet auf null Stellen: ", rx) +ix = int(x) +print("int(x): ", ix) + +# hier einige Beispiele zum Testen: +print("3/2 =", 3/2) +print("5%3 =", 5%3, "# Rest einer Ganzzahldivision") +print("5//3 =", 5//3, "# Ganzzahldivision") +print("2**3 =", 2**3, "# Potenzieren") +print("4**(1/2) =", 4**(1/2), "# naive Berechnung der Wurzel, 4^(1/2)") +print("(3*2 -4 )**2 =", (3*2 -4 )**2, "# Punkt vor Strich, Klammern und Potenz") \ No newline at end of file diff --git a/Vorlesung 2/variablen.py b/Vorlesung 2/variablen.py new file mode 100644 index 0000000..91c7cde --- /dev/null +++ b/Vorlesung 2/variablen.py @@ -0,0 +1,29 @@ +# Variablen und Datentypen + +a = True # Datentyp bool +b = False +print("a =", a, "Type: " , type(a)) + +char1 = 'A' # Datentyp char +char2 = '!' +char3 = '#' +print("char1 =", char1, "Type: " , type(char1)) + +satz = "Hallo Welt!" # Datentyp string +print("satz =", satz, "Type: " , type(satz)) + +zahl1 = 4 # Datentyp Integer speichert ganze Zahlen +print("zahl1 =", zahl1, "Type: " , type(zahl1)) + +zahl2 = 3.5 # Datentyp float +print("zahl2 =", zahl2, "Type: " , type(zahl2)) +print("zahl1 =", zahl1, "Speicher-Adresse: ", id(zahl1)) +print("zahl2 =", zahl2, "Speicher-Adresse: ", id(zahl2)) + +# zahl3 verweist jetzt auf die gleiche speicheradresse wie zahl1 +zahl3 = zahl1 +print("zahl3 =", zahl3, "Speicher-Adresse: ", id(zahl3)) + +# Typenkonvertierung: +zahl3 = str(zahl1) +print("zahl3 =", zahl3, "Type: " , type(zahl3)) \ No newline at end of file