binary_study_random.py

Created by wperez274

Created on December 26, 2021

1.43 KB

Great program that allows one to observe the changes in random binary values. Press OK key to generate new byte of binary data!


from math import *
from random import *
from kandinsky import *
from ion import *
from time import *

fill_rect(0,0,322,222,"black")
draw_string("""
  There are only 10 kinds
  of people in this world:
  Those who understand binary,
  and those who don't.
  
  Which one will you become?

""",20,40,choice(["white","orange","cyan"]),"black")

sleep(0.2)

while not keydown(KEY_OK):
    draw_string("Press OK to Begin",115,200,"white","black")

restart=True
loop=True
font=choice(["green","white","gray","cyan"])
fill_rect(0,0,322,222,"black")

  
while loop:
  fill_rect(0,20,322,2,"gray")
  fill_rect(0,55,322,2,"gray")
    
  mylist=[]
      
  for n in range(40,40+12*9,14):
    sleep(0.1)
    
    bit=choice([0,1])
    draw_string(str(bit),n,30,font,"black")
    mylist.append(bit)
  
  decimal=mylist[-1]*1+mylist[-2]*2+mylist[-3]*4+mylist[-4]*8+mylist[-5]*16+mylist[-6]*32+mylist[-7]*64+mylist[-8]*128
  
  while not keydown(KEY_OK):
    draw_string(str(mylist),30,90,"gray","black")
    draw_string(str("= "+str(decimal)),165,30,"white","black")
    draw_string("Standard Format: "+str(bin(decimal)),25,130,"white",(15,25,45))
    
    if int(decimal)%2==1:
      draw_string("Number: Odd ",32,160,"gray","black")
    else:
      draw_string("Number: Even",32,160,"green","black")

    draw_string("Press OK to restart",115,200,"cyan","black")
    
  font=choice(["cyan","green","white","gray"])
  fill_rect(0,0,322,222,"black")

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.