Friday, July 5, 2019

Regular triangle using stars

Script

#!/usr/local/bin/python3.7

print ("Enter the number of stars in the last line: ", end = "")
lines = int(input())

k = 0
for i in range(1, lines + 1):
    for j in range (1, (lines - i) + 1):
        print(end = " ")
    while k != (2 * i - 1):
        print("*", end = "")
        k = k + 1
    k = 0

    print()


Execution

Enter the number of stars in the last line: 25
                                                 *
                                               ***
                                             *****
                                           *******
                                         *********
                                       ***********
                                     *************
                                   ***************
                                 *****************
                               *******************
                             *********************
                           ***********************
                        *************************
                      ***************************
                    *****************************
                   *******************************
                 *********************************
               ***********************************
             *************************************
           ***************************************
         *****************************************
       *******************************************
      *********************************************
    ***********************************************
  *************************************************





No comments:

Post a Comment