Create a certain triangle with stars
Question: I'm using python IDE wing version 4.1

I'm trying to write a function with only 1 input which will be an integer and
return the next shape of stars:

    
    
      *
     **
    ***
    

I tried using the following code but it gave another shape:

    
    
    from math import *
    from string import *
    def tri_1(n):
        x=n*'*'
        i=0
        while i<5:
            x=i*'*'
            i=i+1
            print x
    
    n=input()
    tri_1(n)
    


Answer: You need to think more carefully about what the algorithm should do. For each
integer in the range `1` to `n` inclusive you want to print `n-1` spaces
followed by `n` asterisks, so what is the hard-coded `5` doing there? Why
don't you have _any_ spaces? Given that you know how many times you will loop,
why use `while` rather than `for`?

The most efficient way to achieve this is using the built-in string method
[`rjust`](https://docs.python.org/2/library/stdtypes.html#str.rjust), which
pads the supplied string with spaces:

    
    
    def tri_1(n):
        for i in range(1, n+1):
            print(str.rjust("*"*i, n))
    

