This goes with the saying that, practice makes perfect; It's very easier to understand this language more so if you like practicing it, than when reading python novels and tutorials without practicing on them.
In this article, I'm going to show you how to create half a pyramid and later make a complete one.
Let's start with half a pyramid.
Codes.
We are using a star * as our building block of the pyramid. The space b=" " represents the gaps between each star *.
i=4 means that our pyramid will have four lines and since the counting in python starts from zero, that's why we end up getting five lines of stars.
The range(i, _1, _1) means that the counting will start from four going backward.ie 4,3,2,1,0.
J=j+1 means that, since j=1, the first star should be one, the next stars should be two, the next three stars, etc.
So, if you want to make a bigger structure of the pyramid, you can place a bigger number where there is i.ie i= 5,6,7,8 or any other number.
Complete pyramid.
Since the above structure is half a pyramid, to make a complete one, we need to double the first codes. Just a small change and boom the pyramid.
Where to place the code.
Our above code where there is print(k*b)+(j*a)) is where we are going to make the changes .ie print(k*b)+(j*a)*2).
Remember to leave a comment and follow my blog for more short python projects.
No comments:
Post a Comment