<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Aaesha Azeemuddin on Medium]]></title>
        <description><![CDATA[Stories by Aaesha Azeemuddin on Medium]]></description>
        <link>https://medium.com/@aaesha2402?source=rss-176885ca0b9e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*9cUO7-TgiSC7hu-A</url>
            <title>Stories by Aaesha Azeemuddin on Medium</title>
            <link>https://medium.com/@aaesha2402?source=rss-176885ca0b9e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 14:28:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aaesha2402/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Exploring Python Patterns with Loops]]></title>
            <link>https://medium.com/@aaesha2402/exploring-python-patterns-with-loops-b5b12c0e0ce4?source=rss-176885ca0b9e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5b12c0e0ce4</guid>
            <category><![CDATA[patterns-and-practices]]></category>
            <category><![CDATA[python-pattern]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Aaesha Azeemuddin]]></dc:creator>
            <pubDate>Thu, 11 Jan 2024 04:17:41 GMT</pubDate>
            <atom:updated>2024-01-11T04:17:41.206Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Welcome to our journey through Python patterns using loops! In this blog, we’ll dive into the fundamental concepts of while loops and for loops in Python, and then explore various patterns that showcase the versatility of these constructs.</p><h3>Understanding Loops in Python</h3><h3>1. While Loop:</h3><p>A while loop in Python continues to execute a block of code as long as a specified condition is true. The general syntax is as follows:</p><pre>while condition:<br>    # Code to be executed while the condition is true<br>    # This code block will repeat until the condition becomes false</pre><h3>2. For Loop</h3><p>A for loop is used for iterating over a sequence (that is either a list, tuple, dictionary, string, or range). The syntax is as follows:</p><pre>for variable in sequence:<br>    # Code to be executed for each item in the sequence</pre><p>Now, let’s explore some patterns to see for loop in action!</p><p><strong>COMMON TERMS TO REMEMBER:</strong></p><ol><li><strong>User Input:</strong> The program prompts the user to enter a number (n). This number determines the size of the pattern to be generated.</li><li><strong>For Loop: </strong>A for loop is employed to iterate from the range. The loop variable i will be used.</li><li><strong>Outer Loop (</strong><strong>for i in range(......):)</strong>: The outer loop runs from 1 to n (inclusive). It is responsible for iterating through each row of the pattern.</li><li><strong>Inner Loop (</strong><strong>for j in range(....):):</strong> The inner loop runs from 1 to i (inclusive), where i is the current value of the outer loop variable. This loop controls the number of columns for each row, starting from 1 and incrementing with each iteration of the outer loop.</li><li><strong>Second Inner Loop (</strong><strong>for k in range(....):):</strong> This inner loop is responsible for printing the asterisks in each line. The number of asterisks is determined by the expression. As i increases, the number of asterisks decreases.</li><li><strong>Printing Asterisks: </strong>The print(&#39;*&#39; * n) statement cleverly utilizes the * operator to create a row of asterisks. The sequence &#39;*&#39; represents an asterisk followed by a space, and by multiplying it by n, we create a row of n asterisks separated by spaces.</li><li><strong>Print Statement (</strong><strong>print(&#39;*&#39;, end=&#39; &#39;)): </strong>Inside the inner loop, the program prints an asterisk (*) followed by a space. The end=&#39; &#39; parameter ensures that the next character will be printed with a space instead of a new line, keeping the output on the same line.</li><li><strong>Newline (</strong><strong>print()): </strong>After the inner loop completes for a particular row, the program uses print() without any arguments to move to the next line. This creates a new line for the next row of the pattern.</li></ol><pre>#SQUARE GRID PATTERN:<br><br>n=int(input(&#39;enter a number: &#39;)) #Taking input from the user and  converting it to an integer<br>for i in range(n): # Using for loop to iterate from 0 to n-1<br>  print(&#39;* &#39;*n) #Printing row of asterisk &#39;*&#39; multiplied by the value n<br><br># OUTPUT <br>Enter a number: 5<br>* * * * * <br>* * * * * <br>* * * * * <br>* * * * * <br>* * * * *</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*hNTjqpdCuwJ1E4n28nXI3Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*b-QJNqAy5_QBiL_DTwI01A.jpeg" /><figcaption>🔍 Zoom-In for a Closer Look! 🌟</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*EDrQNY1aWYdLpNozH2hffw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*X7yID_Y15dhsAzfQd_fWrg.jpeg" /><figcaption>🔍 Zoom-In for a Closer Look! 🌟</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*iiwTNkTlKRGxz0I0pwkoAg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*WBFQqWE4YjIFnNYP5kDHXg.jpeg" /><figcaption>In the code “Left Aligned Decreasing Triangular pattern” <strong>Third Inner Loop (</strong><strong>for m in range(i):): This inner loop is responsible for printing the asterisks in decreasing order</strong>. The number of asterisks is determined by the current value of i.</figcaption></figure><ol><li><strong>First Loop (</strong><strong>for i in range(n):):</strong> This loop iterates from 0 to n-1 (inclusive), controlling the number of rows in the first half of the pattern.</li><li><strong>First Inner Loop (</strong><strong>for j in range(i):):</strong> This inner loop runs from 0 to i-1, determining the number of columns for each row in the first half. It prints the &#39;*&#39; character j times, separated by a space.</li><li><strong>Second Loop (</strong><strong>for i in range(n, 0, -1):):</strong> This loop iterates from n to 1 in reverse order, controlling the number of rows in the second half of the pattern.</li><li><strong>Second Inner Loop (</strong><strong>for k in range(i):):</strong> This inner loop runs from 0 to i-1, determining the number of columns for each row in the second half. It prints the &#39;*&#39; character k times, separated by a space.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*cJo9eLumVlp6BOy-dvLA5Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*DWw1cuMlUpTgFqb7rGU-Dw.jpeg" /><figcaption>🔍 Zoom-In for a Closer Look! 🌟</figcaption></figure><pre># DIAMOND PATTERN:<br><br>n = int(input(&quot;Enter your number: &quot;))  # Accepting input from the user<br># First half of the pattern<br>for i in range(n):  # Loop for the number of rows<br>    print(&quot; &quot; * (n - i), end=&quot; &quot;)  # Print leading spaces before the asterisks<br>    for j in range(0, i + 1):  # Loop for the number of columns<br>#Using if condition to print an asterisk at the beginning and end<br>        if j == 0 or j == i:  <br>            print(&quot;*&quot;, end=&quot; &quot;)  # Print asterisk separated by spaces<br>        else:<br>            print(&quot; &quot;, end=&#39; &#39;)  # Print space between asterisks<br>    print()  # Move to the next line after completing a row<br><br># Second half of the pattern<br>for i in range(n, -1, -1):<br>    print(&quot; &quot; * (n - i), end=&quot; &quot;)  # Print spaces before the asterisks<br>    for j in range(i+1):<br>#Using if condition to print an asterisk at the beginning and end<br>        if j == 0 or j == i:  <br>            print(&quot;*&quot;, end=&quot; &quot;)  # Print asterisk separated by spaces<br>        else:<br>            print(&quot; &quot;, end=&#39; &#39;)  # Print space between asterisks<br>    print()  # Move to the next line after completing a row<br><br># OUTPUT<br><br>Enter your number: 5<br>      * <br>     * * <br>    *   * <br>   *     * <br>  *       * <br> *         * <br>  *       * <br>   *     * <br>    *   * <br>     * * <br>      *</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*RnLfxRKyonRoqExFvU5R1Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*VMJL2gYZNzH10VpcrHJO6Q.jpeg" /><figcaption>🔍 Zoom-In for a Closer Look! 🌟</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*BV_1EzJLdmyW_YVsho2bkg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*2bvbslbwPPM9gBaLQFEbBg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*PY5eP20iN6kdRc_zpDpCow.jpeg" /><figcaption>🔍 Zoom-In for a Closer Look! 🌟</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*mN84xLShyXzUacLj8UZFpQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*QY3DLluTjsQXkV_h_BDlmg.jpeg" /></figure><pre># MIRRORED DIAMOND:<br><br>n=int(input(&quot;Enter your number : &quot;)) # accepting input from user<br>for i in range(n):  # loop for n number of rows<br>  for j in range(i+1):  # loop for i number of columns<br>    print(&quot;*&quot;,end=&#39;&#39;) # printing i number of *&#39;s separated by space<br>  for k in range(n-i-1):  # loop for n-i-1 number of spaces in each row<br>    print(&quot; &quot;,end=&#39; &#39;)  # printing n-i-1 spaces<br>  for m in range(i+1):  # loop for i number of columns<br>    print(&quot;*&quot;,end=&#39;&#39;) # printing i number of *&#39;s separated by space<br>  print() #an empty print() for next line<br><br>for i in range(n-1,0,-1):  # loop for n-1 number of rows<br>  for j in range(i):  # loop for i number of columns<br>    print(&quot;*&quot;,end=&#39;&#39;)  # printing i number of *&#39;s separated by space<br>  for k in range(n-i):  # loop for n-i number of spaces in each row<br>    print(&#39; &#39;,end=&#39; &#39;) # printing n-i spaces<br>  for k in range(i):  # loop for i number of columns<br>    print(&quot;*&quot;,end=&#39;&#39;)# printing i number of *&#39;s separated by space<br>  print() #an empty print() for next line<br><br># OUTPUT<br><br>Enter your number: 5<br>*        *<br>**      **<br>***    ***<br>****  ****<br>**********<br>****  ****<br>***    ***<br>**      **<br>*        *</pre><pre># SYMMETRICAL TRIANGULAR PATTERN:<br><br>n = int(input(&quot;Enter your number: &quot;))  #Taking input from the user <br><br># Checking whether the number is even or odd<br>if n % 2 == 0:<br>    n = n - 1  # If the number is even, decrement it by 1 to make it odd<br><br># Outer loop to iterate through each line, starting from 1 up to n//2+1<br>for i in range(1, n // 2 + 2):<br>  # Inner loop to print spaces before the first set of asterisks in each line<br>    for j in range(n - i - n // 2):<br>        print(&quot; &quot;, end=&quot; &quot;)<br>#Inner loop to print the first set of &#39;*&#39; in each line, starting from 1 to 2i-1<br>    for j in range(1, 2 * i):<br>        print(&quot;*&quot;, end=&quot; &quot;)<br>#Inner loop to print spaces before the second set of asterisks in each line<br>    for j in range(n - i - n // 2):<br>        print(&quot;   &quot;, end=&quot; &quot;)<br>#Inner loop to print the second set of &#39;*&#39; in each line,starting from 1 to 2i-1<br>    for j in range(1, 2 * i):<br>        print(&quot;*&quot;, end=&quot; &quot;)<br><br>    print()  # Moving to the next line after completing the inner loops<br><br># OUTPUT<br><br>Enter your number: 7<br>      *             * <br>    * * *         * * * <br>  * * * * *     * * * * * <br>* * * * * * * * * * * * * * </pre><pre># SYMMETRICAL TRIANGULAR PATTERN<br><br>n=int(input(&quot;Enter your number : &quot;)) # Taking input from the user <br>for i in range(1,n+1): # Outer loop to print the pattern in ascending order<br>  for j in range(n-i): #First inner loop to print spaces, aligning to the left<br>    print(&quot; &quot;,end=&#39;&#39;)<br>  for k in range(1,i+1): #Second inner loop to print left-aligned asterisks<br>    print(&quot;*&quot;,end=&#39; &#39;)<br>  for j in range(n-i): #Third inner loop to print spaces, aligning to the right<br>    print(&quot; &quot;,end=&#39; &#39;)<br>  for k in range(1,i+1): #Fourth inner loop to print right-aligned asterisks<br>    print(&quot;*&quot;,end=&#39; &#39;)<br>  print() # Moving to the next line after completing the inner loops<br><br> # OUTPUT<br><br>Enter your number: 5<br>    *         * <br>   * *       * * <br>  * * *     * * * <br> * * * *   * * * * <br>* * * * * * * * * * </pre><p><strong>CONCLUSION: </strong>These simple patterns serve as a foundational example of how loops and user input can be combined to create visual structures in Python. Stay tuned for more patterns and insights in our exploration of Python’s loop capabilities!</p><p><strong>Coming up next:</strong></p><ul><li>The Art of Numbers: A Journey into Patterns</li><li>Discovering Patterns in Letters: A Beginner’s Journey</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5b12c0e0ce4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>