This code works perfectly:
n=int(raw_input('n='))
for i in range(1,n+1):
for j in range(1,n+1):
if j==1 or j==n or j==i:
print'#',
else:
print' ',
print
solved Print the following pattern in Python language