0
What is the logic to write a code, so that we get number pyramid as output?
I have googled about this and found various answers. But i really did not understand the row and column logic there. Can someone please explain this in simple terms
2 Réponses
+ 5
Hello, మాధురి
Sure, basically it's the questions of the topic "Nested loop" , you can make it easily in python but in sense of other languages, they run a loop as outer loop to give the rows and inner for coloumns
A pyramid shape is like this
*
* * *
* * * * *
Now, try to find the pattern, like you can see that the sum of the number of spaces and the number of astricks are same, so you can do like this
sum = 5
for i in range(1,6,3):
print(' '*(sum-i) + '*' * (i))
Now do one thing, try to give the output of this code in a notebook for better understanding!
Happy Learning 🙂
+ 1
Thank you so much.