-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathm05_fairness.py
More file actions
37 lines (29 loc) · 873 Bytes
/
Copy pathm05_fairness.py
File metadata and controls
37 lines (29 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
Modul 05: Fairness
"""
from collections import Counter
from random import randint
import matplotlib.pyplot as plt
import numpy as np
# Ist der Würfel fair?
wuerfe = []
for i in range(1000):
wuerfe.append(randint(1, 6))
strichliste = Counter(wuerfe)
print(sorted(strichliste.items()))
for augenzahl, anzahl in sorted(strichliste.items()):
print("Augenzahl:", augenzahl, "|", str(anzahl / i * 100) + "%")
# strichliste in zwei separate Listen entpacken (deswegen zip mit *)
x_achse, y_achse = zip(*strichliste.items())
y_achse = np.array(y_achse) / i * 100
# Abbildung und Diagramm erstellen
plt.figure("Fairness von Würfeln")
plt.bar(x_achse, y_achse)
# Beschriftung hinzufügen
plt.title("Fairness")
plt.xlabel("Augenzahl")
plt.ylabel("Prozent")
# Referenzlinie hinzufügen
plt.axhline(y=16.7, color="r", linestyle="-")
# Diagramm anzeigen
plt.show()