6 Replies - 4774 Views - Last Post: 01 April 2010 - 08:00 PM Rate Topic: -----

#1 mocqueanh   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 25-June 07

Division and Modulus operators in Python

Post icon  Posted 11 July 2007 - 12:58 AM

>>> 10/4
2
>>> -10/4
-3

Why is it ? I think -10/4 = -2

And now, the Modulus in Python:

>>> 10%4
2
>>> -10%4
2

The operator -10/4 has remainder is -2, not 2

Next:
>>> 10%-4
-2

The operator 10/-4 has remainer is 2, not 2

Next:
>>> 11%4
3
>>> -11%4
1
>>> 11%-4
-1


I cant understand this case.

Is This A Good Question/Topic? 0
  • +

Replies To: Division and Modulus operators in Python

#2 Xing   User is offline

  • D.I.C Addict
  • member icon

Reputation: 19
  • View blog
  • Posts: 725
  • Joined: 22-July 06

Re: Division and Modulus operators in Python

Posted 16 July 2007 - 10:47 PM

I think your question is already answered here
http://ubuntuforums....ad.php?t=498178
Was This Post Helpful? 0
  • +
  • -

#3 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 250
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Division and Modulus operators in Python

Posted 17 July 2007 - 12:53 PM

hahaha...same question on two forums :)
Was This Post Helpful? 0
  • +
  • -

#4 k.sangeeth   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 62
  • Joined: 27-July 07

Re: Division and Modulus operators in Python

Posted 31 July 2007 - 03:17 AM

Although I have been using python for last four months .. I never noticed this ..
very interesting though.
Was This Post Helpful? 0
  • +
  • -

#5 kuratkull   User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 01-May 07

Re: Division and Modulus operators in Python

Posted 27 August 2007 - 05:25 AM

A short a answer:

use:
10.0/4 :)
Was This Post Helpful? 0
  • +
  • -

#6 Guest_K.Kishore*


Reputation:

Re: Division and Modulus operators in Python

Posted 29 March 2010 - 11:43 PM

>>> 10%4
2
>>> -10%4
2

Yes, The operator -10/4 has remainder is -2
In this case you have to type in this way
>>> -(10%4)

Next:
>>> 11%4
3
>>> -11%4
1
>>> 11%-4
-1

In this, The remainder is
4 )11(3 , then you get remainder is -1
12

4 )-11 (3 , then you get remainder is 1
12
Was This Post Helpful? 0

#7 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2965
  • View blog
  • Posts: 11,222
  • Joined: 15-July 08

Re: Division and Modulus operators in Python

Posted 01 April 2010 - 08:00 PM

Thanks for your answer, but this topic is nearly 3 years old!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1