Display number of dots from the given largest card to 1

Challenge Level: Growing experience

Learning outcomes

Students will be able to:

Requirement:

Write a program that takes the largest number of dots on a card as an input and displays the bit values from largest to smallest as the output.

Testing examples:

Your program should display the outputs shown in this table for the given inputs provided:

Input Output
32 32
16
8
4
2
1
128 128
64
32
16
8
4
2
1
1 1

Languages

Scratch

What it should look like

Click on the green flag, enter the inputs provided in the “testing examples” to see the expected output of your program.

Recommended blocks
when green flag clicked

ask [Enter the largest number of dots on a card:] and wait

repeat until <(number of dots) = [1]>
end
set [number of dots v] to (answer)

set [number of dots v] to ((number of dots) / (2))
say (number of dots) for (1) secs

say (number of dots) for (1) secs
Hints
  • Make a variable called “number of dots” and set it to the largest number of dots entered as the input. Divide the value of “number of dots” by 2 and display the result as the output until “number of dots” is equal to 1.
  • Use the () / () operation under “Operators” to divide the value of your variable by 2.
  • Use the repeat until <> block to run the blocks inside while the condition is true. In this challenge you need to repeat the blocks until number of dots is equal to 1.

Show Scratch solution

Python
Block-based