Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #69473

Re: Code style query: multiple assignments in if/elif tree

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.120
X-Spam-Level *
X-Spam-Evidence '*H*': 0.78; '*S*': 0.02; 'say,': 0.05; 'affected': 0.07; 'subject:query': 0.07; 'assuming': 0.09; 'curve': 0.09; 'here?': 0.09; 'integral': 0.09; '(within': 0.16; 'curve.': 0.16; 'incorrect': 0.16; 'segment': 0.16; 'wrote:': 0.18; 'comfortable': 0.22; '31,': 0.24; 'stopping': 0.24; 'subject:Code': 0.24; 'initial': 0.24; 'mon,': 0.24; 'subject:/': 0.26; 'header:In- Reply-To:1': 0.27; 'chris': 0.29; 'needed.': 0.30; 'reaches': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '(which': 0.31; "d'aprano": 0.31; 'second,': 0.31; 'steven': 0.31; 'probably': 0.32; 'quite': 0.32; 'actual': 0.34; '(2)': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'next': 0.36; 'operating': 0.37; 'two': 0.37; '(3)': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'called': 0.40; 'skip:u 10': 0.60; 'easy': 0.60; 'first': 0.61; 'connecting': 0.64; 'more': 0.64; 'distance': 0.65; 'modeling': 0.65; 'between': 0.67; 'mar': 0.68; 'increase': 0.74; 'distinctive': 0.84; 'heh.': 0.84; 'points,': 0.84; 'traveled': 0.84; 'distance.': 0.91; 'increases': 0.91; 'stretch': 0.91; 'average': 0.93; 'comfort': 0.96; 'picture': 0.97
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=TKIyGmRGgacPdlBYY8erW3+QT+ErIDxE2VPYxEAO0JQ=; b=S8xEz7HB0BaOLl83lRXgvfAugyIX4USpoNrgYFjqkBeICtBbgO8QiOoCUY5q2V2JJQ 03711FEab43+Z2uNYdg9AfQIcnyYdWEonI+nhybagGQkuTbeCQW+tqkpvDCPKt6eFS9g XWdDTA7y5Dhgz/oOhU/RuasmsXLVLuSpeHawlx/aKJTolDvl1WxZx0CoU5xgSSUYQ98N c1T+tsaMA6yPWe+amyGocp4aK0rNcHodS/y5tsvz41+xBfZlqoQ1MI/0H9b5rKYIit+X 6ZLMcKwHZL0DMvwokBrZr8TL784tGt31SOwTfFa69F6ygZwXKOpKRQfRe5N82sc1CycJ 8zQw==
X-Received by 10.66.41.106 with SMTP id e10mr13293482pal.109.1396332820771; Mon, 31 Mar 2014 23:13:40 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <CAPTjJmoqdHtbyTKLf0b6c5Xy8Wx_NQVvFenB-S0hE3dHO15uzA@mail.gmail.com>
References <mailman.8744.1396276875.18130.python-list@python.org> <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> <CAPTjJmoqdHtbyTKLf0b6c5Xy8Wx_NQVvFenB-S0hE3dHO15uzA@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Tue, 1 Apr 2014 00:13:00 -0600
Subject Re: Code style query: multiple assignments in if/elif tree
To Python <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.8770.1396332824.18130.python-list@python.org> (permalink)
Lines 36
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1396332824 news.xs4all.nl 2904 [2001:888:2000:d::a6]:36732
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:69473

Show key headers only | View raw


On Mon, Mar 31, 2014 at 11:01 PM, Chris Angelico <rosuav@gmail.com> wrote:
> On Tue, Apr 1, 2014 at 3:26 PM, Steven D'Aprano <steve@pearwood.info> wrote:
>> The scenario you describe has (effectively) infinite rate-of-change-of-
>> acceleration, often called "jerk". (A jerk is a rapid change in
>> acceleration.) Human comfort is (within reasonable limits) more affected
>> by jerk than acceleration. The passengers will feel three quite
>> distinctive jerks, one when the brakes are first applied (which is
>> probably reasonable), then one at 1s, then again at 2s. That's not
>> comfortable by any stretch of the imagination.
>
> It actually is a smooth increase in deceleration, but I'm operating
> the simulator on a 1s period, so it's actually an average across the
> first second, and an average across the next second...

Then your computation is incorrect and will systematically
underestimate the stopping distance.  Assuming for simplicity that the
acceleration actually increases linearly until it reaches maximum,
picture the velocity graph between, say, t=0 and t=1s.  You are
modeling it as a straight line segment.  However, it would actually be
part of a quadratic curve connecting the same points, convex upwards.
The line segment is short-cutting the curve between the two points.
The distance traveled is the integral of the curve, and it is easy to
see that the integral of the line segment is less than the integral of
the actual curve.


>> (1) v = u + at
>> (2) s = 1/2(u + v)t
>> (3) s = ut + 1/2(at^2)
>> (4) v^2 = u^2 + 2as
>>
>> Only (1) and (3) are needed.
>
> Okay, what's u here? Heh.

u is the initial velocity; v is the velocity after accelerating at a for time t.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 01:33 +1100
  Re: Code style query: multiple assignments in if/elif tree Marko Rauhamaa <marko@pacujo.net> - 2014-03-31 18:40 +0300
    Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 03:03 +1100
      Re: Code style query: multiple assignments in if/elif tree Rustom Mody <rustompmody@gmail.com> - 2014-03-31 09:20 -0700
        Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 03:29 +1100
          Re: Code style query: multiple assignments in if/elif tree "Rhodri James" <rhodri@wildebst.org.uk> - 2014-03-31 21:31 +0100
    Re: Code style query: multiple assignments in if/elif tree Ned Batchelder <ned@nedbatchelder.com> - 2014-03-31 17:42 -0400
    Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 09:50 +1100
    Re: Code style query: multiple assignments in if/elif tree Ben Finney <ben+python@benfinney.id.au> - 2014-04-01 09:57 +1100
    Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 10:12 +1100
      Re: Code style query: multiple assignments in if/elif tree Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-04-01 00:57 +0000
    Re: Code style query: multiple assignments in if/elif tree Ethan Furman <ethan@stoneleaf.us> - 2014-03-31 17:30 -0700
  Re: Code style query: multiple assignments in if/elif tree Steven D'Aprano <steve@pearwood.info> - 2014-04-01 04:26 +0000
    Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 16:01 +1100
      Re: Code style query: multiple assignments in if/elif tree Steven D'Aprano <steve@pearwood.info> - 2014-04-01 07:20 +0000
        Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 18:35 +1100
          Re: Code style query: multiple assignments in if/elif tree Steven D'Aprano <steve@pearwood.info> - 2014-04-01 08:07 +0000
            Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 19:12 +1100
        Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 02:18 -0600
        Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 02:24 -0600
    Re: Code style query: multiple assignments in if/elif tree Rustom Mody <rustompmody@gmail.com> - 2014-03-31 22:45 -0700
      Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 02:05 -0400
      Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 00:28 -0600
    Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 00:13 -0600
    Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 02:24 -0400
    Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 00:39 -0600
    Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 17:55 +1100
      Re: Code style query: multiple assignments in if/elif tree Steven D'Aprano <steve@pearwood.info> - 2014-04-01 07:29 +0000
        Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 18:49 +1100
        Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 02:29 -0600
        Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 19:56 +1100
    Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 03:21 -0400
    Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 18:26 +1100
    Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 03:34 -0400
    Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 03:39 -0400
    Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 03:46 -0400
    Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 02:55 -0600

csiph-web