0% found this document useful (0 votes)
12 views2 pages

P02 - Print Diamond Shape

Uploaded by

CRITERION II
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

P02 - Print Diamond Shape

Uploaded by

CRITERION II
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

2.

Write a Python program to construct the following pattern, using a nested loop

*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
Aim : Print *s in Diamond Shape.

Procedure:

Step 1: Open Python IDE.

Step 2: Get the input for n.

Step 3: Create a for loop for n terms.

Step 4: Create a nested for loop for printing spaces.

Step 5: Create another nested for loop for printing *s.

Step 6: Write print statement to move to the next line.

Step 7: Use the statements as like step 3 to 6 for decreasing for loop for printing second half of the pattern.

Result: Python program to construct the printing pattern is done successfully.


Program:

# Print *s in Diamond shape


n=int(input("Enter a Number:"))
for i in range(1,n+1):
for space in range(1,40-i):
print(" ",end='')
for top in range(1,i+1):
print("*",end=' ')
print()
for i in range(n-1,0,-1):
for space in range(1,40-i):
print(" ",end='')
for bottom in range(1,i+1):
print("*",end=' ')
print()

Output:
>>>
Enter a Number:5
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
>>>

You might also like