You’re using Python 2.x, where integer divisions will truncate instead of becoming a floating point number.
>>> 1 / 2 0
You should make one of them a float
:
>>> float(10 - 20) / (100 - 10) -0.1111111111111111
or from __future__ import division
, which the forces /
to adopt Python 3.x’s behavior that always returns a float.
>>> from __future__ import division >>> (10 - 20) / (100 - 10) -0.1111111111111111
Related Posts:
- Safest way to convert float to integer in python?
- How can I use “e” (Euler’s number) and power operation in python 2.7
- How can I use “e” (Euler’s number) and power operation in python 2.7
- What does != do/mean in python
- Clamping floating numbers in Python?
- How to round a number to significant figures in Python
- How to perform bilinear interpolation in Python
- Inverse of Tan in python (tan-1)
- Inverse Cosine in Python
- Converting bytes to megabytes
- What is the difference between rw+ and r+
- Converting 3D polar coordinates to cartesian coordinates
- What is the C++ function to raise a number to a power?
- Unfamiliar symbol in algorithm: what does ∀ mean? [closed]
- Python Math – TypeError: ‘NoneType’ object is not subscriptable
- numpy max vs amax vs maximum
- What is the difference between range and xrange functions in Python 2.X?
- raw_input function in Python
- Integer division in Java [duplicate]
- What does the ^ (XOR) operator do? [duplicate]
- What do these operators mean (** , ^ , %, //)? [closed]
- What do these operators mean (** , ^ , %, //)? [closed]
- syntaxerror: “unexpected character after line continuation character in python” math
- syntaxerror: “unexpected character after line continuation character in python” math
- TypeError: ‘float’ object is not callable
- Calculating a 2D Vector’s Cross Product
- write() versus writelines() and concatenated strings
- Error: all the input array dimensions except for the concatenation axis must match exactly
- syntaxerror: “unexpected character after line continuation character in python” math
- No module named MySQLdb
- No module named MySQLdb
- Java Round up Any Number
- How do you use subprocess.check_output() in Python?
- How do order of operations go on Python?
- JavaScript exponents
- How to perform an integer division, and separately get the remainder, in JavaScript?
- What does numpy.gradient do?
- How to perform an integer division, and separately get the remainder, in JavaScript?
- How can I concatenate str and int objects?
- Python: OverflowError: math range error
- How can I use numpy.correlate to do autocorrelation?
- How can I convert radians to degrees with Python?
- Infinite integer in Python
- Lua replacement for the % operator
- How do you find the rightmost digit of an integer?
- How do you use subprocess.check_output() in Python?
- Overflow / math range error for log or exp
- How do I find the distance between two points?
- What is the fastest factorial function in JavaScript?
- How can I check for NaN values?
- Python – how to use the constant e^
- What does `<>` mean in Python?
- log2 in python math module
- What is the difference between ‘/’ and ‘//’ when used for division?
- How can I check for NaN values?
- Python – ‘ascii’ codec can’t decode byte
- How to return dictionary keys as a list in Python?
- UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\xa0′ in position 20: ordinal not in range(128)
- What is the most efficient way to calculate the least common multiple of two integers?
- What is the most efficient way to calculate the least common multiple of two integers?
- How can I check if two segments intersect?
- How can I convert a number from base 8 to base 10?
- What is the maximum number of edges in a directed graph with n nodes?
- Using multiple variables in a for loop in Python
- How to save decimal in java
- Probability of hash collision
- python math domain errors in math.log function
- How to fix ‘RuntimeWarning: divide by zero encountered in double_scalars’
- Is there a math nCr function in python?
- Round *UP* to the nearest 100 in SQL Server
- How do I compute derivative using Numpy?
- TypeError: super() takes at least 1 argument (0 given) error is specific to any python version?
- Is there a math nCr function in python? [duplicate]
- What exactly do “u” and “r” string flags do, and what are raw string literals?
- Determine if 2 lists have the same elements, regardless of order? [duplicate]
- Rotating a Vector in 3D Space
- Using print() (the function version) in Python2.x
- Function to determine if two numbers are nearly equal when rounded to n significant decimal digits
- How to read a CSV file from a URL with Python?
- Mathematica matrix diagonalization
- How to import a csv-file into a data array?
- How do I upgrade the Python installation in Windows 10?
- Selecting multiple columns in a Pandas dataframe
- DataFrame constructor not properly called
- How does functools partial do what it does?
- ctypes – Beginner
- Keras, how do I predict after I trained a model?
- How do I find out my PYTHONPATH using Python?
- ValueError: could not broadcast input array from shape (224,224,3) into shape (224,224)
- Overflow Error in Python’s numpy.exp function
- Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock
- Check if two unordered lists are equal
- How do I change the figure size with subplots?
- Clear terminal in Python [duplicate]
- How to read pickle file?
- Running a Python script from PHP
- ‘instancemethod’ object has no attribute ‘__getitem__’ with class variables
- Python/Scikit-Learn – Can’t handle mix of multiclass and continuous
- How to search for a string in text files?
- TypeError: ‘zip’ object is not subscriptable