Write a python program to take the number of lines as input and print the following patterns
Input
Enter the number of lines
4
Output
1
2 4 2
1 3 5 3 1
2 4 6 8 6 4 2
1 3 5 3 1
2 4 2
1
def row(i, n):
print(" " * (n - i), end="");
x = -1 if i % 2 == 1 else 0
for _ in range(i):
x = x + 2
print(x, end=" ")
for _ in range(i-1):
x = x - 2
print(x, end=" ")
print()
def diamond(i, n):
row(i, n);
if (i < n):
diamond(i + 1, n);
row(i, n);
def main():
n = int(input('Enter the number of lines:'))
diamond(1, n);
if __name__=='__main__':
main();
Comments
Leave a comment