Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41415
| Date | 2013-03-18 19:26 +0530 |
|---|---|
| Subject | What are some other way to rewrite this if block? |
| From | Santosh Kumar <sntshkmr60@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3444.1363614983.2939.python-list@python.org> (permalink) |
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 | Next — 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