Sunday, 2 February 2020

Google Blockly Visual Programming with Bubble Sort Example

Google Blockly is a visual programming library. It is fun to try with, and fun for kids, but not for production use as developing something with it is slower than typing and not complex enough to make applications.

An example Blockly bubble sort is here:
https://blockly-demo.appspot.com/static/demos/code/index.html#bfen2c

Screenshot:

Generated Python source code:
import random

List  = None
I     = None
J     = None
Left  = None
Right = None

List = [random.randint(1,100),random.randint(1,100),random.randint(1,100)]
I    = 1

while I < len(List):
  J = I + 1

  while J <= len(List):
    Left  = List[int(I - 1)]
    Right = List[int(J - 1)]

    if Left > Right:
      List[int(I - 1)] = Right
      List[int(J - 1)] = Left

    J = J + 1
  #End J

  I = I + 1
#End I

print(List[0])
print(List[1])
print(List[2])

No comments:

Post a Comment