declic2de57p351.py

Created by gilles-dhaussy

Created on June 04, 2024

821 Bytes


from random import randint

# On a recopie le script initial de l'énonce.
"""
a=randint(1,4)
b=randint(1,4)
s=a+b
print(a,b,s)
if s==2:
  print('Gagne')
else:
  print('Perdu')
"""

# On crée une fonction pour faciliter
# le calcul du nombre de gains et
# de la fréquence du gain de n lancers.
def jeu(n=10):
  g=0
  for i in range(n):
    a=randint(1,4)
    b=randint(1,4)
    s=a+b
    if n<=20:
      print('lancer:{} dé1:{} dé2:{} somme:{}'.format(i+1,a,b,s))
    if s==2:
      g+=1
  f=g/n
  print()
  print('Avec les', n, 'lancers:')
  print('le nombre de gain est', g)
  print('la frequence du gain est', f)

# On effectue 10 lancers (par défaut).
jeu()
# On effectue 1000 lancers et plus, pour obtenir
# une fréquence plus proche de la probabilité.
jeu(1000)
jeu(10000)
jeu(1000000)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.