Display Binary Numbers (using a variable, operator and a repeat loop)

Challenge Level: Beginner

Learning outcomes

Students will be able to:

Requirement:

Write a program to display numbers 1, 2, 4, 8 and 16 on the screen one at a time. This challenge builds on the previous one, but the program should use a loop, so it could easily be updated to display more numbers.

Testing examples:

The output will always show the numbers 1, 2, 4, 8 and 16 (there is no input).

Languages

Scratch

What it should look like

Click on the green flag to see the expected output of your program.

Recommended blocks
when green flag clicked

set [number of dots v] to [1]

repeat (5)
end

say (number of dots) for (1) secs

set [number of dots v] to ((number of dots) * (2))
Hints
  • Use the set [number of dots v] to [1] block to set the value of your new variable. Use the () * () operation under “Operators” to double the value of your variable.
  • Display the value of your variable on the screen by replacing “Hello” in your say [Hello] for (2) secs block with your new variable.
  • Use the repeat () block to run the blocks inside a specified number of times. In this challenge you need to repeat the blocks 5 times.

Show Scratch solution

Python
Block-based

Extra Challenge

Display the numbers from largest to smallest (display numbers 16, 8, 4, 2 and 1).