Pybites Logo

Rhombus generator

Level: Intermediate (score: 3)

In this Bite you make a generator of rhombus shapes. You will complete gen_rhombus that when called like this:

  gen = gen_rhombus(5)  # gen_rhombus is a generator
  for row in gen:
      print(row)


... will generate the following output:

  *
 ***
*****
 ***
  *

When called with a greater width (you only have to worry about uneven widths for this exercise):

  gen = gen_rhombus(11)
  for row in gen:
      print(row)


... the output would be:

     *
    ***
   *****
  *******
 *********
***********
 *********
  *******
   *****
    ***
     *

So the middle row is always equal to the width passed in. Checkout how format or f-strings can help you here, as well as the range builtin. Have fun!