tables.py

Created by ph-moutou

Created on June 07, 2018

850 Bytes

Pour s’entraîner aux tables de multiplications, on peut fixer les bornes de a et b (les multiplicandes) par défaut a=2 et b=10. Le programme pose des questions jusqu’à ce que le taux de bonnes réponses soit supérieur ou égal à un tau paramétrable, par défaut égal à 90%. Pour éviter d’avoir toujours la même série de questions, changer la graine du générateur aléatoire (s)


from random import *
def tables1(s=12345,m=2,M=10,t=0.9):
  seed(s)
  br,mr,tx=0,0,0
  while tx<=t or br<=20:
    a=randint(m,M)
    b=randint(m,M)
    c=a*b
    n=int(input("{}x{}=".format(a,b)))
    if n==c:
      br+=1
      print("Oui!")
    else:
      mr+=1
      print("NON ({}x{}={})".format(a,b,c))
    tx=br/(br+mr)
  print("{} bonnes reponses sur {}".format(br,br+mr))

def tables2(s=12345,m=2,M=10,t=0.9):
  seed(s)
  br,mr,tx=0,0,0
  while tx<=t or br<=20:
    a=randint(m,M)
    b=randint(m,M)
    c=a*b
    n=int(input("{}x{}=".format(a,b)))
    if n==c:
      br+=1
      print("Oui!")
    else:
      mr+=1
      print("NON! essaie de nouveau...")
      while n!=c:
        n=int(input("{}x{}=".format(a,b)))
      print("Bravo! on continue...")
    tx=br/(br+mr)
  print("{} bonnes reponses sur {}".format(br,br+mr))

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.