Skip to content

Instantly share code, notes, and snippets.

@rwenz3l
Created April 9, 2017 22:36
Show Gist options
  • Save rwenz3l/8b28dd1c6d96a118609dbc1020ef9fd3 to your computer and use it in GitHub Desktop.
Save rwenz3l/8b28dd1c6d96a118609dbc1020ef9fd3 to your computer and use it in GitHub Desktop.
# Variante 1: Pure Python
from random import randint
def wuerfeln(wuerfel=1, versuche=1):
ergebnis = {}
for a in range(wuerfel,(wuerfel*6)+1):
ergebnis[a] = 0
for i in range(0, versuche):
summe = 0
for j in range(0, wuerfel):
summe += randint(1,6)
ergebnis[summe] += 1
return ergebnis
def filterMaxima(uDict):
maxima = {}
current = 0
for key in uDict:
if(current < uDict[key]):
current = uDict[key]
maxima.clear()
maxima[key] = current
elif(current == uDict[key]):
maxima[key] = current;
return maxima
ergebnis = wuerfeln(20,10000)
maxima = filterMaxima(ergebnis)
for key in maxima:
print(str(key) + " wurde (mit) am häufigsten gewürfelt: " + str(maxima[key]) + " mal")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment