I made this code which outputs

``````     .
...
.....
...*****.
....***...
.....*.....
``````

but its supposed to output

``````     .
...
.....
.*****.
...***...
.....*.....
``````

Any ideas what im doing wrong?

To output the triangle
myChar1 = *
myChar2 = .
myLen = 3

``````myChar1 = input("Select first character: ")
myChar2 = input("Select Second character: ")
myLen = int(input("Length of first segment: "))

def triangle1(mylen):
for i in range(mylen, 0, -1):
print('.'*(mylen-i+3) + myChar1*(2*i-1) + '.'*(mylen-i*2+4))
def triangle2(mylen):
for i in range(mylen):
print(' '*(mylen-i+2) + myChar2*(2*i-1))

triangle2(4), triangle1(3)
``````

You are perhaps over thinking this with all of the complicated print statements. You now want a second function with num_dots, num_spaces, and num_stars, and print and then add/subtract from each field accordingly.

``````def top_down(my_len, spaces):
num_dots = 1
for ctr in range(my_len):
print ' '*spaces + '.'*num_dots
num_dots += 2
spaces -= 1

myChar1 = '*'
myChar2 = '.'
my_len = 3

top_down(my_len, 5)
## as an example only --> but number of spaces will be first number-my_len
## that is 5-3
top_down(my_len, 2)
``````

I acted upon the code you supplied me, but im still having a problem

The output is below

``````     .
...
.....
*****.
***...
*.....
.
...
.....

def top_down(my_len, spaces):
num_dots = 1
for ctr in range(my_len):
print(' '*spaces + '.'*num_dots)
num_dots += 2
spaces -= 1

def top_down2(my_len, num_spaces):
num_dots = 1
num_spaces = 3
num_stars = 5
for ctr in range(my_len):
print(' '*num_spaces + '*'*num_stars + '.'*num_dots)
num_dots += 2
num_spaces += 1
num_stars -= 2

myChar1 = '*'
myChar2 = '.'
my_len = 3

top_down(my_len, 5)
top_down2(3, my_len)
top_down(my_len, 2)
``````

It should be obvious that top_down2 should print 2 "dot" triangles and one "star" triangle. Start by getting the "draw the left most triangle" to work, then add the star triangle, then add in the right most triangle. Don't make me sorry I helped you on this.

Note also that you should not hard wire the number of spaces as that will change as my_len changes, as will num_stars (which you can calculate or take the number of dots printed in the final row of the first function). I gave you a hint on how to calculate the number of start spaces for the second function. You will have to figure out the relationship between my_len and the number of start spaces for the first function.

Finally, you pass num_spaces to the function but then re-set to 3 within the function. See "Calling a Function" and "The Return Statement" in this tutorial for info on passing parameters to and getting them from functions. I will not write this program for you.

Thanks for the extra help woooee! Even thought I got to it in the end using a slightly different method. I always appreciate the help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.