3
Contributors
3
Replies
14
Views
2 Years
Discussion Span
Last Post by woooee
0
 z=1   

 while z<=40:

 y=0
 x=10
while y<=10:
    print(" "*y,"*")
    y+=1
while x>=0:
    print(" "*x,"*")
    x-=1
    z=z+1
0

You can use he same variable for the number of spaces to print, see below. If you want to print a total of 40 stars, I can't tell from your code and you didn't explain

empty_spaces=0
one_side=7 # stars
stars_side=0
incr=1
stars_printed=0
while stars_printed < 40:
    print "%s*" % (" "*empty_spaces)
    stars_printed += 1
    empty_spaces += incr
    stars_side += 1

    ## change direction every "one_side" stars
    if stars_side >= one_side:
        stars_side=0
        if incr == 1:
            incr = -1
            print "testing: incr changed to minus one"
        else:
            incr = 1
            print "testing: incr changed to plus one"

Edited by woooee

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.