What is the logic to write a code, so that we get number pyramid as output? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
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

31st Jan 2022, 11:05 AM
మాధురి
మాధురి - avatar
2 ответов
+ 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 🙂
31st Jan 2022, 2:15 PM
Abhiyantā
Abhiyantā - avatar
+ 1
Thank you so much.
31st Jan 2022, 2:50 PM
మాధురి
మాధురి - avatar