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


Groups > comp.lang.python > #41415

What are some other way to rewrite this if block?

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <sntshkmr60@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.027
X-Spam-Evidence '*H*': 0.95; '*S*': 0.01; 'else:': 0.03; 'elif': 0.04; 'welcome.': 0.07; 'def': 0.10; "range'": 0.16; "time'": 0.16; 'script': 0.24; 'message-id:@mail.gmail.com': 0.27; 'subject:other': 0.29; 'subject:some': 0.29; 'to:addr:python- list': 0.33; 'code:': 0.33; 'received:google.com': 0.34; 'subject:?': 0.35; 'skip:p 20': 0.36; 'to:addr:python.org': 0.39; 'here': 0.65; 'forward': 0.66; 'subject:this': 0.84; 'transport,': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=RmC+5rkpjLuubgACTLRRBbz9NqOPG4T6bIuE7bRUpII=; b=F+nWSf6JhdObiP2XVloNt4l2JPD0koLsNcUj9h/DI5r1eXOOztWlLfZKJpD1Zn+qVN eZqhCfEN0f79Zqo7N7eKsZb4tELkRIVc4aogAIfC4CPmD2fXXafyJTcALj7TdQvq3hKI IopMkkL+XLOO8sAB+ml7AzvmhKs97l4+3J3eXmh4jP7BPRNpbAHdOX7mot8TCKSVQySK SCw3whtl5w7dW2u2/pkrpZbjBDWWv4JWwmL6DHkFwjTYPqhNNw6PNRFGf/qXtNkdA+Kl A9fcBvedCqpXGJ0x/X6Nt5y4WOWM+1XYlDggjgCPEGIh4WWZoEIwwoe5+yhC+HJVBfKv WivA==
MIME-Version 1.0
X-Received by 10.152.110.6 with SMTP id hw6mr14828787lab.43.1363614976165; Mon, 18 Mar 2013 06:56:16 -0700 (PDT)
Date Mon, 18 Mar 2013 19:26:16 +0530
Subject What are some other way to rewrite this if block?
From Santosh Kumar <sntshkmr60@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=UTF-8
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 <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3444.1363614983.2939.python-list@python.org> (permalink)
Lines 20
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1363614983 news.xs4all.nl 6951 [2001:888:2000:d::a6]:38788
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:41415

Show key headers only | View raw


This simple script is about a public transport, here is the code:

def report_status(should_be_on, came_on):
    if should_be_on < 0.0 or should_be_on > 24.0 or came_on < 0.0 or
came_on > 24.0:
        return 'time not in range'
    elif should_be_on == came_on:
        return 'on time'
    elif should_be_on > came_on:
        return 'early'
    elif should_be_on < came_on:
        return 'delayed'
    else:
        return 'something might be wrong'

print(report_status(123, 12.0))

I am looking forward of make the line starting with `if` short.

Any tips are welcome.

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


Thread

What are some other way to rewrite this if block? Santosh Kumar <sntshkmr60@gmail.com> - 2013-03-18 19:26 +0530
  Re: What are some other way to rewrite this if block? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-03-18 16:10 +0200
    Re: What are some other way to rewrite this if block? Duncan Booth <duncan.booth@invalid.invalid> - 2013-03-18 14:43 +0000
      Re: What are some other way to rewrite this if block? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-03-18 16:53 +0200
  Re: What are some other way to rewrite this if block? "Yves S. Garret" <yoursurrogategod@gmail.com> - 2013-03-18 07:18 -0700
  Re: What are some other way to rewrite this if block? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-18 15:10 +0000
    Re: What are some other way to rewrite this if block? Chris Angelico <rosuav@gmail.com> - 2013-03-19 02:24 +1100

csiph-web