Triangle Program in Python

Print the Triangle in stars( * ) using Python...

Output:


       * 

      * * 

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

Program:

for python 3...

n = 7
for i in range(n):
    
    for j in range(0,n):
        print(end=" ")
    n = n-1    

    for k in range(0,i+1):
        print("*",end=" ")
    print("\r")

------------------------------------------------------------------------------------


Right hand triangle in numbers( 0-9 ) using python...

Output:

1
22
333
4444
55555
666666
7777777
88888888
999999999

Program:

for python 3...

n = 9
k = 1
for i in range(n):
    for j in range(0,i+1):
        print(k,end="")
    print("\r")
    k = k+1


---------------------------------------------

Comments

Popular posts from this blog

Swap file using python

PyCon-India 2019

Addition Game using Python