Star Patterns with Python Loops | Part 5 - Diamond

preview_player
Показать описание


Follow along with this tutorial to construct a diamond pattern using Python loops. Subscribe to the channel for more tutorials.
Рекомендации по теме
Комментарии
Автор

why do u need nested loop it can be done using single loop

srajesh
Автор

Using a while loop:

n = 5 #number of rows
i = 1
while i<=n:
print(" " * (n-i) + "*" * (2*i-1))
i+=1

i = n-1
while i>=1:
print(" " * (n-i) + "*" * (2*i-1))
i-=1

allnamestakennn
Автор

May I ask how to do sth like this ?:
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
Many thanks for your help

iwonkaawa
Автор

for i in range(5):
for j in range(i):
print(" ", end='')

for j in range(i, 5):
print('*', end='')

for j in range(i+1, 5):
print('*', end='')
print()

for i in range(4):
for j in range(i+1, 4):
print(' ', end='')
for j in range(i+1):
print('*', end='')
for j in range(i+2):
print('*', end='')
print()😁

kiantopgun