Skip to content

Instantly share code, notes, and snippets.

@halexus
Created March 8, 2019 08:14
Show Gist options
  • Save halexus/c550dcaf2ca061825f8084918ba502a6 to your computer and use it in GitHub Desktop.
Save halexus/c550dcaf2ca061825f8084918ba502a6 to your computer and use it in GitHub Desktop.
Python Lösung Beispiel 4 Wahrscheinlichkeitstheorie
from itertools import product # Kartesisches Produkt
from fractions import Fraction # Brüche
def X1(w): # Augenzahl erster Würfel
return w[0]
def X2(w): # Augenzahl zweiter Würfel
return w[1]
omega = list(product(range(1,7), range(1,7))) # Ergebnismenge
print(sorted({X1(w)*X2(w) for w in omega})) # Wertemenge X1*X2
print([str(x) for x in sorted({Fraction(X1(w), X2(w)) for w in omega})]) # Wertemenge X1/X2
print(sorted({2*X1(w) - 3*X2(w) for w in omega})) # Wertemenge 2*X1 - 3*X2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment