lehrkraefte:sbt:informatik-glf2-23-4

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
lehrkraefte:sbt:informatik-glf2-23-4 [2023/03/10 07:04]
Karlheinz Schubert
lehrkraefte:sbt:informatik-glf2-23-4 [2023/03/24 13:28] (current)
Karlheinz Schubert
Line 97: Line 97:
    * Schreibe eine Funktion sim, welche das Sammelbildproblem einmal simuliert und die Anzahl nötiger Bilder ausgibt.    * Schreibe eine Funktion sim, welche das Sammelbildproblem einmal simuliert und die Anzahl nötiger Bilder ausgibt.
    * Führe sim mehrmals durch und bestimme die durchschnittliche Anzahl nötiger Bildkäufe.    * Führe sim mehrmals durch und bestimme die durchschnittliche Anzahl nötiger Bildkäufe.
 +
 +<hidden Lösungsvorschlag>
 +<code python listen.py>
 +"""
 +Simulation Sammelbilder
 +A2) Wieviele Bilder muss ein einzelner kaufen, um sein Album zu füllen?
 +"""
 +from random import randint
 +
 +
 +def sim():
 +    zaehler = 0
 +    Sammelliste = []
 +    while len(Sammelliste) < 680:
 +        einBildchen = randint(1, 681)
 +        if einBildchen in Sammelliste:
 +            zaehler += 1
 +        else:
 +            Sammelliste.append(einBildchen)
 +            zaehler += 1
 +    return zaehler
 +
 +gesamtzahl = 0
 +anzahlSimulationen = 200
 +for index in range(0, anzahlSimulationen):
 +    x = sim()
 +    gesamtzahl += x
 +
 +print("-------------------------------------------------")
 +print("Anzahl Käufe etwa: {:.0f} ({} Simulationen)".format(
 +    gesamtzahl/anzahlSimulationen, anzahlSimulationen))
 +
 +
 +# Optimiere die sim Funktion!
 +</code>
 +</hidden>
 </WRAP> </WRAP>
 <WRAP center round todo> <WRAP center round todo>
  • lehrkraefte/sbt/informatik-glf2-23-4.1678428265.txt.gz
  • Last modified: 2023/03/10 07:04
  • by Karlheinz Schubert