mercredi 11 novembre 2020

Printing a pyramid pattern inverse order in python

I am trying to print out this:

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

But somehow I get it in the inverse order like upside down This is my code. I am very confused since the things that I can use are very restrained. I must not use any String method, for loops, slicing-index, or "*" * n, something like that. All I can do is using while and if-else cases.

This is my code, I delve deep into it with trying not to make it useless.

outer = 10
while outer <= 10:
    inner = outer
    pos = 10  
    while pos >= 1:
        if pos > inner:
            print(" ", end=" ")  
            inner = inner - 1
            pos = pos - 1
        else:  
            print("*", end=" ")
            pos = pos - 1

    print(" ")
    outer = outer + 1

Thanks.

Aucun commentaire:

Enregistrer un commentaire