Notification texts go here Contact Us Click here

Using Python to print the pattern .

Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated

  1. ➤ Print half pyramid pattern's .
  2.  
  3. # number of rows
  4. rows = 5
  5. for i in range(0, rows):
  6.     # nested loop for each column
  7.     for j in range(0, i + 1):
  8.         # print star
  9.         print("*", end=' ')
  10.     # new line after each row
  11.     print("\r")
  12.  
  13.  
  14.  
  15. OUTPUT :
  16.  
  17. * * 
  18. * * * 
  19. * * * * 
  20. * * * * *
  21.  
  22. ➤ Print triangle pyramid of star .
  23.  
  24. # number of rows
  25. rows = 5
  26. k = 2 * rows - 2
  27. for i in range(0, rows):
  28.     # process each column
  29.     for j in range(0, k):
  30.         # print space in pyramid
  31.         print(end=" ")
  32.     k = k - 2
  33.     for j in range(0, i + 1):
  34.         # display star
  35.         print("* ", end="")
  36.     print("")
  37.  
  38.  
  39.  
  40. OUTPUT :
  41.  
  42.         * 
  43.       * * 
  44.     * * * 
  45.   * * * * 
  46. * * * * * 
  47.  
  48.  
  49. ➤ Print downward half pyramid pattern of star's.
  50.  
  51. rows = 5
  52. for i in range(rows + 1, 0, -1):
  53.     # nested reverse loop
  54.     for j in range(0, i - 1):
  55.         # display star
  56.         print("*", end=' ')
  57.     print(" ")
  58.  
  59.  
  60.  
  61. OUTPUT :
  62.  
  63. * * * * *  
  64. * * * *  
  65. * * *  
  66. * *  
  67. *
  68.  
  69.  
  70. ➤ Print downward full pyramid pattern of star .
  71.  
  72. rows = 5
  73. = 2 * rows - 2
  74. for i in range(rows, -1, -1):
  75.     for j in range(k, 0, -1):
  76.         print(end=" ")
  77.     k = k + 1
  78.     for j in range(0, i + 1):
  79.         print("*", end=" ")
  80.     print("")
  81.  
  82.  
  83.  
  84. OUTPUT :
  85.  
  86.         * * * * * *   
  87.          * * * * * 
  88.           * * * * 
  89.            * * * 
  90.             * * 
  91.              * 
  92.  
  93. ➤ Print equilateral triangle pattern of star .
  94.  
  95. print("Print equilateral triangle Pyramid using asterisk symbol ")
  96. # printing full Triangle pyramid using stars
  97. size = 7
  98. = (2 * size) - 2
  99. for i in range(0, size):
  100.     for j in range(0, m):
  101.         print(end=" ")
  102.     # decrementing m after each loop
  103.     m = m - 1
  104.     for j in range(0, i + 1):
  105.         print("* ", end=' ')
  106.     print(" ")
  107.  
  108.  
  109.  
  110.  
  111. OUTPUT :
  112.             *   
  113.            *  *   
  114.           *  *  *   
  115.          *  *  *  *   
  116.         *  *  *  *  *   
  117.        *  *  *  *  *  *   
  118.       *  *  *  *  *  *  *   
  119.  
  120.  
  121. ➤ Print Right start pattern of star .
  122.  
  123. rows = 5
  124. for i in range(0, rows):
  125.     for j in range(0, i + 1):
  126.         print("*", end=' ')
  127.     print("\r")
  128.  
  129. for i in range(rows, 0, -1):
  130.     for j in range(0, i - 1):
  131.         print("*", end=' ')
  132.     print("\r")
  133.  
  134.  
  135.  
  136.  
  137. OUTPUT :
  138.  
  139. * * 
  140. * * * 
  141. * * * * 
  142. * * * * * 
  143. * * * * 
  144. * * * 
  145. * * 
  146.  
  147.  
  148. ➤  Print the number's pattern .
  149.  
  150. rows = 6
  151. # if you want user to enter a number, uncomment the below line
  152. # rows = int(input('Enter the number of rows'))
  153. # outer loop
  154. for i in range(rows):
  155.     # nested loop
  156.     for j in range(i):
  157.         # display number
  158.         print(i, end=' ')
  159.     # new line after each row
  160.     print('')
  161.  
  162.  
  163.  
  164. OUTPUT :
  165.  
  166. 1  
  167. 2 2  
  168. 3 3 3  
  169. 4 4 4 4  
  170. 5 5 5 5 5
  171.  
  172.  
  173. ➤  Print Number'in pyramid pattern . 
  174. rows = 5
  175. for i in range(1, rows + 1):
  176.     for j in range(1, i + 1):
  177.         print(j, end=' ')
  178.     print('')
  179.  
  180.  
  181.  
  182. OUTPUT :
  183.  
  184. 1 
  185. 1 2 
  186. 1 2 3 
  187. 1 2 3 4 
  188. 1 2 3 4 5
  189.  
  190.  
  191. ➤  Print Inverted  pyramid pattern of number's .
  192.  
  193. rows = 5
  194. b = 0
  195. # reverse for loop from 5 to 0
  196. for i in range(rows, 0, -1):
  197.     b += 1
  198.     for j in range(1, i + 1):
  199.         print(b, end=' ')
  200.     print('\r')
  201.  
  202.  
  203. OUTPUT :
  204.  
  205.  
  206. 1 1 1 1 1 
  207. 2 2 2 2 
  208. 3 3 3 
  209. 4 4 
  210. 5
  211.  
  212.  
  213. ➤  Print the inverted pyramid pattern with the same digit .
  214.  
  215. rows = 5
  216. num = rows
  217. # reverse for loop
  218. for i in range(rows, 0, -1):
  219.     for j in range(0, i):
  220.         print(num, end=' ')
  221.     print("\r")
  222.  
  223.  
  224.  
  225. OUTPUT :
  226.  
  227. 5 5 5 5 5 
  228. 5 5 5 5 
  229. 5 5 5 
  230. 5 5 
  231. 5
  232.  
  233.  
  234.  
  235. ➤ Print inverted pyramid pattern with different digit .
  236.  
  237. rows = 5
  238. for i in range(rows, 0, -1):
  239.     for j in range(0, i + 1):
  240.         print(j, end=' ')
  241.     print("\r")
  242.  
  243.  
  244.  
  245. OUTPUT :
  246.  
  247. 0 1 2 3 4 5 
  248. 0 1 2 3 4 
  249. 0 1 2 3 
  250. 0 1 2 
  251. 0 1
  252.  
  253.  
  254. ➤  Print reverse number pattern's .
  255.  
  256. rows = 5
  257. # reverse loop
  258. for i in range(rows, 0, -1):
  259.     num = i
  260.     for j in range(0, i):
  261.         print(num, end=' ')
  262.     print("\r")
  263.  
  264.  
  265.  
  266. OUTPUT :
  267.  
  268. 5 5 5 5 5 
  269. 4 4 4 4 
  270. 3 3 3 
  271. 2 2 
  272. 1
  273.  
  274.  
  275. ➤ Print Reverse pyramid of umber's .
  276.  
  277. rows = 6
  278. for i in range(1, rows):
  279.     for j in range(i, 0, -1):
  280.         print(j, end=' ')
  281.     print("")
  282.  
  283.  
  284.  
  285.  
  286. OUTPUT :
  287.  
  288. 2 1 
  289. 3 2 1 
  290. 4 3 2 1 
  291. 5 4 3 2 1
  292.  
  293.  
  294. ➤ Print Another  reverse number pattern .
  295.  
  296. rows = 5
  297. for i in range(0, rows + 1):
  298.     for j in range(rows - i, 0, -1):
  299.         print(j, end=' ')
  300.     print()
  301.  
  302.  
  303. OUTPUT :
  304.  
  305. 5 4 3 2 1 
  306. 4 3 2 1 
  307. 3 2 1 
  308. 2 1 
  309. 1
  310.  
  311.  
  312.  
  313.  
  314.  
  315. ➤  Print  square pattern with number's.
  316.  
  317. rows = 5
  318. for i in range(1, rows + 1):
  319.     for j in range(1, rows + 1):
  320.         if j <= i:
  321.             print(i, end=' ')
  322.         else:
  323.             print(j, end=' ')
  324.     print()
  325.  
  326.  
  327.  
  328.  
  329. OUTPUT :
  330.  
  331. 1 2 3 4 5 
  332. 2 2 3 4 5 
  333. 3 3 3 4 5 
  334. 4 4 4 4 5 
  335. 5 5 5 5 5
  336.  
  337.  
  338.  
  339.  
  340. ➤ Print Multliplication table using number's pattern .
  341.  
  342. rows = 10
  343. # rows = int(input("Enter the number of rows "))
  344. for i in range(1, rows + 1):
  345.     for j in range(1, i + 1):
  346.         # multiplication current column and row
  347.         square = i * j
  348.         print(i * j, end='  ')
  349.     print()
  350.  
  351.  
  352.  
  353.  
  354. OUTPUT :
  355.  
  356. 1  
  357. 2  4  
  358. 3  6  9  
  359. 4  8  12  16  
  360. 5  10  15  20  25  
  361. 6  12  18  24  30  36  
  362. 7  14  21  28  35  42  49  
  363. 8  16  24  32  40  48  56  64  
  364. 9  18  27  36  45  54  63  72  81  
  365. 10  20  30  40  50  60  70  80  90  100  
  366.  
  367.  
  368.  
  369. ➤ Print Daimond shaped pattern of star's .
  370. rows = 5
  371. = 2 * rows - 2
  372. for i in range(0, rows):
  373.     for j in range(0, k):
  374.         print(end=" ")
  375.     k = k - 1
  376.     for j in range(0, i + 1):
  377.         print("* ", end="")
  378.     print("")
  379.  
  380. = rows - 2
  381.  
  382. for i in range(rows, -1, -1):
  383.     for j in range(k, 0, -1):
  384.         print(end=" ")
  385.     k = k + 1
  386.     for j in range(0, i + 1):
  387.         print("* ", end="")
  388.     print("")
  389.  
  390.  
  391.  
  392.  
  393. OUTPUT :
  394.  
  395.         * 
  396.        * * 
  397.       * * * 
  398.      * * * * 
  399.     * * * * * 
  400.    * * * * * * 
  401.     * * * * * 
  402.      * * * * 
  403.       * * * 
  404.        * * 
  405.         * 
  406.  
  407.  
  408.  
  409. ➤ Print Daimond shaped pattern of star's .
  410.  
  411. rows = 5
  412. i = 1
  413. while i <= rows:
  414.     j = rows
  415.     while j > i:
  416.         # display space
  417.         print(' ', end=' ')
  418.         j -= 1
  419.     print('*', end=' ')
  420.     k = 1
  421.     while k < 2 * (i - 1):
  422.         print(' ', end=' ')
  423.         k += 1
  424.     if i == 1:
  425.         print()
  426.     else:
  427.         print('*')
  428.     i += 1
  429.  
  430. i = rows - 1
  431. while i >= 1:
  432.     j = rows
  433.     while j > i:
  434.         print(' ', end=' ')
  435.         j -= 1
  436.     print('*', end=' ')
  437.     k = 1
  438.     while k <= 2 * (i - 1):
  439.         print(' ', end=' ')
  440.         k += 1
  441.     if i == 1:
  442.         print()
  443.     else:
  444.         print('*')
  445.     i -= 1
  446.  
  447.  
  448.  
  449.  
  450.  
  451. OUTPUT :
  452.  
  453.     *
  454.    * *
  455.   *   *
  456.  *     *
  457. *       *
  458.  *     *
  459.   *   *
  460.    * *
  461.     *
  462.  
  463.  
  464. ➤  Pattern to display letter of the word .
  465. word = "Python"
  466. x = ""
  467. for i in word:
  468.     x += i
  469.     print(x)
  470.  
  471.  
  472.  
  473.  
  474. OUTPUT :
  475.  
  476. P
  477. Py
  478. Pyt
  479. Pyth
  480. Pytho
  481. Python
  482.  
  483.  
  484. ➤  Print Equilateral triangle pattern of character's /alphabet's.
  485. print("Print equilateral triangle Pyramid with characters ")
  486. size = 7
  487. asciiNumber = 65
  488. m = (2 * size) - 2
  489. for i in range(0, size):
  490.     for j in range(0, m):
  491.         print(end=" ")
  492.     m = m - 1
  493.     for j in range(0, i + 1):
  494.         character = chr(asciiNumber)
  495.         print(character, end=' ')
  496.         asciiNumber += 1
  497.     print(" ")
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504. OUTPUT :
  505.  
  506.             A  
  507.            B C  
  508.           D E F  
  509.          G H I J  
  510.         K L M N O  
  511.        P Q R S T U  
  512.       V W X Y Z [  
  513.  
  514.  
  515. ➤ Print Random number pattern's.
  516. rows = 9
  517. for i in range(1, rows):
  518.     for i in range(0, i, 1):
  519.         print(format(2 ** i, "4d"), end=' ')
  520.     for i in range(-1 + i, -1, -1):
  521.         print(format(2 ** i, "4d"), end=' ')
  522.     print("")
  523.  
  524.  
  525.  
  526.  
  527.  
  528. OUTPUT :
  529.   1 
  530.    1    2    1 
  531.    1    2    4    2    1 
  532.    1    2    4    8    4    2    1 
  533.    1    2    4    8   16    8    4    2    1 
  534.    1    2    4    8   16   32   16    8    4    2    1 
  535.    1    2    4    8   16   32   64   32   16    8    4    2    1 
  536.    1    2    4    8   16   32   64  128   64   32   16    8    4    2    1 
  537. Go to Link

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.