Count dots on 5 black and white cards as one input (without 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, all as one line of input ('B' for black and 'W' for white), and displays the total number of dots as the output. You can do this without a loop, using 5 similar sets of blocks to process each of the 5 values.

Testing examples:

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

Input Output
WWBBB 24
BBBBB 0
WWWWW 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
whenclickedaskPlease enter 5 cards ('B' for black and 'W' for white):andwaitsaytotalnumberofdots
ifletter1ofcards=Wthenifletter2ofcards=Wthenifletter3ofcards=Wthenifletter4ofcards=Wthenifletter5ofcards=Wthen
settotal number of dotsto0setcardstoanswersettotal number of dotstototalnumberofdots+16settotal number of dotstototalnumberofdots+8settotal number of dotstototalnumberofdots+4settotal number of dotstototalnumberofdots+2settotal number of dotstototalnumberofdots+1
Hints
  • Make a variable called “total number of dots” and set its value to 0. Make a string variable called “cards” and set its value to the input entered by the end user (5 black and white cards). Check each letter of the string and if it’s ‘W’ add the corresponding number of dots (16 for the first letter, 8 for the second letter and so on) to the “total number of dots”. Display the “total number of dots” as the output.
  • You can access a letter at the specified position in a string by using the letter1ofworld block under “Operators”. For example: letter1ofworldw

Show Scratch solution

Python
Block-based