Python triangel pattern

Hi!
I’m having som trouble understanding the concept of this excercise.
The program is gonna read a positive integer from user and print out two traingles, one right-angled and one isoceles.

Enter an odd positive integer: 7

Right-Angled Triangle:

Isosceles Triangle:

This is my code:

space=0

n = int(input("Enter an odd positive integer:")) #7 for an example

if n<=0 or n%2==0:
    print("It must be and odd and positive number!")

else:
    stars=n-space

    print("Right-Angled Triangle:")
    while space<n:
        print (space*' ',stars*'*')
        space+=1
        stars=n-space
        if space==n:
            break


    space = 0
    row = 1
    n = n
    i = int((n+1)/2)
    stars =n-space

    print("Isosceles Triangle:")

    for space in range(i):
        space = ((n-row)//2)
        stars=int(row)
        print(space*' ',stars*'*')
        row += 2

And the reason i made this post is that I have some problem understanding it. I did it some time ago, and with help of some friends. Would appreciate alternativ solutions and/or some insight on the excercise!

If you wrote it then you must understand parts of it. What particular points are now causing you a problem? Have you tried breaking them down to smaller lines and understanding them one by one? It’s a good place to start.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.