Merge branch 'master' of http://git.olli-cloud.de:3000/raspithek/pythonkurs
This commit is contained in:
@@ -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|
|
||||
|
||||
|
5
teil2/range.py
Normal file
5
teil2/range.py
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
for zahl in range(1,11,2):
|
||||
print(zahl)
|
||||
|
9
teil3/berechne_flaeche.py
Normal file
9
teil3/berechne_flaeche.py
Normal 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
9
teil3/import.py
Normal 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
14
teil3/kommentare.py
Normal 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
7
teil3/kreis.py
Normal 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
9
teil3/parameter.py
Normal 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}")
|
7
teil4/beispielstrings.py
Normal file
7
teil4/beispielstrings.py
Normal file
@@ -0,0 +1,7 @@
|
||||
# coding = 'utf-8'
|
||||
|
||||
s1 = 'Homer'
|
||||
s2 = '1969'
|
||||
s3 = 'Dies ist ein ganzer Satz.'
|
||||
s4 = 'Auf den Alkohol - Der Beginn und die Lösung sämtlicher Lebenprobleme. (Homer Simpson)'
|
||||
|
5
teil4/f-string-format.py
Normal file
5
teil4/f-string-format.py
Normal file
@@ -0,0 +1,5 @@
|
||||
import math
|
||||
|
||||
|
||||
print(f'Pi ist {math.pi}')
|
||||
print(f'Pi ist {math.pi:.2f}')
|
1
teil4/find_case_insesitive.py
Normal file
1
teil4/find_case_insesitive.py
Normal file
@@ -0,0 +1 @@
|
||||
print('Homer'.lower().find('home'.lower()))
|
12
teil4/find_eigen.py
Normal file
12
teil4/find_eigen.py
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
def find_in_string(s, c):
|
||||
|
||||
for pos in range(0,len(s)):
|
||||
if(s[pos] == c):
|
||||
return pos
|
||||
return -1
|
||||
|
||||
|
||||
print(find_in_string('Homer','e'))
|
||||
print(find_in_string('Homer','n'))
|
||||
|
5
teil4/find_intern.py
Normal file
5
teil4/find_intern.py
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
print('Homer'.find('e'))
|
||||
print('Homer'.find('n'))
|
||||
|
2
teil4/find_string.py
Normal file
2
teil4/find_string.py
Normal file
@@ -0,0 +1,2 @@
|
||||
print('Homer'.find('Home'))
|
||||
print('Homer'.find('home'))
|
6
teil4/fstring.py
Normal file
6
teil4/fstring.py
Normal file
@@ -0,0 +1,6 @@
|
||||
a=5
|
||||
b=10
|
||||
|
||||
produkt = a * b
|
||||
|
||||
print(f'Das Produkt aus {a} und {b} ist {produkt}')
|
7
teil4/split.py
Normal file
7
teil4/split.py
Normal file
@@ -0,0 +1,7 @@
|
||||
s = 'Dies ist ein ganzer Satz.'
|
||||
|
||||
print(f'zerlegt= {s.split()}')
|
||||
|
||||
werte = '1,2,3,4,5,6,7,8,9'
|
||||
|
||||
print(f'werteliste = {werte.split(",")}')
|
3
teil4/str_upp_lower.py
Normal file
3
teil4/str_upp_lower.py
Normal file
@@ -0,0 +1,3 @@
|
||||
print('Homer'.lower())
|
||||
print('Homer'.upper())
|
||||
print('homer'.capitalize())
|
5
teil4/string_iter.py
Normal file
5
teil4/string_iter.py
Normal file
@@ -0,0 +1,5 @@
|
||||
s = 'Homer'
|
||||
|
||||
for pos in range(0,len(s)):
|
||||
print(s[pos])
|
||||
|
3
teil4/stringlaenge.py
Normal file
3
teil4/stringlaenge.py
Normal file
@@ -0,0 +1,3 @@
|
||||
s1 = 'Homer'
|
||||
|
||||
print(len(s1))
|
5
teil4/strip.py
Normal file
5
teil4/strip.py
Normal file
@@ -0,0 +1,5 @@
|
||||
s= ' mit Leerzeichen '
|
||||
|
||||
s = s.strip()
|
||||
print(f'*{s}*')
|
||||
|
1
teil4/title.py
Normal file
1
teil4/title.py
Normal file
@@ -0,0 +1 @@
|
||||
print('dr. nick riviera'.title())
|
23
teil5/dict/iter_kfz.py
Normal file
23
teil5/dict/iter_kfz.py
Normal 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
12
teil5/dict/kfz.py
Normal 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
7
teil5/lists/append.py
Normal file
@@ -0,0 +1,7 @@
|
||||
namen = ["Homer", "Marge", "Bart"]
|
||||
|
||||
|
||||
namen.append('Lisa')
|
||||
namen.append('Maggie')
|
||||
|
||||
print(namen)
|
9
teil5/lists/del.py
Normal file
9
teil5/lists/del.py
Normal 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
6
teil5/lists/extend.py
Normal file
@@ -0,0 +1,6 @@
|
||||
zahlen1 = ['0','1','2','3','4','5']
|
||||
zahlen2 = ['6','7','8','9']
|
||||
|
||||
zahlen1.extend(zahlen2)
|
||||
|
||||
print(zahlen1)
|
4
teil5/lists/iter_namen.py
Normal file
4
teil5/lists/iter_namen.py
Normal 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
5
teil5/lists/namen.py
Normal 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
8
teil5/lists/sort.py
Normal 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
3
teil5/tupel/tupel.py
Normal file
@@ -0,0 +1,3 @@
|
||||
coords = (51.2562,7.1508)
|
||||
|
||||
print(coords)
|
BIN
teil6/__pycache__/person.cpython-39.pyc
Normal file
BIN
teil6/__pycache__/person.cpython-39.pyc
Normal file
Binary file not shown.
9
teil6/anschrift.py
Normal file
9
teil6/anschrift.py
Normal 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
5
teil6/person.py
Normal file
@@ -0,0 +1,5 @@
|
||||
class Person:
|
||||
# Konstruktor
|
||||
def __init__(self,vorname, name):
|
||||
self.vorname = vorname
|
||||
self.name = name
|
16
teil6/personMitAnschrift.py
Normal file
16
teil6/personMitAnschrift.py
Normal 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
4
teil6/useperson.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from person import Person
|
||||
|
||||
p = Person('Olli','Graf')
|
||||
print(p.vorname)
|
34
teil6/vererbung.py
Normal file
34
teil6/vererbung.py
Normal 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))
|
Reference in New Issue
Block a user