Answer to Question #236832 in Python for Raju

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


1
Expert's answer
2021-09-15T13:52:21-0400
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS