Vorlesung 4
This commit is contained in:
65
Vorlesung 4/Uebung1.py
Normal file
65
Vorlesung 4/Uebung1.py
Normal file
@@ -0,0 +1,65 @@
|
||||
# Große Datenmenge > 1000 Datensätze
|
||||
from statistics import mean, median, stdev, variance # z.b. mean(list)
|
||||
|
||||
def inputNumericString(inp):
|
||||
try:
|
||||
float(inp)
|
||||
except ValueError:
|
||||
print("Could not convert Data to an integer")
|
||||
else:
|
||||
return float(inp).inputNumericString()
|
||||
|
||||
list = []
|
||||
print("Bitte geben Sie Ihre ersten 5 Modulnoten ein")
|
||||
list.append(int(input("Bitte geben Sie die nächste Modulnote ein: ")))
|
||||
list.append(int(input("Bitte geben Sie die nächste Modulnote ein: ")))
|
||||
list.append(int(input("Bitte geben Sie die nächste Modulnote ein: ")))
|
||||
list.append(int(input("Bitte geben Sie die nächste Modulnote ein: ")))
|
||||
list.append(int(input("Bitte geben Sie die nächste Modulnote ein: ")))
|
||||
# Weitere: .clear() .count(el) .extend(otherList) .index(el) .insert(pos,el) .len() .remove(el) .reverse .sort(reverse)
|
||||
|
||||
# 1.1
|
||||
modus = input("Bitte geben Sie 's' ein, wenn sie die Liste sortiert ausgeben möchten.")
|
||||
if modus != "s":
|
||||
print("Unsortiert: ", list)
|
||||
else:
|
||||
list.sort()
|
||||
print("Sortiert: ", list)
|
||||
|
||||
# 1.2
|
||||
needle = int(input("Welche Note soll gesucht werden?: "))
|
||||
i=0
|
||||
while i < len(list):
|
||||
if i < len(list):
|
||||
try:
|
||||
print("Die Note", needle, "ist an Listen-Position: ", list.index(needle, i, i+1)) # from pos i to pos i
|
||||
pass # not: break
|
||||
except ValueError:
|
||||
# triggers in every item, that doesnt match the needle
|
||||
pass # not: break
|
||||
i += 1
|
||||
|
||||
# 1.3
|
||||
print("Min: ", min(list))
|
||||
print("Max: ", max(list))
|
||||
print("Median: ", median(list))
|
||||
print("Mittelwert: ", mean(list))
|
||||
print("Varianz: ", variance(list))
|
||||
print("Standardabweichung: ", stdev(list))
|
||||
list.remove(5)
|
||||
print("Median (ohne 5en): ", median(list))
|
||||
print("Mittelwert (ohne 5en): ", mean(list))
|
||||
|
||||
# 1.4
|
||||
eingabe = input('Wenn gewünscht, geben Sie bitte eine weitere Note (1-5) ein: ')
|
||||
if eingabe == '1' or eingabe == '2' or eingabe == '3' or eingabe == '4' or eingabe == '5':
|
||||
neueZahl = int(eingabe)
|
||||
#print(list[list.count()])
|
||||
#storedLastItem = list[len(list)-1] # Store last item..
|
||||
#list.append(storedLastItem)
|
||||
#list.insert(0, neueZahl)
|
||||
list.append(neueZahl)
|
||||
#list.append(storedLastItem) # ReStore last item
|
||||
print(list)
|
||||
else:
|
||||
print('Anzahl der Modulnoten: ', list.count())
|
||||
Reference in New Issue
Block a user