Created
April 9, 2017 22:36
-
-
Save rwenz3l/8b28dd1c6d96a118609dbc1020ef9fd3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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