Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Looking for a slick way to classify relationship between twonumbers, without tons of if/else
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Paul Rubin, post: 3895408"] Didn't we just have a huge thread about that? Using a special null value is often (not always) a code smell. But anyway (untested): def compare(a,b): if a is None and b is None: # I'm guessing you meant this return "No data" if a == b: return "Stayed the same" if a != 0 else "Never had" elif a < b: return "gained" else: # we know here that a > b return "Lost some" if b > 0 else "Lost all" I don't know what you intended to do in the case where exactly one of (a,b) is None, so I'll leave that to you. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Looking for a slick way to classify relationship between twonumbers, without tons of if/else
Top