[Tutor] Convert doesn't work... I'm stumped
jfouhy at paradise.net.nz
jfouhy at paradise.net.nz
Wed Mar 16 05:12:33 CET 2005
Quoting "Jacob S." <keridee at jayco.net>:
> But, I digress--to the problem...
> If I call convert(3,'ft','yd'), I should get Decimal("1")
> instead, I get Decimal("1.195990046301080256481500617")
At the risk of being blindingly obvious ---
ft[0] is lambda x:381*x/1250
yd[1] is lambda x:1250/(1143*x)
ft[0](3) is 3*381/1250 which is .9144 (according to bc)
yd[1](.9144) is 1240/(1143*.9144) which is 1.19599...
I think you need to check your conversion equations, rather than your code...
> x -ft- 12 -in- 2.54 -cm- m
> def dic['ft'][0](x) = ---- X -------- X ----------- X ------- =
> 12*2.54*x/100 = 12*254*x/10000 = 381*x/1250
> -ft- -in-
> 100 -cm-
I guess this is meant to be some algebra. Unfortunately, I can't make sense of
it --- do you use a proportional font?
Anyway:
yd(x) := 1250/(1143*x)
ft(x) := 381*x/1250
You are computing yd(ft(x)), which is:
1250/(1143*(381*x/1250))
which works out as:
yd(ft(x)) := 1250**2/(1143*381*x)
HTH.
--
John.
More information about the Tutor
mailing list