← Back to challenges

Characters in Shapes

PythonHardstringsarrayslanguage_fundamentals

Instructions

Create a function to calculate how many characters in total are needed to make up the shape. You will be given a list of strings which make up a shape in the compiler (i.e. a square, a rectangle or a line).

Examples

count_characters([
  "###",
  "###",
  "###"
]) ➞ 9

count_characters([
  "22222222",
  "22222222",
]) ➞ 16

count_characters([
  "------------------"
]) ➞ 18

count_characters([]) ➞ 0

count_characters(["", ""]) ➞ 0

Notes

Return 0 if the given list is empty.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Recursion: Factorials