Count dots on 5 black and white cards (using a loop)

Challenge Level: Growing experience

Learning outcomes

Students will be able to:

Requirement:

Write a program that asks the end user to enter 5 black and white cards representing bits ('B' for black and 'W' for white which are entered one at a time) and displays the total number of dots as the output. Use a loop for this challenge, so it could be changed to work for a different number of cards.

Testing examples:

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

Input Output
B
W
W
B
W
13
B
B
B
B
B
0
W
W
W
W
W
31

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

repeat (5)
end

say (total number of dots)

ask [Please enter a black or white card ('B' for black or 'W' for white):] and wait

end
set [number of dots v] to ((number of dots) / (2))

set [total number of dots v] to ((total number of dots) + (number of dots))

set [number of dots v] to [16]

set [total number of dots v] to [0]
Hints
• Make a variable called “total number of dots” and set its value to 0. Make another variable called “number of dots” and set its value to 16. Add the value of “number of dots” to the value of “total number of dots” every time the end user enters ‘W’ as the input. Repeat this 5 times dividing the value of “number of dots” by 2 each time. Display the “total number of dots” as the output.
• 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.
• The if <> then block checks if the condition is true and then runs the blocks inside of the if block.
Python

Block-based