"""
Solutions to Assignment 1

Some questions have more than one solution.  Try to understand each of them.
These samples also illustrate the use of docstring comments, like this one,
for documenting modules and functions
"""

from __future__ import division


##########################################################
# Question 1
##########################################################
def lbs2kg(w):
    """Convert pounds to kilograms"""
    return 0.453592*w

##########################################################
# Question 2
##########################################################
def ftin2cm(f,i):
    """Convert feet to centimetres"""
    return (12*f+i)*2.54

##########################################################
# Question 3
##########################################################
def format_name1(fn, ln, ap):
    """Format a name like 'Cooper, Sheldon, Dr.'"""
    return "%s, %s, %s" % (ln, fn, ap)

##########################################################
# Question 4
##########################################################
def format_name2(fn, ln, ap):
    """Format a name like 'Dr. Sheldon Cooper'"""
    return "%s %s %s" % (ap, fn, ln)

##########################################################
# Question 5
##########################################################
def limerick_maker():
    """Generate a funny customized limerick"""
    name = raw_input("Enter your first name: ")
    city = raw_input("Enter your city of birth: ")
    print "%s had funny funny hair" % name
    print "With tons and tons to spare" 
    print "%s's clippings made a wig" % name 
    print "It was very big" 
    print "And caused the townsfolk of %s to stare" % city

##########################################################
# Question 6
##########################################################
def bmi(w,h):
    """Compute the BMI given a weight and height

    Return the BMI of an individual whose weighs w pounds and
    is h inches tall.  Details on BMI calculations can be found
    here: http://en.wikipedia.org/wiki/Body_mass_index
    """
    return (w/(h**2))*703

##########################################################
# Question 7
##########################################################
def in2ftin(i):
    """Convert inches to feet,inches"""
    return i//12, i%12

##########################################################
# Question 8
##########################################################
def ft2ftin(f):
    """Convert feet to feet,inches"""
    return (int(f), (f*12)%12)

##########################################################
# Question 9
##########################################################
def bmi_calculator():
    """A simple application for reporting a user's BMI information"""
    app = raw_input("Enter you appelation (Mr., Mrs., Dr.,...): ")
    fn = raw_input("Enter your first name: ")
    ln = raw_input("Enter your last name: ")
    h = int(raw_input("Enter your height in inches: "))
    w = int(raw_input("Enter your weight in pounds: "))
    print "BMI Record for %s %s %s:" % (app, fn, ln)
    print "Subject is %d feet %d inches tall" % in2ftin(h), 
    print "and weighs %d pounds" % w
    print "Subject's BMI is %f" % bmi(w,h)

##########################################################
# Question 10
##########################################################
# This one requires some reading ahead, since it requires iteration
def stars(n):
    """Return a string consisting of n '*' characters"""
    s = ""
    for i in xrange(0,n):
        s += "*"
    return s

# This solution requires discovering that the multiplication operator
# does what we want when one argument is a string and the other is an
# integer
def stars2(n):
    """Return a string consisting of n '*' characters"""
    return n * '*'

