Thursday, June 14, 2012

Reflection Journal for Programming 06

The Question (from http://bit.ly/KxmVcS) :





























The Code :

# 4 line version

for i in range(0,10,1):
    print (i*'#') + (22 - i*2) * ' ' + (i*'#')
for i in range(10,0,-1):
    print (i*'#') + (22 - i*2) * ' ' + (i*'#')


OR

# 5 line version

def hourglass(a,b,c):
    for i in range (a,b,c):
        print (i*'#') + (22 - i*2) * ' ' + (i*'#')

hourglass(0,10,1)
hourglass(10,0,-1)


Reflection : Managed to figure out how the pattern of the code should be after 10 minutes of screwing around with the codes.
I'm bad with visualizing such stuffs in my mind with program codes, hope next time don't have such troublesome question lol.


No comments:

Post a Comment