I have created a new terminal in a Jupyter notebook.
When I type 3 / 2
I get 1
How do I obtain 1.5
?
I have selected type code.
I have created a new terminal in a Jupyter notebook.
When I type 3 / 2
I get 1
How do I obtain 1.5
?
I have selected type code.
You need at least one of two operands to be floating point number. Your problem occurs as in Python 2 the default behaviour when dividing two int
is try to do the integer division (no decimals).
So try forcing them to be float numbers by typing explicitly the decimal part like 3.0 / 2
or 3 / 2.0
or even converting both sides 3.0 / 2.0
.
You're definitively not using Python 3 as you can see in this example:
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 3/2
1.5
>>>
Dividing 3 by 2 will definitively evaluate to 1.5. If you would want to have an integer division you'd need to use the operator //
instead of /
:
>>> 3//2
1
>>>
So check your Python version first before looking for any other reason why you don't get 1.5
!
Please note that Python 2 is outdated for about 11 years now. If you're using a Jupyter notebook with Python 2 there's likely something wrong with the Jupyter notebook installation.