-2

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"
Dqnny
  • 11
  • 4

1 Answers1

6

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.

Damian Yerrick
  • 4,602
  • 2
  • 26
  • 64
  • Is it possible to remove a certain number of spaces? For example https://repl.it/Do3C/0 in this case, how would I be able to remove 1 space from newstr? – Dqnny Oct 05 '16 at 02:55
  • To remove the first character, use a subsequence `s[1:]`. Read the Sequence Types link. – Damian Yerrick Oct 05 '16 at 02:57