Lesson 2 - While Loop - in lecture problem

Hi - Very new to the python programming and programming in general. I will appreciate any hints or direction towards solving this exercise that was given in lesson 2 - while loops - cell 40

line =’*’
max_length = 10

while len(line) <=max_length:
line+= “*”

while len(line)>0:
line = line[:-1]

The problem in the lesson was to build pattern/shapes using this code and I am trying to understand but running clueless so far.
Any hints or direction or link to understand the similar logic is appreciated ?

Hey @clforabhi, welcome to the forum,
Count the number of *, initially, you are starting with one star, but with each iteration, you are first increasing the stars and then decreasing them. Try to run the first part first and next part in the next cell and see what happens, also change the values of max_length to 4 and 5 and you will be able to see a difference.

1 Like

Hi @birajde - Thank you for the inputs. I tried but I could not do it with While loop , although I gave it a try with for loop and I was mildly successful , I will keep trying with While loop.
line =""
max_length = 5
length = len(line)
for i in range (max_length):
for j in range (max_length-i-1):
print(" “,end = “”)
for j in range (i+1):
print(line , end=” “)
for i in range (max_length,0,-1):
print(” "
(max_length-i)+"* "*i)

Can you show what you tried with while loop? And, what result you got using for loop?