Compare commits
No commits in common. "a7cf6aed5f440d4c058198393d25fe79103641fe" and "57667ac8b5bc94c01e570b11d281ff846f08df44" have entirely different histories.
a7cf6aed5f
...
57667ac8b5
|
@ -1,27 +0,0 @@
|
||||||
# personclass1.py
|
|
||||||
|
|
||||||
class Person:
|
|
||||||
name = ""
|
|
||||||
age = 0
|
|
||||||
gender = None
|
|
||||||
|
|
||||||
|
|
||||||
person = Person()
|
|
||||||
|
|
||||||
print(person)
|
|
||||||
print(person.__class__)
|
|
||||||
print(person.name)
|
|
||||||
print(person.age)
|
|
||||||
print(person.gender)
|
|
||||||
|
|
||||||
person.name = "Joe Doe"
|
|
||||||
person.age = 32
|
|
||||||
person.gender = "m"
|
|
||||||
|
|
||||||
print(person)
|
|
||||||
print(person.__class__)
|
|
||||||
print(person.name)
|
|
||||||
print(person.age)
|
|
||||||
print(person.gender)
|
|
||||||
|
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
# personclass1.py
|
|
||||||
|
|
||||||
class Person:
|
|
||||||
|
|
||||||
def __init__(self, name="", age=0, gender=None):
|
|
||||||
self.name = name
|
|
||||||
self.age = age
|
|
||||||
self.gender = gender
|
|
||||||
|
|
||||||
|
|
||||||
person1 = Person()
|
|
||||||
|
|
||||||
print(person1)
|
|
||||||
print(person1.__class__)
|
|
||||||
print(person1.name)
|
|
||||||
print(person1.age)
|
|
||||||
print(person1.gender)
|
|
||||||
|
|
||||||
person2 = Person("Joe Doe", 32, gender="m")
|
|
||||||
|
|
||||||
print(person2)
|
|
||||||
print(person2.__class__)
|
|
||||||
print(person2.name)
|
|
||||||
print(person2.age)
|
|
||||||
print(person2.gender)
|
|
||||||
|
|
||||||
|
|
|
@ -1,142 +0,0 @@
|
||||||
# Ausgangslage
|
|
||||||
|
|
||||||
salaries_1 = {'Anna': 2000, 'Mark': 3000, 'Judith': 3500, 'Thomas': 2500}
|
|
||||||
salaries_2 = {'Barbara': 3000, 'Elke': 3300, 'Michael': 2800, 'Johann': 2000}
|
|
||||||
|
|
||||||
# Aufgabe 1:
|
|
||||||
|
|
||||||
salaries_all = salaries_1.copy()
|
|
||||||
salaries_all.update(salaries_2)
|
|
||||||
|
|
||||||
print(salaries_all)
|
|
||||||
|
|
||||||
print("-" * 50)
|
|
||||||
|
|
||||||
# Aufgabe 2:
|
|
||||||
|
|
||||||
employee = ""
|
|
||||||
max_salary = 0
|
|
||||||
sum_salary = 0
|
|
||||||
|
|
||||||
for name, salary in salaries_all.items():
|
|
||||||
if salary > max_salary:
|
|
||||||
max_salary = salary
|
|
||||||
employee = name
|
|
||||||
sum_salary += salary
|
|
||||||
|
|
||||||
print("Topverdiener:", employee, max_salary)
|
|
||||||
|
|
||||||
print("-" * 50)
|
|
||||||
|
|
||||||
# Aufgabe 3:
|
|
||||||
|
|
||||||
print("Summe:", sum_salary)
|
|
||||||
|
|
||||||
# Aufgabe 3 alternativ:
|
|
||||||
|
|
||||||
print("Summe:", sum(salaries_all.values()))
|
|
||||||
|
|
||||||
print("-" * 50)
|
|
||||||
|
|
||||||
# Aufgabe 4:
|
|
||||||
|
|
||||||
salaries_new = {}
|
|
||||||
|
|
||||||
for key in salaries_all:
|
|
||||||
salaries_new[key] = salaries_all[key] * 1.1
|
|
||||||
|
|
||||||
# Aufgabe 5:
|
|
||||||
|
|
||||||
heading = "Name Gehalt"
|
|
||||||
print(heading)
|
|
||||||
print("-" * len(heading))
|
|
||||||
for name, salary in salaries_new.items():
|
|
||||||
print(name.ljust(8), int(salary))
|
|
||||||
|
|
||||||
print("-" * 50)
|
|
||||||
|
|
||||||
# Aufgabe 6:
|
|
||||||
|
|
||||||
heading = "Name Gehalt"
|
|
||||||
print(heading)
|
|
||||||
print("-" * len(heading))
|
|
||||||
for name, salary in salaries_all.items():
|
|
||||||
print(name.ljust(8), int(salary))
|
|
||||||
|
|
||||||
print("-" * 50)
|
|
||||||
|
|
||||||
# Aufgabe 5 & 6 mit Funktion
|
|
||||||
|
|
||||||
def print_salary_list(data, col_width=8):
|
|
||||||
heading = "Name".ljust(col_width) + "Gehalt"
|
|
||||||
print(heading)
|
|
||||||
print("-" * len(heading))
|
|
||||||
for name, salary in data.items():
|
|
||||||
print(name.ljust(col_width), int(salary))
|
|
||||||
|
|
||||||
print_salary_list(salaries_new, 10)
|
|
||||||
print("-" * 50)
|
|
||||||
print_salary_list(salaries_all, 10)
|
|
||||||
|
|
||||||
print("-" * 50)
|
|
||||||
|
|
||||||
# Bonusaufgabe 1:
|
|
||||||
|
|
||||||
def print_ordered_salary_list(data, col_width=8):
|
|
||||||
heading = "Name".ljust(col_width) + "Gehalt"
|
|
||||||
print(heading)
|
|
||||||
print("-" * len(heading))
|
|
||||||
|
|
||||||
salary_first = []
|
|
||||||
for name, salary in data.items():
|
|
||||||
salary_first.append((salary, name))
|
|
||||||
|
|
||||||
for salary, name in sorted(salary_first, reverse=True):
|
|
||||||
print(name.ljust(col_width), int(salary))
|
|
||||||
|
|
||||||
print_ordered_salary_list(salaries_new)
|
|
||||||
|
|
||||||
print("-" * 50)
|
|
||||||
|
|
||||||
# Bonusaufgabe 2:
|
|
||||||
|
|
||||||
def print_enumerated_salary_list(data, col_width=8):
|
|
||||||
heading = "Nr. " + "Name".ljust(col_width) + "Gehalt"
|
|
||||||
print(heading)
|
|
||||||
print("-" * len(heading))
|
|
||||||
|
|
||||||
salary_first = []
|
|
||||||
for name, salary in data.items():
|
|
||||||
salary_first.append((salary, name))
|
|
||||||
|
|
||||||
for i, (salary, name) in enumerate(sorted(salary_first, reverse=True)):
|
|
||||||
print(str(i+1).rjust(3), name.ljust(col_width), int(salary))
|
|
||||||
|
|
||||||
print_enumerated_salary_list(salaries_new)
|
|
||||||
|
|
||||||
print("-" * 50)
|
|
||||||
|
|
||||||
# Bonusaufgabe 3:
|
|
||||||
|
|
||||||
print("Gehaltsdurchschnitt:", sum(salaries_new.values()) / len(salaries_new))
|
|
||||||
|
|
||||||
print("-" * 50)
|
|
||||||
|
|
||||||
# Bonusaufgabe 4:
|
|
||||||
|
|
||||||
def print_extended_salary_list(data, col_width=8):
|
|
||||||
mean_salary = sum(data.values()) / len(data)
|
|
||||||
|
|
||||||
heading = "Nr. " + "Name".ljust(col_width + 1) + "Gehalt".ljust(col_width +1) + "% d. ø"
|
|
||||||
print(heading)
|
|
||||||
print("-" * len(heading))
|
|
||||||
|
|
||||||
salary_first = []
|
|
||||||
for name, salary in data.items():
|
|
||||||
salary_first.append((salary, name))
|
|
||||||
|
|
||||||
for i, (salary, name) in enumerate(sorted(salary_first, reverse=True)):
|
|
||||||
print(str(i+1).rjust(3), name.ljust(col_width), str(int(salary)).ljust(col_width), round(salary / (mean_salary / 100), 2))
|
|
||||||
|
|
||||||
print_extended_salary_list(salaries_new)
|
|
||||||
|
|
|
@ -19,12 +19,9 @@ Schreiben Sie ein Programm, das die beiden Dictionaries in einem neuen
|
||||||
Dictionary (`salaries_all`) zusammenführt und die Namen aller Mitarbeiter
|
Dictionary (`salaries_all`) zusammenführt und die Namen aller Mitarbeiter
|
||||||
als Liste ausgibt.
|
als Liste ausgibt.
|
||||||
|
|
||||||
Tipp: Machen Sie zunächst eine Kopie des ersten Dictionaries ([dict.copy]`()`)
|
Tipp: Machen Sie zunächst eine Kopie des ersten Dictionaries (`dict.copy()`)
|
||||||
und fügen Sie dann die Einträge des zweiten Dictionaries der Kopie hinzu
|
und fügen Sie dann die Einträge des zweiten Dictionaries der Kopie hinzu
|
||||||
([dict.update]`()`).
|
(`dict.update()`).
|
||||||
|
|
||||||
[dict.copy]: https://docs.python.org/3/library/stdtypes.html#dict.copy
|
|
||||||
[dict.update]: https://docs.python.org/3/library/stdtypes.html#dict.update
|
|
||||||
|
|
||||||
|
|
||||||
## Aufgabe 2:
|
## Aufgabe 2:
|
||||||
|
@ -43,8 +40,8 @@ ermittelt und diese ausgibt.
|
||||||
## Aufgabe 4:
|
## Aufgabe 4:
|
||||||
|
|
||||||
Schreiben Sie ein Programm, das das Gehalt aller Mitarbeiter um 10% erhöht und
|
Schreiben Sie ein Programm, das das Gehalt aller Mitarbeiter um 10% erhöht und
|
||||||
diese Daten in einem *neuen* Dictionary (z.B. `salaries_new`) mit der selben
|
diese Daten in einem *neuen* Dictionary mit der selben Struktur speichert. Das
|
||||||
Struktur speichert. Das ursprüngliche Dictionary soll *nicht* verändert werden.
|
ursprüngliche Dictionary soll nicht verändert werden.
|
||||||
|
|
||||||
|
|
||||||
## Aufgabe 5:
|
## Aufgabe 5:
|
||||||
|
@ -59,10 +56,7 @@ Mark ???
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
Tipp: verwenden Sie die String-Methode [ljust]`()` für die Ausgabe der ersten
|
Tipp: verwenden Sie die Escape-Sequenz für Tabulatoren `\t`.
|
||||||
Spalte, um die zweite Spalte auszurichten.
|
|
||||||
|
|
||||||
[ljust]: https://docs.python.org/3/library/stdtypes.html#str.ljust
|
|
||||||
|
|
||||||
|
|
||||||
## Aufgabe 6:
|
## Aufgabe 6:
|
||||||
|
@ -76,7 +70,7 @@ um zu zeigen, dass das ursprüngliche Dictionary nicht verändert wurde.
|
||||||
|
|
||||||
1. Sortieren Sie die Liste nach Höhe des Gehalts (absteigend).
|
1. Sortieren Sie die Liste nach Höhe des Gehalts (absteigend).
|
||||||
|
|
||||||
Tipp: verwenden Sie die Funktion [sorted]`()` zum Sortieren.
|
Tipp: verwenden Sie die Funktion `sorted()` zum Sortieren.
|
||||||
|
|
||||||
2. Nummerieren Sie die Listeneinträge in der Ausgabe, startend mit 1.
|
2. Nummerieren Sie die Listeneinträge in der Ausgabe, startend mit 1.
|
||||||
|
|
||||||
|
@ -91,9 +85,6 @@ um zu zeigen, dass das ursprüngliche Dictionary nicht verändert wurde.
|
||||||
Wert im Dictionary ablegen.
|
Wert im Dictionary ablegen.
|
||||||
|
|
||||||
|
|
||||||
[sorted]: https://docs.python.org/3/library/functions.html#sorted
|
|
||||||
|
|
||||||
|
|
||||||
## Ressourcen
|
## Ressourcen
|
||||||
|
|
||||||
Hilfe zu Dictionaries:
|
Hilfe zu Dictionaries:
|
||||||
|
|
Loading…
Reference in New Issue