print 0.5 * ((2**4)/(4)+(2**-2)/(-2)-(1/4)-(1/-2)) # fractions present! because of the 0.5? print 1 / 2 * ((2**4)/(4)+(2**-2)/(-2)-(1/4)-(1/-2)) # apparently, this appears to be the case print 1/2 print 1/2+1/2 print 0.5+0.25 print 1/3+1/3 print 4/2 print 0.5/2 # decimals are treated as floating-point numbers, the natural way in which numbers are stored on the computer # these numbers are written in scientific notation (hence decimals being treated as floats) # without a decimal point, regular division occurs; "/" results in truncation of all numbers that aren't whole # doesn't apply only to division either (theoretically); int results in int while float results in float # in order to not get a truncated number, do the following: print 1.0/2.0 #or print 1.0/2 #or print 1/2.0
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question