calcul_mental.py

Created by enzo-ginhoux-07

Created on October 11, 2021

3.07 KB


from random import *

def calculmental():
  choix=int(input("Choisir le niveau de 1 à 5"))
  if choix == 1:
      nb_1=randint(0,100)
      nb_2=randint(0,100)
      operation=randint(0,1)
      if operation==0:
          result = nb_1 + nb_2
          print(nb_1,"+", nb_2,"=")
          answer = float(input())
          if answer == result:
              print("bonne réponse")
              calculmental()
          else :
              print("la réponse etait :",result)
              calculmental()
      else:
          result = nb_1 - nb_2
          print(nb_1, "-", nb_2, "=")
          answer = float(input())
          if answer == result:
              print("bonne réponse")
              calculmental()
          else :
              print("la réponse etait :",result)
              calculmental()

  elif choix == 2:
      nb_1=randint(-100,100)
      nb_2=randint(-100,100)
      operation=randint(0,1)
      if operation==0:
          result = nb_1 + nb_2
          print(nb_1,"+", nb_2,"=")
          answer = float(input())
          if answer == result:
              print("bonne réponse")
              calculmental()
          else :
              print("la réponse etait :",result)
              calculmental()
      else:
          result = nb_1 - nb_2
          print(nb_1, "-", nb_2, "=")
          answer = float(input())
          if answer == result:
              print("bonne réponse")
              calculmental()
          else :
              print("la réponse etait :",result)
              calculmental()
  
  elif choix == 3:
      nb_1=randint(0,20)
      nb_2=randint(0,20)
      result = nb_1 * nb_2
      print(nb_1, "x", nb_2, "=")
      answer = float(input())
      if answer == result:
          print("bonne réponse")
          calculmental()
      else:
          print("la réponse etait :", result)
          calculmental()

  elif choix == 4:
      r=[2,4]
      nb_1 = randint(0, 10)
      nb_2 = choice(r)
      result = nb_1 / nb_2
      print(nb_1, "/", nb_2, "=")
      answer = float(input())
      if answer == result:
          print("bonne réponse")
          calculmental()
      else:
          print("la réponse etait :", result)
          calculmental()
  else:
      print("Ce niveau peut être très difficile")
      nb_1 = randint(0, 100)
      nb_2 = randint(0, 100)
      operation = randint(0, 1)
      if operation == 0:
          result = nb_1 * nb_2
          print(nb_1, "x", nb_2, "=")
          answer = float(input())
          if answer == result:
              print("bonne réponse")
              calculmental()
          else:
              print("la réponse etait :", result)
              calculmental()
      else:
          result = nb_1 * nb_2
          print(nb_1, "x", nb_2, "=")
          answer = float(input())
          if answer == result:
              print("bonne réponse")
              calculmental()
          else:
              print("la réponse etait :", result) 
              calculmental()
                
calculmental()

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.