Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Boolean result of divmod

Reply
Thread Tools

Boolean result of divmod

 
 
Gnarlodious
Guest
Posts: n/a
 
      06-21-2011
What is the easiest way to get the first number as boolean?

divmod(99.6, 30.1)

Or do I have to say:

flote, rem=divmod(99.6, 30.1)
bool(flote)

-- Gnarlie
 
Reply With Quote
 
 
 
 
Chris Torek
Guest
Posts: n/a
 
      06-21-2011
In article <261fc85a-ca6b-4520-93ed->
Gnarlodious <> wrote:
>What is the easiest way to get the first number as boolean?
>
>divmod(99.6, 30.1)


divmod returns a 2-tuple:

>>> divmod(99.6,30.1)

(3.0, 9.2999999999999901)

Therefore, you can subscript the return value to get either
element:

>>> divmod(99.6,30.1)[0]

3.0

Thus, you can call bool() on the subscripted value to convert
this to True-if-not-zero False-if-zero:

>>> bool(divmod(99.6,30.1)[0])

True
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: gmail (figure it out) http://web.torek.net/torek/index.html
 
Reply With Quote
 
 
 
 
MRAB
Guest
Posts: n/a
 
      06-21-2011
On 21/06/2011 01:28, Gnarlodious wrote:
> What is the easiest way to get the first number as boolean?
>
> divmod(99.6, 30.1)
>
> Or do I have to say:
>
> flote, rem=divmod(99.6, 30.1)
> bool(flote)
>

divmod returns a tuple, so:

bool(divmod(99.6, 30.1)[0])
 
Reply With Quote
 
Terry Reedy
Guest
Posts: n/a
 
      06-21-2011
On 6/20/2011 8:28 PM, Gnarlodious wrote:
> What is the easiest way to get the first number as boolean?
>
> divmod(99.6, 30.1)
>
> Or do I have to say:
>
> flote, rem=divmod(99.6, 30.1)
> bool(flote)


divmod(x,y) == x//y, x%y

so bool(x//y)

--
Terry Jan Reedy

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
When is divmod(a,b)[0] == floor(a/b)-1 ? kj Python 3 09-27-2009 06:51 AM
Measure class, precision, significant digits, and divmod() Ethan Furman Python 3 07-16-2008 04:29 PM
difference between 'boolean' and 'java.lang.Boolean' J Leonard Java 4 01-19-2008 02:56 AM
Bug: Numeric#divmod calculates wrongly Dirk Traulsen Ruby 11 10-15-2007 12:43 PM
1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds Michael Tan Ruby 32 07-21-2005 03:23 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57