add_subtract_bin.py

Created by wperez274

Created on August 12, 2022

4.9 KB

Add and Subtract up to 8 different rows of digits. key [left] / [right ] = - 1/ +1 key [up] / [down] = Cursor Up/Down key [EXE] = Change background Color key [+] / [-] = +10 / -10

      (    Press [OK] to Start    )


from math import *
from random import *
from kandinsky import *
from ion import *
from time import *
from kandinsky import fill_rect as FILL
from kandinsky import draw_string as STR

from ion import keydown as KEY

from ion import KEY_LEFT as LEFT
from ion import KEY_RIGHT as RIGHT
from ion import KEY_UP as UP
from ion import KEY_DOWN as DOWN

from time import sleep as S


# black rgb = (0,0,0) = (0,)*3
bg=(0,)*3

FILL(0,0,322,222,bg)


while not KEY(KEY_OK) and not KEY(KEY_EXE):
 
  STR("""===============================
Add and Subtract up to 8 rows !.
=================================

 key [left]/[right ] = -1/ +1
 key [up]/[down] = Cursor Up/Down
 key [EXE] = Change background
 key [+]/[-] = +10 / -10
 
    
 (    Press [OK] to Start    )
""",0,0,"white",bg)


  FILL(0,6,322,5,(randint(0,100),randint(0,100),randint(0,100)))
  FILL(0,42,322,5,"red")


c="->"
cx=10
cy=30

bg=choice(["white","cyan","pink","yellow","orange",(81,234,190),(21,175,235),(167,200,43),(255,193,48),(162,207,243),(188,216,226),(28,188,165)])

bg2="black"

n1=0
n2=0
n3=0
n4=0
n5=0
n6=0
n7=0
n8=0


tsum=n1+n2+n3+n4+n5+n6+n7+n8

# background
FILL(0,0,322,222,"white")

FILL(0,27,322,163,bg)
FILL(0,0,322,25,bg2)

# thin black lines
FILL(0,25,322,2,"black")
FILL(0,190,322,3,"black")


while 1:

  tsum=n1+n2+n3+n4+n5+n6+n7+n8

  STR(c,cx,cy,"black",bg)
  
  STR(str(n1)+"                             ",35,30,"black",bg)
  STR(str(n2)+"                             ",35,50,"black",bg)
  STR(str(n3)+"                             ",35,70,"black",bg)
  STR(str(n4)+"                             ",35,90,"black",bg)
  STR(str(n5)+"                             ",35,110,"black",bg)
  STR(str(n6)+"                             ",35,130,"black",bg)
  
  STR(str(n7)+"                             ",35,150,"black",bg)
  STR(str(n8)+"                             ",35,170,"black",bg)

  STR("Sum: "+str(tsum)+"                             ",10,200)
  STR("bin("+str(tsum)+")= "+bin(tsum)+"                             ",5,4,"gray",bg2)
  
  
  #============================ 
  if KEY(LEFT) and cy==30:
    S(0.2)
    n1-=1
  if KEY(RIGHT) and cy==30:
    S(0.2)
    n1+=1
  if KEY(KEY_MINUS) and cy==30:
    S(0.2)
    n1-=10
  if KEY(KEY_PLUS) and cy==30:
    S(0.2)
    n1+=10
  if KEY(KEY_BACKSPACE) and cy==30:
    S(0.2)
    n1=0
   #============================ 
  if KEY(LEFT) and cy==50:
    S(0.2)
    n2-=1
  if KEY(RIGHT) and cy==50:
    S(0.2)
    n2+=1
  if KEY(KEY_MINUS) and cy==50:
    S(0.2)
    n2-=10
  if KEY(KEY_PLUS) and cy==50:
    S(0.2)
    n2+=10
  if KEY(KEY_BACKSPACE) and cy==50:
    S(0.2)
    n2=0
  #============================  
   
  if KEY(LEFT) and cy==70:
    S(0.2)
    n3-=1
  if KEY(RIGHT) and cy==70:
    S(0.2)
    n3+=1
  if KEY(KEY_MINUS) and cy==70:
    S(0.2)
    n3-=10
  if KEY(KEY_PLUS) and cy==70:
    S(0.2)
    n3+=10
  if KEY(KEY_BACKSPACE) and cy==70:
    S(0.2)
    n3=0
  #============================  
  if KEY(LEFT) and cy==90:
    S(0.2)
    n4-=1
  if KEY(RIGHT) and cy==90:
    S(0.2)
    n4+=1
  if KEY(KEY_MINUS) and cy==90:
    S(0.2)
    n4-=10
  if KEY(KEY_PLUS) and cy==90:
    S(0.2)
    n4+=10
  if KEY(KEY_BACKSPACE) and cy==90:
    S(0.2)
    n4=0
  #============================  
  if KEY(LEFT) and cy==110:
    S(0.2)
    n5-=1
  if KEY(RIGHT) and cy==110:
    S(0.2)
    n5+=1
  if KEY(KEY_MINUS) and cy==110:
    S(0.2)
    n5-=10
  if KEY(KEY_PLUS) and cy==110:
    S(0.2)
    n5+=10
  if KEY(KEY_BACKSPACE) and cy==110:
    S(0.2)
    n5=0
  #============================  
  if KEY(LEFT) and cy==130:
    S(0.2)
    n6-=1
  if KEY(RIGHT) and cy==130:
    S(0.2)
    n6+=1
  if KEY(KEY_MINUS) and cy==130:
    S(0.2)
    n6-=10
  if KEY(KEY_PLUS) and cy==130:
    S(0.2)
    n6+=10
  if KEY(KEY_BACKSPACE) and cy==130:
    S(0.2)
    n6=0
#============================  
      
  if KEY(LEFT) and cy==150:
    S(0.2)
    n7-=1
  if KEY(RIGHT) and cy==150:
    S(0.2)
    n7+=1
  if KEY(KEY_MINUS) and cy==150:
    S(0.2)
    n7-=10
  if KEY(KEY_PLUS) and cy==150:
    S(0.2)
    n7+=10
  if KEY(KEY_BACKSPACE) and cy==150:
    S(0.2)
    n7=0
#============================  
      
  if KEY(LEFT) and cy==170:
    S(0.2)
    n8-=1
  if KEY(RIGHT) and cy==170:
    S(0.2)
    n8+=1
  if KEY(KEY_MINUS) and cy==170:
    S(0.2)
    n8-=10
  if KEY(KEY_PLUS) and cy==170:
    S(0.2)
    n8+=10
  if KEY(KEY_BACKSPACE) and cy==170:
    S(0.2)
    n8=0
#============================  
   
#============================  
      
  if KEY(UP):
    S(0.2)
    FILL(cx,cy,20,20,bg)
    cy-=20
  if KEY(DOWN):
    S(0.2)
    FILL(cx,cy,20,20,bg)
    cy+=20
  if KEY(KEY_EXE):
    S(0.2)
    bg=choice(["white","cyan","pink","yellow","orange",(81,234,190),(21,175,235),(167,200,43),(255,193,48),(162,207,243),(188,216,226),(28,188,165),(253,200,224),(151,225,146),(214,252,220),(223,220,231),(204,255,204),(255,229,204)])
    FILL(0,27,322,163,bg)
   
  
    
  if cy<30:
    cy=30
  if cy>30+(20*7):
    cy=30+(20*7)

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.