'Python: a pattern of two signs (* and $) that creates a pyramid
I want to create a pattern that looks like this:
*
* $
* $ *
* $ * $
* $ * $ *
* $ * $
* $ *
* $
*
I know how to use nested loops to print pattern like this with one sign but I have difficulties to create it wth two signs. Any idea how to do that?
Solution 1:[1]
I am using python3 here
for i in range(5):
for j in range(i+1):
print('*' if j%2==0 else '$' , end=" ")
print()
for i in range(4):
for j in range(4-i):
print('*' if j%2==0 else '$' , end=" ")
print()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hari Prasad |
