Welcome to Dream.In.Code
Become an Expert!

Join 149,507 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,332 people online right now. Registration is fast and FREE... Join Now!




Division and Modulus operators in Python

 
Reply to this topicStart new topic

Division and Modulus operators in Python

mocqueanh
10 Jul, 2007 - 11:58 PM
Post #1

New D.I.C Head
*

Joined: 25 Jun, 2007
Posts: 1


My Contributions
>>> 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.


User is offlineProfile CardPM
+Quote Post

Xing
RE: Division And Modulus Operators In Python
16 Jul, 2007 - 09:47 PM
Post #2

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 4 times
Dream Kudos: 1575
My Contributions
I think your question is already answered here
http://ubuntuforums.org/showthread.php?t=498178
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Division And Modulus Operators In Python
17 Jul, 2007 - 11:53 AM
Post #3

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,349



Thanked: 51 times
Dream Kudos: 25
My Contributions
hahaha...same question on two forums smile.gif
User is online!Profile CardPM
+Quote Post

k.sangeeth
RE: Division And Modulus Operators In Python
31 Jul, 2007 - 02:17 AM
Post #4

D.I.C Head
**

Joined: 27 Jul, 2007
Posts: 61


My Contributions
Although I have been using python for last four months .. I never noticed this ..
very interesting though.
User is offlineProfile CardPM
+Quote Post

kuratkull
RE: Division And Modulus Operators In Python
27 Aug, 2007 - 04:25 AM
Post #5

New D.I.C Head
Group Icon

Joined: 1 May, 2007
Posts: 6


Dream Kudos: 250
My Contributions
A short a answer:

use:
10.0/4 smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 07:15PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month