Code style query: multiple assignments in if/elif tree

Chris Angelico rosuav at gmail.com
Tue Apr 1 04:56:59 EDT 2014


On Tue, Apr 1, 2014 at 7:29 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Tue, Apr 1, 2014 at 1:59 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
>> Given that, I have to question your figures:
>>
>>> 177.211111333333
>>
>>> compared to 177.26527800000002 calculated the rough way. That's not bad,
>>> only about 5cm off! Effectively, your rough calculation was accurate to
>>> one decimal place.
>>
>> As I noted the rough way should be an underestimate, so I'm not sure
>> why it's an overestimate here.  That said, I don't see where either of
>> us made a mistake.
>
> And I realize now that this is also because the linear deceleration
> assumption doesn't match the average deceleration stated in the
> problem.  It actually decelerates faster and cuts under the t=1s and
> t=2s points in the velocity graph, and therefore is actually a
> slightly larger underestimate.

Okay... so... hmm.

I'm trying to wrap a fried brain around your post here, and I'm not
sure it covered it properly. It's like a tortilla with the meat
spilling out. (My analogies aren't much saner when I'm not brain
fried, trust me.)

The important part here is to work out exactly how fast we'll be going
at the end of two seconds of gentle braking (before the 0.85m/s/s bit
begins). If that velocity is exactly the initial speed minus 0.625
m/s/s, then the error won't accumulate, and it's just a slight
difference that's well within tolerance. But if that velocity is
higher or lower, then it's going to be significant; the initial speed
could be 111.1̅ m/s (line speed of 400 km/h), and at that speed, 0.1
m/s difference could make a visible difference to the distance
travelled (the difference between 111.0 and 111.1 m/s makes a 10m
difference in the distance to reach 90 km/h or 25 m/s). Although,
truth be told, that's probably still not *very* significant; it's 0.12
seconds of time difference.

The exact deceleration curve isn't significant; all that matters is
how far the train goes during that curve, and how much speed it loses.

ChrisA



More information about the Python-list mailing list