Python Program to Print Diamond Crystal | Python Pattern Programs

 

Python Program to Print Diamond Crystal | Python Pattern Programs

Python Program to Print Diamond Crystal 

Program:

Given an integer value N, write a program to print a diamond pattern of 2*N rows as shown below.

Input:

The first line of input is an integer N

Explanation:

In the given example, the number of rows in the diamond is 2*5 = 10 So, the output should be

    /\ 
   /  \ 
  /    \ 
 /      \ 
/        \ 
\        /
 \      /
  \    /
   \  /
    \/

Code:

n=int(input())
for i in range(n):
    print(" "*(n-i-1),end="")
    print("/",end="")
    print(" "*(i+i),end="")
    print("\ " ,end="")
    print()
for i in range(n-1,-1,-1):
    print(" "*(n-i-1),end="")
    print("\\",end="")
    print(" "*(i+i),end="")
    print("/" ,end="")
    print()

Sample Input: 3

Sample Output:

  /\ 
 /  \ 
/    \ 
\    /
 \  /
  \/

Comments

Popular posts from this blog

CODING ASSIGNMENT 4

CODING PRACTICE 11 Music Page

CCBP Static Website Coding Assignment 2 Solution | Yoga Page