Help with python functions?

kjakupak at gmail.com kjakupak at gmail.com
Tue Oct 1 13:53:26 EDT 2013


I ended up with these. I know they're only like half right...
I was wondering if any of you had to do this, what would you end up with?

# Question 1.a
def temp(T, from_unit, to_unit):
    if from_unit == 'C' or from_unit == 'c':
        return 32 + (9/5)*T
    elif from_unit == 'K' or from_unit == 'k':
        return T + 273.15
    elif from_unit == 'F' or from_unit == 'f':
        return (5/9)*(T - 32)
    else:
        return to_unit

# Question 1.b
def comp(T1, u1, T2, u2):
    if u1 != u2:
        T1 = temp(T1, u1)
    elif T2 > T1:
        return -1
    elif T1 > T2:
        return 1
    else:
        return 0

# Question 2
def P(p_0, t, i):
    Amount = P(1 + (i/100))
    return P(1 + (t * i/12))



More information about the Python-list mailing list