Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41424
| X-Received | by 10.180.75.8 with SMTP id y8mr3528725wiv.1.1363616338661; Mon, 18 Mar 2013 07:18:58 -0700 (PDT) |
|---|---|
| X-Received | by 10.49.84.73 with SMTP id w9mr1197248qey.34.1363616337955; Mon, 18 Mar 2013 07:18:57 -0700 (PDT) |
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!87.79.20.101.MISMATCH!newsreader4.netcologne.de!news.netcologne.de!feeder1.cambriumusenet.nl!feed.tweaknews.nl!209.85.212.216.MISMATCH!19no7574722wij.1!news-out.google.com!g1ni68654wig.0!nntp.google.com!yu2no7632997wib.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Mon, 18 Mar 2013 07:18:57 -0700 (PDT) |
| In-Reply-To | <mailman.3444.1363614983.2939.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=70.188.179.16; posting-account=AvekzAoAAABj-TclKcOWQmXwA49MFPGX |
| NNTP-Posting-Host | 70.188.179.16 |
| References | <mailman.3444.1363614983.2939.python-list@python.org> |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <3dcc50c9-5909-4b10-9eb4-fd0cc5d98f35@googlegroups.com> (permalink) |
| Subject | Re: What are some other way to rewrite this if block? |
| From | "Yves S. Garret" <yoursurrogategod@gmail.com> |
| Injection-Date | Mon, 18 Mar 2013 14:18:58 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Xref | csiph.com comp.lang.python:41424 |
Show key headers only | View raw
On Monday, March 18, 2013 9:56:16 AM UTC-4, Santosh Kumar wrote: > 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. If you have a lot of conditions to check, you can't really get around it.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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