lehrkraefte:blc:informatik:glf4-20:simulation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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,1000)
 </code>   </code>  
 </hidden> </hidden>
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,1000)) 
 + 
 +largest = 0 
 +for i in numbers: 
 +    if i > largest: 
 +        largest = i 
 + 
 +print largest
 </code>   </code>  
 </hidden> </hidden>
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: Würfeln Sie eine Zahl z. Anschliessend prüfen Sie, ob die die Zahl z noch nicht gewürfelt wurde (ist sie in meiner Liste). Wenn ja (dh noch nicht gewürfelt), dann fügen Sie diese Zahl zu "meiner Liste" hinzu. Anschliessend ...
- +
  
 <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,6)                # es wird gewürfelt 
 +        if (not z in numbers):          # wenn Zahl bis jetzt noch nicht gewürfelt 
 +            numbers.append(z)           # Zahl hinzufügen 
 +            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
 </code>   </code>  
 </hidden> </hidden>
  • lehrkraefte/blc/informatik/glf4-20/simulation.txt
  • Last modified: 2021/03/26 15:31
  • by michael.greminger