Tuesday, June 5, 2012

Tuesday, 05th June 2012 [Holidays de Programming Homework]

Almost forgot to do my programming homework lol
Slacked too much during this 2 weeks holidays x.x


Lazy study for UT, think will just briefly go through what I learnt so far when I got the mood.

Managed to complete my programming homework within 30 minutes, but also spent 15 minutes finding my printer's driver.
I lazy write out my codes on paper, might as well just print them out.


=====================================================================

Q1 - Writing function

def handlebars (X1,X2):
    return "--" + X1 + "--" + X2 + "--"


print handlebars('me','you')
print handlebars('love','hate')


Q2 - Printing Area of Rectangle

def area (width, height):
    area = width * height
    return area


print area(5,6)

Q3 - Returning Area of Rectangle

def area (width, height):
    area = width * height
    return area


print area(5,6)

Q4 - More about areas

def cube(x):
    area = x * x
    return area


def rect(x,y):
    area = x * y
    return area


print rect(35,50) - cube(10)

I should use return value when calculating and print value when obtained result

Q5 - Function : Bigger number

def big(x,y):
    if (x > y) :
        return x
    elif (y > x):
        return y
    else :
        return "Both values are equal"


print big(10,30)
print big(-10,-30)


Q6 - Buffet Price

def getPrice(x,y):
    if(x == 'male' and y >= 12):
        return 20
    elif (x == 'male' and y < 12):
        return 12

    elif (x == 'female'and y >= 12):
        return 18
    elif (x == 'female' and y < 12):
        return 10


print getPrice("male", 15)
print getPrice("male", 10)


Q7 - Total Buffet Price

def getPrice(x,y):
    if(x == 'male' and y >= 12):
        return 20
    elif (x == 'male' and y < 12):
        return 12
    elif (x == 'female'and y >= 12):
        return 18
    elif (x == 'female' and y < 12):
       return 10


def totalPrice():
    peter = getPrice("male", 42)
    mary = getPrice("female", 42)
    alan = getPrice("male", 11)
    john = getPrice("male", 10)


    totalprice = peter + mary + alan + john
    return totalprice
print "The total price for a family outing is $" + `totalPrice()`

=====================================================================
Easy to type la, but I really hate writing everything out on my paper.
My handwriting sucks, why bother writing something that I can't recognize lol


Gonna use this blog to record what I learnt so far too, maybe summarize or make notes.

Pizza~

# Update : Edited on Thursday, 21th June 2012


Tuesday, 05th June 2012 (3 am, early morning post)

After some consideration, I think I'll resume my blogging.
I know my blog kept on pause & resume, but this is how I blog.

If you ask me why?
This is my blog, I do it my way.
There're also things that I can't blog out, or else other people will die lol

I think I will just blog about daily life stuffs, example things I need to remember or take notes of. I know I have a bad memory.