From f70039d21b8e074002258fd57fe9797f7d7ed6a7 Mon Sep 17 00:00:00 2001 From: theeducationalworld <64415119+theeducationalworld@users.noreply.github.com> Date: Sun, 22 Oct 2023 16:28:50 +0530 Subject: [PATCH] Create print the diamond shape Given a number n, write a program to print a diamond shape with 2n rows. --- P/print the diamond shape | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 P/print the diamond shape diff --git a/P/print the diamond shape b/P/print the diamond shape new file mode 100644 index 00000000..555f55e4 --- /dev/null +++ b/P/print the diamond shape @@ -0,0 +1,40 @@ +# Python program to +# print Diamond shape + +# Function to print +# Diamond shape +def Diamond(rows): + n = 1 + for i in range(1, rows + 1): + # loop to print spaces + for j in range (1, (rows - i) + 1): + print(end = " ") + + # loop to print star + while n != (i+1): + print("*", end = " ") + n = n + 1 + n = 1 + + # line break + print() + + k = 0 + n = 0 + for i in range(1, rows + 1): + # loop to print spaces + for j in range (1, k + 1): + print(end = " ") + k = k + 1 + + # loop to print star + while n <= (rows - i): + print("*", end = " ") + n = n + 1 + n = 0 + print() + +# Driver Code +# number of rows input +rows = 5 +Diamond(rows)