Ascii Tree Art - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Ascii Tree Art (/thread-14702.html) |
Ascii Tree Art - beepBoop123 - Dec-12-2018 Hi, I'm trying to create a function that will make the correct sized ascii Christmas tree art based on the size passed in. This is what I have so far def get_festive(size): Triangle = "" for i in range (size+4): Triangle += ("*"*((i*4)+1)).center(((size*4))," ") Triangle += "\n" return TriangleThis is what I need it to look like: get_festive(3) * ***** ********* ************* ***** ********* ************* ***************** ********* ************* ***************** *********************This is what I have so far: get_festive(3) * ***** ********* ************* ***************** ********************* *************************Any suggestions or if you know what to fix let me know - thank you! RE: Ascii Tree Art - ichabod801 - Dec-13-2018 One thing is that you need to center based on the largest line you are going to print. In the case of your current code that would be (size + 4) * 4, not just size * 4. Beyond that it's hard to say, because the general case is not clear. Do you have more detailed instructions for the assignment, or examples of what get_festive(2) and get_festive(4) should look like? RE: Ascii Tree Art - beepBoop123 - Dec-13-2018 get_festive(2) * ***** ********* ************* ***** ********* ************* ***************** get_festive(1) * ***** ********* *************here are the other ones (: RE: Ascii Tree Art - ichabod801 - Dec-13-2018 You need two nested loops. Each tree is made of a number of trapezoids equal to it's size. Each trapezoid has four rows. That should tell you what the two loops you need are. The number of *'s at any level is a function of the sum of the two looping variables. Remember to center based on the largest number of *'s you will get. RE: Ascii Tree Art - Gribouillis - Dec-13-2018 ichabod801 Wrote:You need two nested loops.I'm using only one loop for n in range(4 * size): ...The divmod() function helps.
RE: Ascii Tree Art - ichabod801 - Dec-13-2018 Well, you could do it with no loops, but let's start him out with the two loop solution. |