avatar Bite 245. Xmas Tree 2.0

In this Bite you have to complete generate_improved_xmas_tree that takes a rows arg (= number of rows with leafs). For each row you add a star, leafs and a trunk and center them nicely. This bite is an extension to Bite 119 with additional elements and some twists.

Elements of the tree:

  • STAR: Every tree has exactly one star at the top row.
  • LEAF: Every tree has row_number * 2 - 1 leafs per row.
  • TRUNK: Every tree has a trunk with a height of 2 and a width which is half of the largest leaf row.

However, the trunk should always be nicely centered by having the same number of empty spaces on both sides of the trunk. Therefore, you have to consider the width of the leaf rows and do some conditional rounding :)

The tree with default args should look like this:

         +
         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************
    |||||||||||
    |||||||||||

Return the finished tree as a multi-line string (use newlines \n between the lines).

Good luck and keep calm and merry Python Xmas!

Login and get coding
go back Intermediate level
Bitecoin 3X

92 out of 95 users completed this Bite.
Will you be Pythonista #93 to crack this Bite?
Resolution time: ~55 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 3.0 on a 1-10 difficulty scale.
» You can do it! 😌

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help