binary_calc_add.py

Created by wperez274

Created on January 12, 2022

3.36 KB

Binary Code for integers or whole numbers.


# Binary plus decimal add
# By: Wilson



from math import *
from kandinsky import *
from kandinsky import fill_rect as F
from kandinsky import draw_string as STR

from ion import *
from ion import keydown as KEY

from time import *
from random import *


print("\n\n************************\n",

"\n[Left]/[Right] Arrows = +10/-10",
"\n[Up]/[Down] Arrows = +1/-1",
"\nBackSpace = Reset to value 0",
"\nKeys [+]/[-] = Number +/- 100",
"\nKeys [(]/[)] = Number +/- 10^3",
"\n\n     ( PRESS [OK] )")

input("")
print("\n\n****************************\n",
"\n  You can print some",
"\n  numbers on the bottom",
"\n  panel by pressing [OK] key",
"\n\n  To get sum, press [EXE]",
"\n\n****************************\n",
"\n ( PRESS [OK] to Start )\n")
ans=input("Number? : ")


num=int(ans)
y=67

the_sum=0
screen=(204,255,204)
panel=(0,102,102)
default_f="black"
default_f2="white"
cursor_x=10

F(0,0,322,80,screen)
F(0,82,322,170,panel)  
F(0,0,322,2,"black")
F(0,35,322,2,"black")
F(0,80,322,2,"black")

while 1:
  b_code=bin(num)

  STR(str(num),10,12)
  STR(str(b_code),cursor_x,50,default_f,screen)
  
  if KEY(KEY_OK):
#    num=randint(0,255)
    F(2,2,322,78,screen)
    sleep(.1)
  
  if KEY(KEY_UP):
    F(2,2,322,78,screen)
    sleep(0.2)
    num+=1
  
  if KEY(KEY_DOWN):
    F(2,2,322,78,screen)
    sleep(0.2)
    num-=1
  
  if KEY(KEY_PLUS):
    F(2,2,322,78,screen)
    sleep(0.2)
    num+=100
  if KEY(KEY_MINUS):
    F(2,2,322,78,screen)
    sleep(0.2)
    num-=100
  
  if KEY(KEY_RIGHTPARENTHESIS):
    F(2,2,322,78,screen)
    sleep(0.2)
    num+=1000
  if num>4294967295:
    num=4294967295
  if KEY(KEY_LEFTPARENTHESIS):
    F(2,2,322,78,screen)
    F(0,0,322,2,"black")
    F(0,35,322,2,"black")
    F(0,80,322,2,"black")
    sleep(0.2)
    num-=1000
  
  if KEY(KEY_LEFT):
    F(2,2,322,78,screen)
    F(0,0,322,2,"black")
    F(0,35,322,2,"black")
    F(0,80,322,2,"black")
    sleep(0.2)
    num-=10
  if num<=0:
    num=0
  
  if KEY(KEY_RIGHT):
    F(2,2,322,78,screen)
    F(0,0,322,2,"black")
    F(0,35,322,2,"black")
    F(0,80,322,2,"black")
    sleep(0.2)
    num+=10
  
  if KEY(KEY_BACKSPACE):
    the_sum=0
    y=67
    F(0,82,322,170,panel)  
    F(2,2,322,78,screen)
    F(0,0,322,2,"black")
    F(0,35,322,2,"black")
    F(0,80,322,2,"black")
    num=0
    sleep(0.2)
  
  if KEY(KEY_OK) and y<17+20*8 or KEY(KEY_OK) and y<17+20*7:
    sleep(0.2)
    a=num
    the_sum+=num
    y+=20
    STR(str(a)+"="+str(bin(a)),10,y,choice([(156,169,107),(102,225,165),(190,209,143),(162,208,200),(150,228,202),(255,255,255),(0,255,0)]),"black")
  if y>17+20*8:
    STR("(MAX REACHED)",150,87)
    STR("[Backspace]=Clear",150,107,choice([(95,69,207),(201,156,145),(182,148,152),(169,56,204),(98,176,55)]),"black")
    
  if KEY(KEY_EXE):
    STR("[Backspace]=Clear",150,107,choice([(95,69,207),(201,156,145),(182,148,152),(169,56,204),(98,176,55)]),"black")
    STR("SUM: "+str(the_sum)+" = "+bin(the_sum),100,200,"black",(255,229,204))
    
  
  if KEY(KEY_ZERO):
    F(2,2,322,78,screen)
    num=0    
  if KEY(KEY_ONE):
    F(2,2,322,78,screen)
    sleep(0.5)
    num+=1    
    
  if KEY(KEY_TWO):
    F(2,2,322,78,screen)
    sleep(0.5)
    num+=2
  if KEY(KEY_THREE):
    F(2,2,322,78,screen)
    sleep(0.5)
    num+=3
  if KEY(KEY_FOUR):
    F(2,2,322,78,screen)
    sleep(0.5)
    num+=4
  if KEY(KEY_FIVE):
    F(2,2,322,78,screen)
    sleep(0.5)
    num+=5

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.