Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Last revision Both sides next revision | ||
lehrkraefte:blc:informatik:glf4-20:simulation [2021/03/26 13:35] michael.greminger |
lehrkraefte:blc:informatik:glf4-20:simulation [2021/03/26 15:22] michael.greminger |
||
---|---|---|---|
Line 9: | Line 9: | ||
<hidden Lösungsvorschlag> | <hidden Lösungsvorschlag> | ||
<code python> | <code python> | ||
- | kommt bald... | + | from random import randint |
+ | |||
+ | for i in range(20): | ||
+ | print randint(1, | ||
</ | </ | ||
</ | </ | ||
Line 26: | Line 29: | ||
<hidden Lösungsvorschlag> | <hidden Lösungsvorschlag> | ||
<code python> | <code python> | ||
- | kommt bald... | + | from random import randint |
+ | |||
+ | numbers=[] | ||
+ | for i in range(400): | ||
+ | numbers.append(randint(1, | ||
+ | |||
+ | largest = 0 | ||
+ | for i in numbers: | ||
+ | if i > largest: | ||
+ | largest = i | ||
+ | |||
+ | print largest | ||
</ | </ | ||
</ | </ | ||
Line 33: | Line 47: | ||
Mit welcher Wahrscheinlichkeit treten bei zehnmal Würfeln alle Zahlen mindestens einmal auf? | Mit welcher Wahrscheinlichkeit treten bei zehnmal Würfeln alle Zahlen mindestens einmal auf? | ||
- | Hinweis für die Lösung: | + | Hinweis für die Lösung: |
- | + | ||
<hidden Lösungsvorschlag> | <hidden Lösungsvorschlag> | ||
<code python> | <code python> | ||
- | kommt bald... | + | from random import randint |
+ | |||
+ | def sim(): | ||
+ | numbers = [] | ||
+ | for i in range(10): | ||
+ | z = randint(1, | ||
+ | if (not z in numbers): | ||
+ | numbers.append(z) | ||
+ | if (len(numbers) == 6): # wenn wir alle Zahlen haben | ||
+ | return 1 | ||
+ | return 0 # nicht alle Zahlen wurden gewürfelt | ||
+ | |||
+ | |||
+ | anzahlVersuche = 10000 | ||
+ | anzahlMindEinmal6 = 0 | ||
+ | for i in range(anzahlVersuche): | ||
+ | anzahlMindEinmal6 += sim() | ||
+ | |||
+ | print anzahlMindEinmal6 / anzahlVersuche | ||
</ | </ | ||
</ | </ |