Computer Science, asked by AlwaysSmile, 1 year ago

WRITE A PYTHON PROGRAM TO PRINT THE FOLLOWING PATTERN.............

#CONTENT QUALITY REQUIRED

#NO SPAMS

#RIGHT ANSWER WILL BE MARKED BRAINLIEST

Attachments:

AlwaysSmile: using for loop

Answers

Answered by manamperi344
8

for i in range(6):


   

        spaces = i   #The number of spaces in the beginning of row.


   

        row = [j+1 for j in range(6-i)] + [(6-i-1)-j for j in range(6-i-1)]   #Add numbers into row.


   

        row_string = ' '.join(map(str, row))   #Convert list to string. Use map to turn ints in list to strings.


   

        for j in range(spaces):


       

                 row_string = ' ' + ' ' + row_string  

   

        print(row_string)

Attachments:

manamperi344: The code doesn't look nice when I paste is here... (I guess the answer box isn't meant to contain code, but oh well.) Hope you like this :)
AlwaysSmile: u have which version of python??
manamperi344: This is python 2.7
manamperi344: But it should work with python 3 as well.
Answered by Anonymous
15

Hey there!




Here's your code.







# Python Program Using For Loop To Print Full Inverted Triangle Pyramid Of Numbers

# Author : Mahnaz @NamkeenCandy




print("\t\t\t\tFull Inverted Triangle Pyramid of Numbers")



limit = spacecount = 6


# I am putting 6 because it's been asked in your question

# Here you can use any number instead of 6


while limit:

     print(' '*(spacecount-limit), end='')

     for _ in range(1,limit+1):

         print(_, end='')

     for _ in range(limit-1, 0, -1):

         print(_, end='')

     print('')

     limit -=1




______________________________

See the attachment for proper review.

______________________________

Attachments:
Similar questions