[Solved] How to make a triangle of x’s in python?


Dude It’s super easy:

def triangle(n):
    for i in range(1, n +1):
        print ' ' * (n - i) + 'x' * i

Or even:

def triangle(n):
    for i in range(1, n +1):
        print ('x' * i).rjust(n, ' ')

output for triangle(5):

    x
   xx
  xxx
 xxxx
xxxxx

Dont just copy this code without comprehending it, try and learn how it works. Usually good ways to practice learning a programming language is trying different problems and seeing how you can solve it. I recommend this site, because i used it a lot when i first started programming.

And also, dont just post your homework or stuff like that if you dont know how to do it, only if you get stuck. First try thinking of lots of ways you think you can figure something out, and if you dont know how to do a specific task just look it up and learn from it.

3

solved How to make a triangle of x’s in python?