Rectangle Pattern Program In Python Most asked in interview
And below Python concepts are used to print that patterns
For Loop
While Loop
if..else
1). Program to print Solid Rectangle using star(*) in Python
print("This is Rectangle program")
rows = int(input("Enter number of rows: "))
columns = int(input("Enter number of columns: "))
for i in range(0,rows):
for j in range(0,columns):
print("*",end='')
print()
Output
2). Program to print hollow Rectangle using star(*) in Python
print("This is Rectangle program")
rows = int(input("Enter number of rows: "))
columns = int(input("Enter number of columns: "))
for i in range(1,rows+1):
for j in range(1,columns+1):
if i==1 or i==rows or j==1 or j==columns:
print("*",end='')
else:
print(" ",end='')
print()
Output
Keep reading
Related Questions
More from Interview Preparation — pick the next question to continue your revision.