Code style query: multiple assignments in if/elif tree

Chris Angelico rosuav at gmail.com
Tue Apr 1 03:49:43 EDT 2014


On Tue, Apr 1, 2014 at 6:29 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>> Okay. I never studied calculus, so this is beyond my expertise. Is this
>> going to make a majorly significant difference to the end result?
>
> I thought that there was a chance that there might be, but it turns out,
> not so much. There is a difference, but for the purposes of the
> simulation it probably doesn't matter. If you were trying to land a
> spacecraft on Mars, that's a different story...

I'm liking the idea of pretending it's linear acceleration. Our error
in the system is:

1) Distances are accurate to one meter at absolute best; and I
wouldn't guarantee that they're even that accurate.
2) The simulation will apply the brakes at some exact number of
seconds past its origin.
3) A human driver might well apply the brakes a couple of seconds too
soon, and then cruise at the curve's speed for a short distance before
actually reaching the curve.
4) A human driver might also apply the brakes too _late_, and there
are tolerances built into the curve speed limits to cater for this.
The train would rock a bit more than is desired, but it won't
instantly derail if it hits a 90km/h curve at 91km/h (which is how the
simulator treats it).

Add all that up, and the end result is unlikely to be accurate to
better than ten seconds - and that's being generous. Ultimately, this
would be for drawing up projected timetables, so it's not going to be
used at more than one-minute accuracy; although comparing two proposed
routes might technically make use of more accuracy than that ("we
could go around to the left of this, or to the right of it; which
would be the faster route?" "This one, by thirty seconds"), any
difference of less than a minute would really have to be called
"practically equal".

By the way, line speed (the maximum safe speed on straight track) is
400km/h, so your estimates involving a 320km/h bullet train are in the
right ballpark. Curves could be practically any speed between zero and
that, although one would hope there aren't any Kooyong Stations on the
route! (Just up [1] of the station [2] is a tram crossing, which for
decades has been so bumpy and messy that trains had to slow down to
about 10 or 20 kays to get through safely.)

ChrisA
[1] https://en.wikipedia.org/wiki/Rail_directions#United_Kingdom
[2] https://en.wikipedia.org/wiki/Kooyong_railway_station



More information about the Python-list mailing list