Display number of dots from right to left in one line

Challenge Level: Growing experience

Learning outcomes

Students will be able to:

Requirement:

Write a program to display numbers 1, 2, 4, 8,... (all in one line) for a given number of cards as the input.

Testing examples:

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

Input Output
4 1, 2, 4, 8,
8 1, 2, 4, 8, 16, 32, 64, 128,
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
set [binary cards v] to []

set [number of dots v] to [1]

set [number of cards v] to (answer)

set [binary cards v] to (join (binary cards) (join (number of dots) [, ]))

set [number of dots v] to ((number of dots) * (2))
when green flag clicked

ask [How many cards would you like to display?] and wait

repeat (number of cards)
end

say (binary cards)
Hints
  • Make variables:

    • “number of cards” to store the number of cards to display entered by the end user as the input (e.g. 4).
    • “number of dots” to store the number of dots.
    • “binary cards” which is a variable type string and stores what is going to be displayed on the screen as the output (e.g. “1, 2, 4, 8,”).
  • Use the (join [hello] [world]) block under “Operators” to combine two strings. You can use multiple join blocks inside each other if you need to combine more than two strings.
  • In Scratch, to concatenate data together you use the (join [hello] [world]) blocks. This can be used to join text, variables and calculations. Remember to check if the spaces are correct between the items being joined!

Show Scratch solution

Python
Block-based

Extra Challenge

Now try removing the last , from the end of your output.