toscane.py

Created by elodie-gamot

Created on November 30, 2021

583 Bytes

Lancers(n) : Représentation graphique, pour n lancers, de la somme de deux dés équilibrés Moyenne(n) : Moyenne, pour n lancers, de la somme de deux dés équilibrés Freq(n) : Fréquences, pour n lancer, de l’obtention de 7 et 8


from math import *
from random import *
from matplotlib.pyplot import *

def resultat():
  return randint(1,6)+randint(1,6)
  
def lancers(n):
  lancers=[]
  bins = [x + 0.5 for x in range(1, 13)]
  for i in range(n):
    lancers.append(resultat())
  hist(lancers,bins)
  show()
  
def moyenne(n):
  somme=0
  for i in range(n):
    somme=somme+resultat()
  return(somme/n)
  
def freq(n):
  x=0
  y=0
  for i in range(n):
    d=resultat()
    if d==7:
      x+=1
    if d==8:
      y+=1
  print("Frequence de 7 =",x/n*100,"%")
  print("Frequence de 8 =",y/n*100,"%")

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 <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.