Program to print a square of size n using asterisk in Python
In the python programming article, we are going to learn
-
program to print a sqaure of size n using asterisk in python
Program to print a square of size n using asterisk in Python
The program is as follows:
# Owner : TutorialsInhand Author : Devjeet Roy
size = int(input("Enter the size of square: "))
for i in range(size):
for j in range(size):
print("*", end=" ")
print()
The output is as follows:
PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter the size of square: 6
* * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * *
Few important tips about the program
1. Firstly, we ask the user to enter the length of side of the square.
2. Then. we use two loops to print the asterisks. The two loops take care of the rows and columns respectively.
3. The end attribute is "\n" by default. We have changed it to a single space.
4. The blank print() function allows the control to go to the next line, once the row is completed.
Would you like to see your article here on tutorialsinhand.
Join
Write4Us program by tutorialsinhand.com
About the Author
Devjeet Roy
Full Stack Web Developer & Blockchain Enthusiast
Page Views :
Published Date :
Oct 13,2022