Questions tagged [divmod]

Returns an array containing the quotient and modulus obtained by dividing num by numeric.

Returns an array containing the quotient and modulus obtained by dividing num by numeric.

If q, r = x.divmod(y), then

q = floor(x/y)
x = q*y+r

The table below displays the difference between div, divmod, module and remainder methods is displayed below:

enter image description here

Examples:

11.divmod(3)         #=> [3, 2]
11.divmod(-3)        #=> [-4, -1]
11.divmod(3.5)       #=> [3, 0.5]
(-11).divmod(3.5)    #=> [-4, 3.0]
(11.5).divmod(3.5)   #=> [3, 1.0]

Official documentation

20 questions
0
votes
1 answer

An elegant one-line solution to extract data from Nested Tuples from divmod

assuming the following code: from datetime import datetime start_time = datetime.now() end_time = datetime.now() delta = end_time - start_time delta_ms = delta.microseconds what is the most elegant way to simplify the conversion of the timedelta…
Alexander McFarlane
  • 10,643
  • 9
  • 59
  • 100
-1
votes
1 answer

Python: How to use values from divmod in a subsequent subtraction

how do I include the result of a divmod division into a simple subtraction without facing: TypeError: unsupported operand type(s) for -: 'int' and 'tuple'? Here my code (written in Python): def discount(price, quantity): if (price > 100): …
Jakob
  • 195
  • 4
  • 12
-1
votes
1 answer

Error with divmod

Trying to run some code. Get this error when I do. I thought I had all the necessary dependencies installed, but still getting this error. linux; GNU C++ version 4.8.1; Boost_105300; UHD_003.007.000-133-g6bd9fed2 Traceback (most recent call…
-2
votes
2 answers

Practical Application of divmod() function in python, or how can we use divmod() other than just calculating / and %?

I just want to know how can we use divmod() function for some practical application other than just calculating / and %. I want to know if yes, then how can we use divmod function to prove if a number is prime or not. This would be a perfect…
-3
votes
1 answer

How can I make function print more results?

so I've been for a couple of hours now trying to do this test and I wanted to produce a very concatenated way to my result using a Tuple and the divmod function, and I finally got to a solution.. But I can't understand why it only prints 1 result…
Jacques
  • 1
  • 3
1
2