Square Pattern
- Display the title "Square Pattern"
- Set the size of the square (e.g., 5)
- Use nested loops:
- Outer loop runs for the number of rows (i.e., size)
- Inner loop runs for the number of columns (i.e., size)
- Print the "*" character in each iteration of the inner loop, with a space after it
- After each row, move to a new line by printing an empty line
Hello, dear reader! 👋
Thanks for visiting my blog! I’m a student just like you, sharing what I learn to help others with Python programming. I hope my posts are useful for your studies! 😊
If you find this post helpful, please leave a comment—even just a few emojis will make my day! 🐍✨ Your feedback keeps me motivated to create more content for everyone. 🚀
Happy programming!
— Abhin Krishna, S01, EB Department, MEC
START
DISPLAY "Square Pattern"
SET size = 5
FOR i FROM 0 TO size - 1
FOR j FROM 0 TO size - 1
PRINT "*" FOLLOWED BY A SPACE
PRINT NEW LINE
PRINT NEW LINE
END
print("Square Pattern:")
size = 5
for i in range(size):
for j in range(size):
print('*', end=' ')
print()
print() # Add an empty line for separation
Important!
If you find any mistakes in my code or flowchart, please comment below this post. I will be happy to correct them and clear up any doubts you may have.
Right-Angled Triangle Pattern
- Display the title "Right-Angled Triangle Pattern"
- Set the size of the triangle (e.g., 5)
- Use nested loops:
- Outer loop runs for the number of rows (i.e., size)
- Inner loop runs for the number of columns (i.e., current row number)
- Print the "*" character in each iteration of the inner loop, with a space after it
- After each row, move to a new line by printing an empty line
START
DISPLAY "Right-Angled Triangle Pattern"
SET size = 5
FOR i FROM 1 TO size
FOR j FROM 1 TO i
PRINT "*" FOLLOWED BY A SPACE
PRINT NEW LINE
PRINT NEW LINE
END
print("Right-Angled Triangle Pattern:")
size = 5
for i in range(1, size + 1):
for j in range(i):
print('*', end=' ')
print()
print() # Add an empty line for separation
Important!
If you find any mistakes in my code or flowchart, please comment below this post. I will be happy to correct them and clear up any doubts you may have.
Pyramid Pattern
- Display the title "Pyramid Pattern"
- Set the size of the pyramid (e.g., 5)
- Use nested loops:
- Outer loop runs for the number of rows (i.e., size)
- First inner loop runs for the number of leading spaces (i.e., size - current row number - 1)
- Second inner loop runs for the number of stars (i.e., 2 * current row number + 1)
- Print the leading spaces, then print the stars with a space after each
- After each row, move to a new line by printing an empty line
START
DISPLAY "Pyramid Pattern"
SET size = 5
FOR i FROM 0 TO size - 1
FOR j FROM 0 TO size - i - 1
PRINT " " FOLLOWED BY A SPACE
FOR k FROM 0 TO 2 * i
PRINT "*" FOLLOWED BY A SPACE
PRINT NEW LINE
PRINT NEW LINE
END
print("Pyramid Pattern:")
size = 5
for i in range(size):
# Print leading spaces
for j in range(size - i - 1):
print(' ', end=' ')
# Print stars
for k in range(2 * i + 1):
print('*', end=' ')
print()
print() # Add an empty line for separation
Important!
If you find any mistakes in my code or flowchart, please comment below this post. I will be happy to correct them and clear up any doubts you may have.