# Calcul Mental - V. 2.0.0.0
fromkandinskyimport*fromionimportkeydownfromrandomimportrandintasrd,choicefromtimeimport*frommenuimport*defstart():fill_rect(0,0,320,222,(255,255,255))globalmode,ope,dif,reptry:mode,ope,dif,rep=menu("Automatismes en calcul mental","Calculer [OK]",["Mode","Classique","Rapide"],["Opération(s)","+","-","x","/","+ -"," x / ","+ - x","+ - x /"],["Difficulté"," modéré","difficile","expert","facile"],["Répétition",42,50,100,120,20],["Crédits","Site web$nsi.xyz/calcul","Auteur$Kevin Fedyna","Contributeur$Vincent ROBERT",])dif=["f","","d","e"].index(dif[0])except:mode,ope,dif,rep="Classique","+",1,42aff(1)return1# Difficulte
da=[1,9]db=[10,19]dc=[1,10]dd=[dc,[2,10]]diff={"+":[[da]*2,[db,da],[db,da],[db]*2],"-":[[da]*2,[db,da],[[10,20],[10,20]],[db]*2],"*":[[dc]*2,[dc]*2,[[2,10],[11,20]],[[1,25],[1,25]]],"/":[dd,dd,dd,[[1,20],[2,20]]]}defmel(a,b):l=[a,b]a=l[rd(0,1)]l.remove(a)b=l[0]returna,bdefdraw_line(x,y,clr,*ts):fortints:d=list(map(lambdan:n//abs(n)ifn!=0else0,t[0]))foriinrange(t[1]):set_pixel(x+i*d[0],y+i*d[1],clr)x+=i*d[0]y+=i*d[1]definputG(x,y):inp=""dico={46:"-",49:".",48:"0",42:"1",43:"2",44:"3",36:"4",37:"5",38:"6",30:"7",31:"8",32:"9"}while1:try:key=wait()except:fill_rect(0,0,320,222,(255,255,255))draw_string("Merci d'avoir calculé !",45,100)return"e"ifkey==6:return"h"ifkeyindico:inp+=dico[key]ifinp:ifkeyin(4,52)and(inp.count("-")==0or(inp.count("-")==1andinp[0]=="-")):returneval(inp)ifkey==17:draw_string(""*len(inp),x,y)inp=inp[:-1]draw_string(inp,x,y)defaff(mde,prog=0,a=0,b=0,op="",c=0):globalrepw=(255,255,255)ifmde==1:fill_rect(0,0,320,222,w)fill_rect(0,204,320,18,(200,200,200))foriin[-1,1]:draw_line(160,215,w,([i,0],3),([0,1],5),([i,0],5),([0,-1],7),([-i,-1],7))draw_line(295,219,w,([1,0],10),([1,-1],5),([-1,-1],5),([-1,0],10),([1,1],5),([-1,-1],5),([1,-1],5))draw_string("Automatismes en calcul mental",15,8,(42,120,224))ifmde==2:fill_rect(0,204,int(320*(prog/rep)),18,(42,204,120))ifmde==3:fill_rect(0,92,320,50,w)draw_string(str(a)+""+op+""+str(b)+" = ",180-10*len(str(a)+""+op+""+str(b)+" = "),98)ifmde==4:fill_rect(0,92,320,50,w)todraw=str(a)+""+op+""+str(b)draw_string(todraw+" = "+str(c),180-10*len(todraw+" = "),98,(251,77,61))draw_string(todraw+" = "+str(eval(todraw)),180-10*len(todraw+" = "),126,(42,204,120))wait()defcalcul():globalope,dif,rep,mode# Le generateur de calcul
exeMu=list(range(1,6))exeMu.append(10)exeDiv=[[2,10],[2,3,5,10]]juste=0chrono=0foriinrange(rep):iflen(ope)>1:op=choice(ope.split(""))else:op=opeifop=="x":op="*"while"exceptions gérées":a,b=[rd(*diff[op][dif][i])foriin[0,1]]ifopin"+-*":a,b=mel(a,b)ifop=="*"anddif==0:ifainexeMuandbinexeMu:breakelifop=="-"anddif==0:ifa>=b:breakelifop=="/":a=a*bifdifin[0,1,2]anda<=100:ifdifin[0,1]andbinexeDiv[dif]:breakifdif==2:breakifdif==3anda<=200:breakelse:breakaff(2,i)c="c"whilec=="c":aff(3,a=a,b=b,op=op*(op!="*")+"x"*(op=="*"))depart=monotonic()c=inputG(180,98)chrono+=monotonic()-departifc=="e":return"e",0ifc=="h":return"s",0ifint(c)==int(eval(str(a)+op+str(b))):juste+=1else:ifmode=="Classique":aff(4,a=a,b=b,op=op*(op!="*")+"x"*(op=="*"),c=c)returnjuste,str(round(chrono/rep,1))whilestart():justes,temps=calcul()ifjustes=="e":breakelifjustes=="s":passelse:fill_rect(0,0,320,222,(255,255,255))espace=0foriin[str(rep)+" calculs",str(rep-justes)+" erreur"+"s"*((rep-justes)>1),str(justes)+" juste"+"s"*(justes>1)]:draw_string(i,190-len(i.split("")[0]+"")*10,30+espace*28,((0,0,0),(251,77,61),(42,204,120))[espace])draw_string([mode,ope,["facile","modéré","difficile","expert"][dif]][espace],53,30+espace*28,(200,200,200))espace+=1fill_rect(53,118,214,22,(200,200,200))fill_rect(55,120,int((justes/rep)*210),18,(42,204,120))fill_rect(55+int((justes/rep)*210),120,int((1-(justes/rep))*210),18,(251,77,61))fill_rect(55+int((justes/rep)*210),120,2,18,(200,200,200))draw_string(temps+" secondes / calcul",160-5*len(temps+" secondes / calcul"),152,(200,200,200))wait()
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
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.