Pola piramida angka berongga dengan python

Jalankan
num = 8
k = 0
for i in range(1, num + 1):
    # printing left spaces in rows
    for j in range(i, num):
        print(" ", end="")

    while k != (2 * i - 1):
        # printing left/right boundaries
        if k == 0 or k == 2 * i - 2:
            print("*", end="")
        # printing spaces in the middle of the triangle
        else:
            print(" ", end="")
        k = k + 1

    k = 0
    print()

# printing bottom boundary of the triangle
for i in range(0, 2 * num - 1):
    print("*", end="")

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
20
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
21
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
22
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
23
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
28
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
25
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
26
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
28
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
28________3

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
_6

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
32

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
35
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
21
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
22
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
38

// CPP program to print a hollow pyramid pattern1

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
40
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
23
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
42
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
43
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
16
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
45

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
48

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6#include 0
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
51
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
16
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
23
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
49
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
55
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
20
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
57
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
28________3______59

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
62
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
16
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
16 _______________23
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
____66 ____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________g

#include 5

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
40
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
23
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
79
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
43
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
16
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
45

// CPP program to print a hollow pyramid pattern1using0

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
85

#include 5

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
40
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
23
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
42
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
43
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
16
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
45

// CPP program to print a hollow pyramid pattern1

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
15
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
16
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
15________3______26
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
28

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
15
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
16
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
23________315______4

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
40
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
06
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
07

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
10

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
20
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
21
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
22
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
23
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
23
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
18_______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________ jelas

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
40
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
23
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
79
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
43
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
16
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
45

 

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
_32

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
21
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
16
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
04

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
_36

 

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
_37

C#




using

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
39

void5 void1 void2

 

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6void5 void6 void
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
47

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
5

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
1
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
8

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
0

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
_6

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6void6 void
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
0
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
1
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
5

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
5

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
1
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
9

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
2
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
3

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
5

// CPP program to print a hollow pyramid pattern1

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
7

// CPP program to print a hollow pyramid pattern1

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1 // CPP program to print a hollow pyramid pattern0

#include 5

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
81// CPP program to print a hollow pyramid pattern3
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
2

// CPP program to print a hollow pyramid pattern1

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

// CPP program to print a hollow pyramid pattern1// CPP program to print a hollow pyramid pattern8

// CPP program to print a hollow pyramid pattern1#include 0 #include 1

#include 5#include 3 #include 4

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
_62
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
81#include 7
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
2

#include 5using0

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
_62
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
81// CPP program to print a hollow pyramid pattern3
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
2

#include 5using6

#include 5// CPP program to print a hollow pyramid pattern4

// CPP program to print a hollow pyramid pattern1

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

// CPP program to print a hollow pyramid pattern1namespace0

// CPP program to print a hollow pyramid pattern_1

________315

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
_358_______3

// CPP program to print a hollow pyramid pattern1// CPP program to print a hollow pyramid pattern16

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6namespace7

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1 std;0

// CPP program to print a hollow pyramid pattern1

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
81#include 7
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
2

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

 

// CPP program to print a hollow pyramid pattern_33

PHP




// CPP program to print a hollow pyramid pattern_34

// CPP program to print a hollow pyramid pattern_35

// CPP program to print a hollow pyramid pattern_36

 

// CPP program to print a hollow pyramid pattern_37

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
0// CPP program to print a hollow pyramid pattern39
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
61

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
_5

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6// CPP program to print a hollow pyramid pattern43 // CPP program to print a hollow pyramid pattern44

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
_6

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
3

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
23// CPP program to print a hollow pyramid pattern51 // CPP program to print a hollow pyramid pattern52// CPP program to print a hollow pyramid pattern51 // CPP program to print a hollow pyramid pattern54// CPP program to print a hollow pyramid pattern39// CPP program to print a hollow pyramid pattern4// CPP program to print a hollow pyramid pattern158_____

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
5

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
7

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
23// CPP program to print a hollow pyramid pattern67
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
16// CPP program to print a hollow pyramid pattern51// CPP program to print a hollow pyramid pattern______________________________________________________________________________________________________________________________________________________________________________________________________________

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
5

// CPP program to print a hollow pyramid pattern1// CPP program to print a hollow pyramid pattern80 // CPP program to print a hollow pyramid pattern3// CPP program to print a hollow pyramid pattern4

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6// CPP program to print a hollow pyramid pattern8

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6#include 0
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
23// CPP program to print a hollow pyramid pattern43 // CPP program to print a hollow pyramid pattern92// CPP program to print a hollow pyramid pattern51 // CPP program to print a hollow pyramid pattern94

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
5

// CPP program to print a hollow pyramid pattern1#include 3

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
23// CPP program to print a hollow pyramid pattern43 #include 01// CPP program to print a hollow pyramid pattern43 #include 03

#include 04// CPP program to print a hollow pyramid pattern51 #include 06

#include 5// CPP program to print a hollow pyramid pattern80 #include 7// CPP program to print a hollow pyramid pattern4

