Teil 6 "Objekte ist neu

Repository aufgeräumt.
This commit is contained in:
2023-02-24 06:41:05 +01:00
parent c21159f36f
commit 3d8cb9128d
34 changed files with 196 additions and 0 deletions

View File

@@ -9,4 +9,7 @@ CC-BY-SA Olli Graf
| 2 | Kontrollstrukturen (Schleifen und Bedingungen)|
| 3 | Methoden (inkl. import)|
| 4 | Strings|
| 5 | Listen Dictionaries und Tupel|
| 6 | Objekte|
| 7 | Module|

View File

@@ -0,0 +1,9 @@
PI = 3.1415
r=10
def berechne_flaecheninhalt():
a = PI * r**2
return a
flaeche = berechne_flaecheninhalt()
print(f"Der Flächeninhalt beträgt: {flaeche}")

9
teil3/import.py Normal file
View File

@@ -0,0 +1,9 @@
import math
#PI = 3.1415
def berechne_flaecheninhalt(r):
a = math.pi * r**2
return a
flaeche = berechne_flaecheninhalt(10)
print(f"Der Flächeninhalt beträgt: {flaeche}")

14
teil3/kommentare.py Normal file
View File

@@ -0,0 +1,14 @@
#math Package importieren
import math
#PI = 3.1415
# berechnet den Flächeninhalt eines Kreises
# mit dem Radius r
# Parameter: r - Radius des Kreises
def berechne_flaecheninhalt(r):
a = math.pi * r**2
return a
flaeche = berechne_flaecheninhalt(10)
print(f"Der Flächeninhalt beträgt: {flaeche}")

7
teil3/kreis.py Normal file
View File

@@ -0,0 +1,7 @@
PI = 3.1415
r=10
a = PI * r*r
print(f'Der Flächeninhalt beträgt: {a}')

9
teil3/parameter.py Normal file
View File

@@ -0,0 +1,9 @@
PI = 3.1415
def berechne_flaecheninhalt(r):
a = PI * r**2
return a
flaeche = berechne_flaecheninhalt(10)
print(f"Der Flächeninhalt beträgt: {flaeche}")

23
teil5/dict/iter_kfz.py Normal file
View File

@@ -0,0 +1,23 @@
# encoding utf-8
kfz = {
'W':'Wuppertal',
'HH':'Hamburg',
'D':'Düsseldorf',
'DO':'Dortmund',
'H':'Hannover',
'M':'München'}
for key in kfz:
print(f' Kennzeichen {key} -> Stadt {kfz[key]}')
print()
for key, stadt in kfz.items():
print(f' Kennzeichen {key} -> Stadt {stadt}')
items = kfz.items()
keys = kfz.keys()
print(items)
print(keys)

12
teil5/dict/kfz.py Normal file
View File

@@ -0,0 +1,12 @@
# encoding utf-8
kfz = {
'W':'Wuppertal',
'HH':'Hamburg',
'D':'Düsseldorf',
'DO':'Dortmund',
'H':'Hannover',
'M':'München'}
print(kfz)
print(kfz['W'])

7
teil5/lists/append.py Normal file
View File

@@ -0,0 +1,7 @@
namen = ["Homer", "Marge", "Bart"]
namen.append('Lisa')
namen.append('Maggie')
print(namen)

9
teil5/lists/del.py Normal file
View File

@@ -0,0 +1,9 @@
zahlen1 = ['0','1','4','3','2','5']
zahlen2 = ['8','7','9','6']
zahlen1.extend(zahlen2)
print(f'komplett:{zahlen1}')
zahlen1.sort()
del zahlen1[3]
print(f'nach del:{zahlen1}')

6
teil5/lists/extend.py Normal file
View File

@@ -0,0 +1,6 @@
zahlen1 = ['0','1','2','3','4','5']
zahlen2 = ['6','7','8','9']
zahlen1.extend(zahlen2)
print(zahlen1)

View File

@@ -0,0 +1,4 @@
namen = ["Homer", "Marge", "Bart"]
for ind in range(0,len(namen)):
print(f'{ind}: {namen[ind]}')

5
teil5/lists/namen.py Normal file
View File

@@ -0,0 +1,5 @@
namen = ["Homer", "Marge", "Bart"]
print(namen[0])
print(namen[1])
print(namen[2])

8
teil5/lists/sort.py Normal file
View File

@@ -0,0 +1,8 @@
zahlen1 = ['0','1','4','3','2','5']
zahlen2 = ['8','7','9','6']
zahlen1.extend(zahlen2)
print(f'unsortiert:{zahlen1}')
zahlen1.sort()
print(f'sortiert:{zahlen1}')

3
teil5/tupel/tupel.py Normal file
View File

@@ -0,0 +1,3 @@
coords = (51.2562,7.1508)
print(coords)

Binary file not shown.

9
teil6/anschrift.py Normal file
View File

@@ -0,0 +1,9 @@
class Anschrift:
def __init__(self, strasse, hausnummer, plz, ort):
self.strasse = strasse
self.hausnummer = hausnummer
self.plz = plz
self.ort = ort
def __str__(self):
return self.strasse + ' ' + self.hausnummer + '\n' + self.plz + ' ' + self.ort

5
teil6/person.py Normal file
View File

@@ -0,0 +1,5 @@
class Person:
# Konstruktor
def __init__(self,vorname, name):
self.vorname = vorname
self.name = name

View File

@@ -0,0 +1,16 @@
from anschrift import Anschrift
class Person:
# Konstruktor
def __init__(self,vorname, name,strasse,hausnummer, plz,ort):
self.vorname = vorname
self.name = name
self.anschrift = Anschrift(strasse,hausnummer,plz,ort)
def format(self):
return self.vorname + ' ' + self.name
def __str__(self):
return self.format() + '\n' + str(self.anschrift)

4
teil6/useperson.py Normal file
View File

@@ -0,0 +1,4 @@
from person import Person
p = Person('Olli','Graf')
print(p.vorname)

34
teil6/vererbung.py Normal file
View File

@@ -0,0 +1,34 @@
class Fahrzeug:
def __init__(self, marke, modell, farbe):
self.marke = marke
self.modell = modell
self.farbe = farbe
def __str__(self):
return f'{self.marke} {self.modell} {self.farbe})'
#Klasse Auto erbt von Fahrzeug
class Auto(Fahrzeug):
def __init__(self, marke, modell, farbe, ps):
super().__init__(marke, modell, farbe)
self.ps = ps
def __str__(self):
return f'{super().__str__()} mit {self.ps} PS'
#Klasse Fahhrad erbt von Fahrzeug
class Fahrrad(Fahrzeug):
def __init__(self, marke, modell, farbe):
super().__init__(marke, modell, farbe)
def __str__(self):
return super().__str__()
bond = Auto('Aston Martin','DB5','grau','286')
mcfly = Auto('Delorean', 'DMC-12','grau','132')
eliot = Fahrrad('Kuwahara','ET-1','weiß')
print(str(bond))
print(str(mcfly))
print(str(eliot))