Answer to Question #228294 in Python for varun

Question #228294

Diamond Crystal


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


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

Sample Input 1


5


Sample Output 1


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

Sample Input 2


3


Sample Output 2


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

Refer to the document in the link below 


https://docs.google.com/document/d/1RBknUJ-BqOf7C-5nMxEFs4JxAUQo4_KSt07SSkS3Jak/edit?usp=sharing


1
Expert's answer
2021-08-22T07:15:15-0400
N = int(input('Enter integer here: '))
rows = 2 * N
for i in range(rows):
  s = i + 1
  if s <= N:
    print((N-s)*' '+'/' +'  '*i + '\\' )
  else:
    print((s-N-1)*' '+'\\' +'  '*(rows-i-1) + '/' )

Enter integer here: 6
     /\
    /  \
   /    \
  /      \
 /        \
/          \
\          /
 \        /
  \      /
   \    /
    \  /
     \/

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

varun
22.08.21, 15:28

Thank you

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS