Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #55240
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Help with python functions? |
| Date | 2013-10-01 21:45 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <l2ffpk$618$2@dont-email.me> (permalink) |
| References | (3 earlier) <l1qsdl$f3k$1@dont-email.me> <5d5e5c4d-a79c-4b1a-b9da-ee2ad766ded8@googlegroups.com> <l1s8tj$4ob$1@dont-email.me> <l1spuh$4ob$4@dont-email.me> <1b025b07-3c9c-4390-80e5-8b5661f00d96@googlegroups.com> |
On Tue, 01 Oct 2013 10:53:26 -0700, kjakupak wrote:
> 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):
I suspect that this doesn't work properly for all cases of from_unit,
to_unit.
As a general case:
def temp ( T, u1, u2 ):
# from and to units the same, return T unchanged
# else use a conversion table
ct = { (a, b):lambda x: formula, .... }
return ct[ (u1, u2 ) ]( T )
Note you may need to build in case independence!
> # Question 1.b
> def comp(T1, u1, T2, u2):
You completely missed the point of my earlier posts, and I suspect the
reason both these questions were included.
Firstly, consider that if temp (from q1a) works properly you can use temp
to convert the units of T2 to the units of T1, by calling:
temp( T2, u2, u1 )
q1b can be implemented in one line if temp from q1a works properly!
> # Question 2
> def P(p_0, t, i):
> Amount = P(1 + (i/100))
> return P(1 + (t * i/12))
First calculate the annual interest as 1 + fraction where fraction is
interest % / 100
The calculate the compounded interest as annual ^ years
Finally multiply the compounded interest by the principal
Mathematically:
principal * ( ( 1 + ( period_interest_% / 100 ) ) ^ periods )
Again, this should be possible as a single line function. All you have to
do is turn the math into python code.
--
Denis McMahon, denismfmcmahon@gmail.com
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Help with python functions? kjakupak@gmail.com - 2013-09-23 05:57 -0700
Re: Help with python functions? Roy Smith <roy@panix.com> - 2013-09-23 09:11 -0400
Re: Help with python functions? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-23 13:56 +0000
Re: Help with python functions? kjakupak@gmail.com - 2013-09-23 15:32 -0700
Re: Help with python functions? Terry Reedy <tjreedy@udel.edu> - 2013-09-23 18:48 -0400
Re: Help with python functions? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-24 03:08 +0000
Re: Help with python functions? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-24 03:17 +0000
Re: Help with python functions? giacomo boffi <pecore@pascolo.net> - 2013-09-24 18:53 +0200
Re: Help with python functions? MRAB <python@mrabarnett.plus.com> - 2013-09-24 18:18 +0100
Re: Help with python functions? kjakupak@gmail.com - 2013-09-23 15:55 -0700
Re: Help with python functions? Dave Angel <davea@davea.name> - 2013-09-24 00:07 +0000
Re: Help with python functions? kjakupak@gmail.com - 2013-09-23 18:23 -0700
Re: Help with python functions? Dave Angel <davea@davea.name> - 2013-09-24 03:52 +0000
Re: Help with python functions? Denis McMahon <denismfmcmahon@gmail.com> - 2013-09-24 02:12 +0000
Re: Help with python functions? kjakupak@gmail.com - 2013-09-23 19:40 -0700
Re: Help with python functions? Denis McMahon <denismfmcmahon@gmail.com> - 2013-09-24 14:51 +0000
Re: Help with python functions? Denis McMahon <denismfmcmahon@gmail.com> - 2013-09-24 19:42 +0000
Re: Help with python functions? kjakupak@gmail.com - 2013-10-01 10:53 -0700
Re: Help with python functions? random832@fastmail.us - 2013-10-01 15:02 -0400
Re: Help with python functions? Denis McMahon <denismfmcmahon@gmail.com> - 2013-10-01 21:45 +0000
Re: Help with python functions? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-10-01 19:19 -0400
Re: Help with python functions? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-24 03:15 +0000
Re: Help with python functions? Denis McMahon <denismfmcmahon@gmail.com> - 2013-09-24 15:02 +0000
csiph-web