The user enters a number and the program should output that amount of rows and colunmns. I have tried a couple of different ways butcant quite get it even though I think I am close. for example if 10 is entered it should look something like this:

O

OO

OOO

OOOO



OOOO

OOO

OO

O

Code:

num = 0
#user input
num = int(raw_input('Give me a number up to 10: '))    

for a in range(0,num +1,1):
    print "*" * a
#make a space for the next rows that count down
print
for a in range(num,0,-1):print'*' * a
print'done'
#a different way
num = 0
num = int(raw_input('What is your number: '))
for row in range(1, num + 1, 1):
    for column in range(1, num, 2):
        circleList = list()
        circleList.append(row)
        print'*'

Edited 3 Years Ago by mike_2000_17: Fixed formatting

num = 0
#user input
num = int(raw_input('Give me a number up to 10: '))    

for a in range(0,num +1,1):
    print "*" * a
#make a space for the next rows that count down
print
for a in range(num,0,-1):print'*' * a
print'done'
#a different way
num = 0
num = int(raw_input('What is your number: '))
for row in range(1, num + 1, 1):
    for column in range(1, num, 2):
        circleList = list()
        circleList.append(row)
        print'*'

circlelist is never used and it is list(range(1, num + 1)) why you produce the numberlist?

The user enters a number and the program should output that amount of rows and colunmns.

Your for() loop actually prints the same number of __rows__ as the number entered by the user. Instead, you want to use a counter to count each object when it is printed/displayed. According to your diagram, you want to print up to number/2 and then print the bottom half=number/2 as well. Also, how would you print if an odd number, like 9, was entered. Here's an example for the top half to get you started:

number = 12
ctr = 0
row = 1

while ctr < number/2:
    print "*" * row, 
    ctr += row     ## number of objects printed
    print "    row =", row, "ctr is now", ctr
    row += 1

Edited 6 Years Ago by woooee: n/a

This question has already been answered. Start a new discussion instead.