-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from raypretam/Hour_Glass
Added hour_glass_pattern.py
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
def hour_glass_pattern(n): | ||
|
||
# loop for printing the upper half | ||
for i in range(n+1): | ||
|
||
# printing the spaces at the beginning | ||
for k in range(i): | ||
print(" "*2, end="") | ||
|
||
# printing the values in each row | ||
for j in range(-(n-i), (n-i+1)): | ||
print(abs(j), end=" ") | ||
|
||
print() | ||
|
||
# Loop for printing the lower half | ||
for i in range(1, n+1): | ||
|
||
# Printing spaces at the beginning | ||
for k in range(n-i): | ||
print(" "*2, end="") | ||
|
||
# Printing values in each row | ||
for j in range(-i, i+1): | ||
print(abs(j), end=" ") | ||
|
||
print() | ||
|
||
|
||
n = int(input("Enter the number of rows : ")) | ||
hour_glass_pattern(n) |