// CPP program to print a hollow pyramid pattern1using0

#include 5// CPP program to print a hollow pyramid pattern80 // CPP program to print a hollow pyramid pattern3// CPP program to print a hollow pyramid pattern4

// CPP program to print a hollow pyramid pattern1// CPP program to print a hollow pyramid pattern43#include 19

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6// CPP program to print a hollow pyramid pattern43 // CPP program to print a hollow pyramid pattern44

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6namespace3

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6// CPP program to print a hollow pyramid pattern80 #include 30// CPP program to print a hollow pyramid pattern4

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
_6

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6namespace7

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
23// CPP program to print a hollow pyramid pattern51 // CPP program to print a hollow pyramid pattern44// CPP program to print a hollow pyramid pattern51 #include 43// CPP program to print a hollow pyramid pattern39 #include 45// CPP program to print a hollow pyramid pattern515

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
5

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6// CPP program to print a hollow pyramid pattern80 #include 7// CPP program to print a hollow pyramid pattern4

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

 

#include _57

// CPP program to print a hollow pyramid pattern_39 #include 59

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
0// CPP program to print a hollow pyramid pattern39
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
2

 

#include _63

#include _64

Javascript




#include _65

#include 66#include 67

#include 66#include 69

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
8

#include 66

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
0

#include 66// CPP program to print a hollow pyramid pattern37

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
36

#include _66

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
5

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6#include 69
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
9

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
2
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
3

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
5

#include _87

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
7

#include _87

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1 #include 91

#include _87

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
5

// CPP program to print a hollow pyramid pattern1#include 95#include 96

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
2

#include _87

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

#include _87

#include 87// CPP program to print a hollow pyramid pattern8

________316

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
_316_______0 using05

#include _87

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
5

// CPP program to print a hollow pyramid pattern1#include 3 #include 4

________316______5#include 95#include 7

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
2

// CPP program to print a hollow pyramid pattern1using0

#include 5#include 95#include 96

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
2

// CPP program to print a hollow pyramid pattern1using6

#include _87

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

#include 87namespace0

#include 87#include 95using29

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
2namespace3

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6namespace7

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1 using39

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
5

#include 87#include 95#include 7

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
2

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
6
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

#include 66

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

#include _66

#include 66using52

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
_6using54

Keluaran

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
_

Kompleksitas waktu. O(N^2), Algoritma ini memiliki kompleksitas waktu O(N^2), di mana N adalah jumlah baris. Ini karena kita mengulangi baris dan kolom pola, yang membutuhkan waktu O(N^2) untuk menyelesaikannya

Kompleksitas ruang. O(1), Algoritma ini tidak memerlukan ruang tambahan, sehingga kompleksitas ruangnya adalah O(1)

2. Berlian Berongga

Catatan. Untuk input genap, cetak pola untuk n-1

Contoh

Memasukkan. 1

Keluaran

Pola piramida angka berongga dengan python

Untuk n=1

Memasukkan. 7

Keluaran

Pola piramida angka berongga dengan python

Untuk n=7

Memasukkan. 9

Keluaran

Pola piramida angka berongga dengan python

Untuk n=9

 

Mendekati. Untuk mencetak berlian, kita perlu mencetak spasi sebelum bintang dan setelah bintang untuk mencapai jarak bintang yang terus bertambah

Untuk mencetak bentuk kotak kita perlu mencetak '-' untuk i==1 (baris pertama) & i==n (baris terakhir) dan '. ’ untuk j==1 (kolom pertama) dan j==n (kolom terakhir)

Algoritma. 1. Jika n adalah kenaikan ganjil n

2. Temukan pertengahan = n/2

3. Lintasi dari 1 hingga pertengahan untuk mencetak separuh atas pola (katakanlah i)

4. Lintasi dari 1 ke mid-i untuk mencetak spasi untuk kotak terluar paling kiri atas (katakanlah j)

5. Jika (i==1) cetak '*' (karena untuk baris pertama kita hanya membutuhkan satu bintang)

6. lain cetak '*' dan lintasi dari 1 ke 2*i-3 untuk mencetak spasi untuk berlian berongga (katakanlah j) dan cetak '*' setelah loop selesai

7. Lintasi dari 1 ke mid-i untuk mencetak spasi lagi untuk kotak terluar paling kanan atas (katakanlah j)

8. Tutup loop pada langkah 3

9. Lintasi dari pertengahan+1 ke n-1 untuk mencetak separuh bawah pola (katakanlah i)

4. Lintasi dari 1 ke i-mid untuk mencetak ruang untuk kotak terluar paling kiri bawah (katakanlah j)

5. Jika (i==n-1) cetak '*' (karena untuk baris terakhir kita hanya membutuhkan satu bintang)

6. lain cetak '*' dan lintasi dari 1 ke 2*(n-i)-3 untuk mencetak spasi untuk berlian berongga (katakanlah j) dan cetak '*' setelah loop selesai

7. Lintasi dari 1 ke i-mid untuk mencetak spasi lagi untuk kotak terluar paling kanan bawah (katakanlah j)

