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)