Play with For Loops in Python

I guess this is one of most coolest way to improve your logic and better understanding of any language
This is very small program, i have developed in python to create a simple patter

*
**
***
****
*****


import sys
# Define a main() function that prints a little greeting.
def main():
 
 # Get the name from the command line, using 'World' as a fallback.
    for x in range(1,6):
        print '*' * x
            
            
# This is the standard boilerplate that calls the main() function.

if __name__ == '__main__':
  main()
Explanation of code,

def main(): //Function definition, since in python main function is not called automatically

for x in range(1,6): // Similar to for(i = 1; i<6;i ++) in c++
print '*' * x // for printing * as many times value of x

if __name__ == '__main__': // basically similar to call of any function
main()


This is simplest explanation of above code ,Please correct me if i am wrong somewhere

Also Please come out with some more interesting patterns in pythons , i will also come out with more 😀

Replies

You are reading an archived discussion.

Related Posts

hi.. i am doing a project on texture analysis.. can u provide me a code for calculating GLCM manually?? I am not able to do it..
We've been relying on the fossil fuels for a long time now and it seems that most of the world's problem - economical & health-related seems to be a direct...
a few guidelines to follow for the bridge design. This includes following steps: 1. Understand purpose 2. Site navigation 3. Materials Selection 4. Design Standards and Codes.
Good evening everybody. I 've just managed to register and was wondering that I will make a little offtopic here. If I posted to the wrong category, moderation, please move...