Vorlesung 2

This commit is contained in:
dev weycloud
2021-09-23 19:58:44 +02:00
parent b842733193
commit 5562abd79b
10 changed files with 170 additions and 1 deletions

View File

@@ -12,3 +12,20 @@
- Erste Übungsprogramme - Erste Übungsprogramme
- ```HelloWorld.py``` - ```HelloWorld.py```
- ```Uebung1.py``` - ```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```

14
Vorlesung 2/Uebung1.py Normal file
View File

@@ -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) )

16
Vorlesung 2/Uebung2.py Normal file
View File

@@ -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

15
Vorlesung 2/Uebung3.py Normal file
View File

@@ -0,0 +1,15 @@
print("Ermitteln Sie den Wahrheitswert der angeführten Boolschen Ausdrücke")
print("(1) (82 < 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) ))

10
Vorlesung 2/Uebung4.py Normal file
View File

@@ -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

18
Vorlesung 2/Uebung5.py Normal file
View File

@@ -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, "€.")

11
Vorlesung 2/Uebung6.py Normal file
View File

@@ -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: ")

18
Vorlesung 2/math.py Normal file
View File

@@ -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)

21
Vorlesung 2/operatoren.py Normal file
View File

@@ -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")

29
Vorlesung 2/variablen.py Normal file
View File

@@ -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))