Program to print a pattern in python
Problem: Print a pattern of numbers from to as shown below. Each of the numbers is separated by a single space in python
4 4 4 4 4 4 4
4 3 3 3 3 3 4
4 3 2 2 2 3 4
4 3 2 1 2 3 4
4 3 2 2 2 3 4
4 3 3 3 3 3 4
4 4 4 4 4 4 4
Code:
n= int(input("enter"))
l=n*2-1
for i in range(l):
for j in range(l):
if(i<j):
m=i
else:
m=j
if(m<l- i):
m=m
else:
m=l-i-1
if(m<l-j):
m=m
else:
m=l-j-1
print(n-m, end=" ")
print("")
Screenshot of code and output:
Comments
Post a Comment