Untitled
unknown
plain_text
a year ago
4.5 kB
3
Indexable
#Clickable interaction canvas=getscreen() canvas.num1= "" canvas.operator="" canvas.num1_done= False canvas.num2= "" canvas.num2_done= False #This function will solve the question inputted def solve_question(): if canvas.operator == "+": answer = int(canvas.num1) + int(canvas.num2) write(canvas.num1 + "" + canvas.operator + "" + canvas.num2 +"="+ str(answer), font=("Arial", 15), align="right") if canvas.operator == "-": answer = int(canvas.num1) - int(canvas.num2) write(canvas.num1 + "" + canvas.operator + "" + canvas.num2 +"="+ str(answer),font=("Arial", 15), align="right") if canvas.operator == "x": answer = int(canvas.num1) * int(canvas.num2) write(canvas.num1 + "" + canvas.operator + "" + canvas.num2 +"="+ str(answer),font=("Arial", 15), align="right") if canvas.operator == "/": answer = int(canvas.num1) / int(canvas.num2) write(canvas.num1 + "" + canvas.operator + "" + canvas.num2 +"="+ str(answer),font=("Arial", 15), align="right") #This function will help you to click and write numbers & symbols def use_calculator(x,y): if canvas.num1_done == False: if x>-80 and x<-50 and y>10 and y<40: canvas.num1 += "7" elif x>-40 and x<-10 and y>10 and y<40: canvas.num1 += "8" elif x>0 and x<30 and y>10 and y<40: canvas.num1+= "9" elif x>-80 and x<-50 and y>-30 and y<0: canvas.num1 += "4" elif x>-40 and x<-10 and y>-30 and y<0: canvas.num1+= "5" elif x>0 and x<30 and y>-30 and y<0: canvas.num1 += "6" elif x>-80 and x<-50 and y>-70 and y<-40: canvas.num1+= "1" elif x>-40 and x<-10 and y>-60 and y<-30: canvas.num1 += "2" elif x>0 and x<30 and y>-60 and y<-30: canvas.num1+= "3" elif x>0 and x<30 and y>-110 and y<-80: canvas.num1 += "0" elif x>40 and x<70 and y>-110 and y<-90: canvas.num1_done = True canvas.operator ="+" elif x>40 and x<70 and y>-70 and y<-40: canvas.num1_done = True canvas.operator = "-" elif x>40 and x<70 and y>-30 and y<0: canvas.num1_done = True canvas.operator ="x" elif x>40 and x<70 and y>10 and y<40: canvas.num1_done = True canvas.operator = "/" seth(0) draw_screen() penup() goto(80,80) color("white") pendown() write(canvas.num1 + "" + canvas.operator, font=("Arial", 15), align="right") elif canvas.num2_done == False: if x>-80 and x<-50 and y>10 and y<40: canvas.num2 += "7" elif x>-40 and x<-10 and y>10 and y<40: canvas.num2 += "8" elif x>0 and x<30 and y>10 and y<40: canvas.num2+= "9" elif x>-80 and x<-50 and y>-30 and y<0: canvas.num2 += "4" elif x>-40 and x<-10 and y>-30 and y<0: canvas.num2+= "5" elif x>0 and x<30 and y>-30 and y<0: canvas.num2 += "6" elif x>-80 and x<-50 and y>-70 and y<-40: canvas.num2+= "1" elif x>-40 and x<-10 and y>-60 and y<-30: canvas.num2 += "2" elif x>0 and x<30 and y>-60 and y<-30: canvas.num2+= "3" elif x>0 and x<30 and y>-110 and y<-80: canvas.num2 += "0" elif x>40 and x<70 and y>-110 and y<-90: canvas.num2_done = True canvas.operator ="+" elif x>40 and x<70 and y>-70 and y<-40: canvas.num2_done = True canvas.operator = "-" elif x>40 and x<70 and y>-30 and y<0: canvas.num2_done= True canvas.operator ="x" elif x>40 and x<70 and y>10 and y<40: canvas.num2_done = True canvas.operator = "/" seth(0) draw_screen() penup() goto(80,80) color("white") pendown() write(canvas.num1 + "" + canvas.operator + "" + canvas.num2, font=("Arial", 15), align="right") #This statement will give the result if x>-80 and x<-20 and y>-110 and y<-80: canvas.num2_done = True seth(0) draw_screen() penup() goto(80,80) color("white") pendown() solve_question() #Calling full function canvas.onclick(use_calculator)
Editor is loading...
Leave a Comment