Skip to main content

Command Palette

Search for a command to run...

Basics of Python-11

Published
2 min read
Basics of Python-11
P

Hello, I'm Priya Chakraborty, a dedicated B.Tech student in Electrical Engineering at Siliguri Institute Of Technology. I'm an enthusiastic learner, constantly seeking to expand my skill set and knowledge base. With a solid foundation in programming languages such as C, R, Python, and MySQL, I'm poised to tackle complex technical challenges.

But my passions extend beyond the realm of engineering. I'm also an aspiring content writer, driven by a curiosity to communicate ideas, both technical and non-technical, in a way that captivates and educates.

My journey is defined by a relentless pursuit of self-improvement, coupled with strong communication skills. I believe in the power of continuous learning and the importance of sharing knowledge.

Day-11

Pattern printing :

Pattern printing is done by using loops in python. I am going to use for loop for pattern printing. By doing it, you will get a clear idea about loops in python, it makes you get a clear understanding to approach a problem.

  1. Write a python program to print this pattern:-

     n=5
     i=1;j=0
     while(i<=n):
         while(j<=i-1):
             print("* ",end="")
             j+=1
    
         print("\r")
         j=0;i+=1
    

    output :

  1. Write a python program to print this pattern:-

n = 5
for i in range(1, n+1):
    for j in range(n - i):
        print(' ', end='')
    for k in range(2 * i - 1):
        print('*', end='')
    print()

output :

  1. Write a python program to print this pattern:-

size = 5
num = 1
for i in range(1, size + 1):
    for j in range(size, i - 1, -1):
        print(" ", end="")
    for k in range(0, i * 2 - 1):
        print(num, end="")
        num += 1
    num = 1
    print()
for i in range(1, size):
  for j in range(0, i+1):
        print(" ", end="")
 for k in range((size - i) * 2 - 1):
        print(num, end="")
        num += 1
   num = 1
   print()

output :

These are the basic pattern printing,by using for loop in python. In my next blog ,you will get to know about while loop in python.

Thank you !!

More from this blog

Priya's blog

46 posts

Python Developer@Codeclause Mentee @Trailhead Salesforce Content Executive @GDSC SIT'22-23 Google Women Techmakers Ambassador @Google WTM Coreteam @ GirlScript Kolkata