Touche Ok pour changer la valeur d’un des champs (minimum, maximum, calcul).
from math import * from kandinsky import * from time import * from ion import * try: draw_line(0,0,0,0,(0,0,0)) except: def draw_line(x1,y1,x2,y2,c): width=x2-x1 height=y2-y1 if abs(width)>=abs(height): div=height/width for i in range(0,width,(width>0)*2-1): set_pixel(x1+i,y1+int(div*i),c) else: div=width/height for i in range(0,height,(height>0)*2-1): set_pixel(x1+int(div*i),y1+i,c) COLOR=(0,)*3 B_COLOR=(255,255,255) POINTS=[(40,91),(20,91),(30,111,),(20,131),(40,131)] max=6 start=0 formule="2*i+1" solution={ #(max,start,formule):49, } cursor=0 def draw_all(): fill_rect(0,0,320,222,B_COLOR) back_color=[B_COLOR,]*3 back_color[cursor]=(200,200,0) for i in range(4): draw_line(POINTS[i][0],POINTS[i][1],POINTS[i+1][0],POINTS[i+1][1],COLOR) draw_string(str(max),20,73,COLOR,back_color[0]) draw_string(formule,40,101,COLOR,back_color[1]) draw_string("i={}".format(start),20,132,COLOR,back_color[2]) exe() draw_string("="+str(solution[(start,max,formule)]),40+len(formule)*10,101,COLOR,B_COLOR) def exe(): global solution if (start,max,formule) in solution.keys(): return somme=0 for i in range(start,max+1): somme+=eval(formule.replace("i",str(i))) solution[(start,max,formule)]=somme while keydown(KEY_OK): pass draw_all() while True: if keydown(1) or keydown(2) or keydown(KEY_OK) or keydown(KEY_EXE): if keydown(1): cursor+=-1 if keydown(2): cursor+=1 elif keydown(KEY_OK) or keydown(KEY_EXE): if cursor==0: max=int(input("max : ")) elif cursor==1: formule=input("formule : ") elif cursor==2: start=int(input("debut : ")) cursor%=3 draw_all() sleep(0.1)