A Python program that prints a right-aligned upper half followed by a left-aligned inverted lower half using repeated numbers and nested loops.
It is just a begining of my python learning series, where i write some python programs to improve my pyton learning and enhance skills.
Code:
The code is:
`cnt = 1
m = int(input("Enter the number you are up to print{numbers should be in range 2-9}:"))
space = m - 1
# Upper half:
for i in range(1, m + 1):
print(space * " " + cnt * str(i))
space -= 1
cnt += 1
# Lower half:
cnt -= 2
for i in range(m - 1, 0, -1):
print(cnt * str(i))
cnt -= 1
`
The output will be a half aligned diamond.
Top comments (0)