-1

My forest pattern I did print the forest pattern here but i have to print them next to each other instead of printing them in new lines. How can i do that? When i try to add end="" to last print section, it seems like only the first "*" is printing and the shape is ruined.

for x in range(5):
    sayi = int(input("[5-13] Aralığında tek tam sayı giriniz:"))
    for y in range(5):
        for i in range(1,sayi+1):
            print(" " * (sayi-i) + '\033[92m' + "* " *i + '\033[0m')
        for j in range(sayi // 2 ):
            print(" " * (sayi-2) + "* *")
        

Trying to do forest pattern for my homework. I did manage to print tree shaped outputs but i cant print them next to each other.

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
  • Don't post code as an image. Type the text. – trincot Nov 30 '22 at 20:11
  • Welcome to Stack Overflow. Please read [ask]. In general, we aren't interested in questions where the problem boils down to working through the *logic*, using tools that are already familiar to you. "When i try to add end="" to last print section, it seems like only the first "*" is printing and the shape is ruined." Think clearly about the following things: 1) what should be printed on the first line of the output, exactly? 2) How much space needs to appear between that part of each "tree"? (Can you think of a **mathematical rule that tells you this**, based on the width of that part?) – Karl Knechtel Nov 30 '22 at 20:56
  • 3) How do you know, when the output should continue on the next line, instead of the current line? After that, try to write out a process, step by step, to solve the problem. Think carefully about the order in which everything will be printed, because you cannot "go backwards" or "move" to a new place - you can only write left to right from the current position, or start a new line. – Karl Knechtel Nov 30 '22 at 20:57

1 Answers1

-1

Do you mean something like this

sayi = int(input("[5-13] Aralığında tek tam sayı giriniz:"))
for i in range(1, sayi + 1):
    green = "* " * i
    print('\033[92m' + green.center(sayi * 2 + 2) * 5 + '\033[0m')
for j in range(sayi // 2):
    trunk = "* *"
    print(trunk.center(sayi * 2 + 2) * 5)

for an input of 5 it prints

     *           *           *           *           *      
    * *         * *         * *         * *         * *     
   * * *       * * *       * * *       * * *       * * *    
  * * * *     * * * *     * * * *     * * * *     * * * *   
 * * * * *   * * * * *   * * * * *   * * * * *   * * * * *  
    * *         * *         * *         * *         * *     
    * *         * *         * *         * *         * *     
xeroli
  • 16
  • 3