Dqnny - 2 months ago 7

Python Question

Here is my current code. The question is exactly in the title. (I'm looking to be able to align my triangle correctly)

`def Triangle(height):`

if height % 2 == 0:

print "Please enter a height that is odd"

else:

stringTriangle = "x"

for x in range(height):

print stringTriangle

for x in range(1):

stringTriangle+="xx"

Answer

To make a string containing `n`

spaces, use `" "*n`

. To concatenate two strings `a`

and `b`

, use `a + b`

. To learn about other things that can be done with strings, see Python 2: Built-in Types: `str`

and Other Sequence Types.

From there, you should be able to solve your homework problem by calculating how many spaces and how many asterisks you need in each line of the figure.