Print a 9x9 diamond shaped pattern.......using loops

#written by Chris O'Leary:
#Filename: star.py
star=1
space=5
def star_decrease(star,space):
    while star > 0:
        print " "*space + "*"*star
        space = space+1
        star = star-2
def star_increase(star,space):
    while star < 9:
        print " "*space + "*"*star
        space = space-1
        star = star+2
        if star == 9:
            star_decrease(star, space)
star_increase(star,space)

Recommended Answers

All 3 Replies

I've adapted the code to do ASCII pics of the Union Jack and the US flag:

lines = 10
while lines > 0:
    if lines > 5:
        print "*"*10 + "="*10
        lines = lines-1
    elif lines <= 5:
        print "=" * 20
        lines = lines-1

The american flag ------^

lines=0
B=10
B2=0
backslash=2
straightup=3
fslash=2
equals=27
while lines < 14:
    if lines <= 4:
        print "B"*B2 + "\\"*backslash + "B"*B + "|"*straightup + "B" *B +"/"*fslash +"B"*B2
        B=B-1
        B2=B2+1
        lines=lines+1
    elif lines == 5:
        print "="*equals
        lines=lines+1
    elif lines ==6:
        print ""
        lines=lines+1
    elif lines == 7:
        print "="*equals
        lines=lines+1
    else:
        print "B"*B2 + "/"*fslash + "B"*B + "|"*straightup + "B"*B + "\ \"*backslash + "B"*B2
        B=B+1
        B2=B2-1
        lines = lines+1

The Union Jack --------^

Remove the space in the \\ brackets

Best I could do in ASCII. Next I'll try something else, probably Japan...

OK Here's Japan:

lines = 0
w=33
r=7
w2=13
while lines <= 15:
    if lines <=3:
        print "."*w
        lines=lines+1
    elif lines <= 6:
        print "."*w2 + "r"*r + "."*w2
        w2=w2-1
        r=r+2
        lines=lines+1
    elif lines <= 9:
        print "."*10 + "r"*13 + "."*10
        lines=lines+1
    elif lines <= 12:
        w2=w2+1
        r=r-2
        print "."*w2 + "r"*r + "."*w2
        lines = lines+1
    elif lines <= 15:
        print "."*w
        lines=lines+1

Hope you like it!

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.