Question #236832

Given an integer N, write a program to print the hollow diamond pattern in 2*N rows and 2*N columns, similar to the pattern shown below


Expert's answer

def diamond(n):
    for i in range(n):
        s = [' ']*n
        s[n-1-i] = '*'
        s = s + s[::-1]
        s = ''.join(s)
        print(s)
    for i in range(n):
        s = [' ']*n
        s[i] = '*'
        s = s + s[::-1]
        s = ''.join(s)
        print(s)

def main():
    n = int(input('Enter a number N '))
    diamond(n)

if __name__ == '__main__':
    main()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS