maths.py

Created by stimorol

Created on November 16, 2023

2.09 KB

Jeu de calcul mental de maths ! (plusieurs difficultés, opérateurs)


from math import *
from random import *
from time import *
from kandinsky import *
nums=["1","2","3","4","5","6","7","8","9"]
time=[]

def calculs0(time,correctAwnser,num):
  correctAwnser+=1
  stop=False
  print()
  time1=monotonic()
  if random()<0.5:
    if eval(num[0])+eval(num[1])==int(input(num[0]+"+"+num[1]+"= ")):
      time.append(monotonic()-time1)
      print(round(time[len(time)-1],3),"s")
    else:
      stop=True
      print('Wrong, correct awnser: ',eval(num[0])+eval(num[1]))
  else:
    if eval(num[0])-eval(num[1])==int(input(num[0]+"-"+num[1]+"= ")):
      time.append(monotonic()-time1)
      print(round(time[len(time)-1],3),"s")
    else:
      stop=True
      print('Wrong, correct awnser: ',eval(num[0])-eval(num[1]))
  return time,correctAwnser,stop

def calculs1(time,correctAwnser,num):
  correctAwnser+=1
  stop=False
  print()
  time1=monotonic()
  if random()<0.5:
    if eval(num[0])*eval(num[1])==int(input(num[0]+"x"+num[1]+"= ")):
      time.append(monotonic()-time1)
      print(round(time[len(time)-1],3),"s")
    else:
      stop=True
      print('Wrong, correct awnser: ',eval(num[0])*eval(num[1]))
  else:
    if round(eval(num[0])/eval(num[1]),2)==float(input(num[0]+"/"+num[1]+"= ")):
      time.append(monotonic()-time1)
      print(round(time[len(time)-1],3),"s")
    else:
      stop=True
      print('Wrong, correct awnser: ',round(eval(num[0])/eval(num[1]),2))
  return time,correctAwnser,stop

def calculs(diff):
  stop=False
  correctAwnser=-1
  time=[]
  input("___________________________________________\n\nPret(e) ?\n")
  if diff==0:
    while not stop:time,correctAwnser,stop=calculs0(time,correctAwnser,[choice(nums),choice(nums)])
  elif diff==1:
    while not stop:
      if random()<0.5:time,correctAwnser,stop=calculs0(time,correctAwnser,[(choice(nums)+choice(nums)),(choice(nums)+choice(nums))])
      else:time,correctAwnser,stop=calculs1(time,correctAwnser,[choice(nums),choice(nums)])
  if len(time)>0:print("\nNumber of correct awnser: ",correctAwnser,"\nTemps de reponse moyen: ",round(sum(time)/(len(time)-1),5),"s")
  else:print("Vous etes NUL.\n._.")
calculs(1)

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.