8. Tutup loop pada langkah 9

C++14




using_55

using namespace std;

 

using_59

void

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
0
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
1using63

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
_5

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
1 using67

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6#include 3using70using71

#include 66using73

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
_6using75

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
_6

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
_6using78

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1using81

#include 66

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1using84using85

using86using87// CPP program to print a hollow pyramid pattern3// CPP program to print a hollow pyramid pattern4

using_86

________316

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
_316_______3using93

using86// CPP program to print a hollow pyramid pattern2using96// CPP program to print a hollow pyramid pattern4

#include 66

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1using0
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
5

using86// CPP program to print a hollow pyramid pattern2using96// CPP program to print a hollow pyramid pattern4namespace06

using86

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1namespace09namespace10

// CPP program to print a hollow pyramid pattern1// CPP program to print a hollow pyramid pattern2// CPP program to print a hollow pyramid pattern3// CPP program to print a hollow pyramid pattern4

using86

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

using86// CPP program to print a hollow pyramid pattern2using96// CPP program to print a hollow pyramid pattern4

#include 66

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

#include 66

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1using84namespace26

using86using87// CPP program to print a hollow pyramid pattern3// CPP program to print a hollow pyramid pattern4

using_86

#include 66namespace2

namespace_34

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

namespace_34

________358

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
_358_______38

namespace_34

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1namespace41

namespace_42

#include 66

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1namespace45using85

using86using87// CPP program to print a hollow pyramid pattern3// CPP program to print a hollow pyramid pattern4

using_86

________316

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
_316_______3namespace54

using86// CPP program to print a hollow pyramid pattern2using96// CPP program to print a hollow pyramid pattern4

#include 66

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1using0
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
5

using86// CPP program to print a hollow pyramid pattern2using96// CPP program to print a hollow pyramid pattern4namespace06

using86

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1namespace70namespace10

// CPP program to print a hollow pyramid pattern1// CPP program to print a hollow pyramid pattern2// CPP program to print a hollow pyramid pattern3// CPP program to print a hollow pyramid pattern4

using86

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

using86// CPP program to print a hollow pyramid pattern2using96// CPP program to print a hollow pyramid pattern4

#include 66

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

#include 66

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1namespace45namespace26

using86using87// CPP program to print a hollow pyramid pattern3// CPP program to print a hollow pyramid pattern4

using_86

#include 66namespace2

namespace_34

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

 

namespace_98

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
1 std;00

namespace_34

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
1 std;03

namespace_34

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
0

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1

std;_07

Jawa




std;_08

void1 void2

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
_6

using_59

void6 void

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
0
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
1
   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
5

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
_5

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
1 using67

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6#include 3std;24
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
49std;_26
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
28
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
61using71

#include 66using73

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6std;33
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
49// CPP program to print a hollow pyramid pattern4

std;_36

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
_6using78

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
6
-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
27
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
28std;43

#include 66

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1std;46
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
28std;48using85

using86

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
39// CPP program to print a hollow pyramid pattern3
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
2

#include _87

#include 66#include 3std;57

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
28std;59

using86

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
39using96
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
2

#include 66

   *   
  * *  
 *   * 
*     *
 *   * 
  * *  
   *   
1using0
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
5

using86

     #
    # #
   #   #
  #     #
 #       #
#         #
###########
39using96
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
2namespace06

using86

-----*-----
|   * *   |
|  *   *  |
| *     * |
|*       *|
*         *
|*       *|
| *     * |
|  *   *  |
|   * *   |
-----*-----
1std;46
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
28std;_77
     #
    # #
   #   #
  #     #
 #       #
#         #
###########
49void54std;80std;81namespace_10

Bagaimana cara mencetak pola bintang piramida terbalik berongga dengan Python?

Pola bintang segitiga siku-siku berongga dengan python .
Awal
Ambil jumlah baris sebagai input dari pengguna dan simpan ke dalam num
Jalankan loop 'i' beberapa kali untuk mengulangi semua baris yang Mulai dari i=0 hingga num
Jalankan loop bersarang di dalam loop utama untuk ruang pencetakan yang dimulai dari j=0 hingga i

Bagaimana Anda membuat pola piramida dengan Python?

Kode Sumber .
Pertama, kami mendapatkan tinggi baris piramida dari pengguna
Di loop pertama, kami beralih dari i = 0 ke i = baris
Di loop kedua, kami mencetak angka mulai dari 1 hingga j , di mana j berkisar dari 0 hingga i
Setelah setiap iterasi dari loop pertama, kami mencetak baris baru

Bagaimana Anda mencetak pola segitiga berongga?

scanf("%u",&baris);

Bagaimana Anda mencetak segitiga siku-siku berongga dengan Python?

Deskripsi .
# Ulangi baris. untuk i dalam rentang(1, n+1)
# Ulangi kolom. untuk j dalam rentang(1, n+1)
jika (i == j) atau (j == 1) atau (i == n). cetak("*", akhir=" ")
kalau tidak. cetak(" ", akhir=" ")