We use Python 3.6

go back Level: Intermediate (img: IM / score: 3) level Bite 146. Rhombus generator

5 out of 5 users completed this Bite ...
Will you be Pythonista #6 to crack this Bite?
Average Bite difficulty 1-10 rating: 2.0
» You can do it! 😌

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!

Github login button