This repository has been archived by the owner on Dec 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 366
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 #456 from Vaibhavpan02/main
Create Pyramid_pattern.py
- Loading branch information
Showing
2 changed files
with
55 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,36 @@ | ||
import java.io.*; | ||
|
||
// java program for left triangle | ||
public class GFG { | ||
// Function to demonstrate printing pattern | ||
public static void StarleftTriangle(int k) | ||
{ | ||
int a, b; | ||
|
||
// 1st loop | ||
for (a = 0; a < k; a++) { | ||
|
||
// nested 2nd loop | ||
for (b = 2 * (k - a); b >= 0; b--) { | ||
// printing spaces | ||
System.out.print(" "); | ||
} | ||
|
||
// nested 3rd loop | ||
for (b = 0; b <= a; b++) { | ||
// printing stars | ||
System.out.print("* "); | ||
} | ||
|
||
// end-line | ||
System.out.println(); | ||
} | ||
} | ||
|
||
// Driver Function | ||
public static void main(String args[]) | ||
{ | ||
int k = 5; | ||
StarleftTriangle(k); | ||
} | ||
} |
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,19 @@ | ||
def pypart(n): | ||
|
||
# outer loop to handle number of rows | ||
# n in this case | ||
for i in range(0, n): | ||
|
||
# inner loop to handle number of columns | ||
# values changing acc. to outer loop | ||
for j in range(0, i+1): | ||
|
||
# printing stars | ||
print("* ",end="") | ||
|
||
# ending line after each row | ||
print("\r") | ||
|
||
# Driver Code | ||
n = 5 | ||
pypart(n) |