The volume of a sphere with radius r is 4/3 π r3. What is the volume of a sphere with radius 5? Hint: 392.6 is wrong!
print (((4/3.0) * 3.14) * 5**3)
It gave me this
523.333333333
what's wrong???
python 2.7
Volume of a sphere = 4/3 πr3 The difference between the two shapes is that a circle is a two-dimensional shape and a sphere is a three-dimensional shape which is the reason that we can measure the Volume and area of a Sphere.
1 Answer. The volume of a sphere is 1436.76 cubic inches.
Nothing is wrong, you have the correct answer. You may want to use math.pi
instead of 3.14 however to increase precision of your answer.
>>> from __future__ import division # not necessary if using python 3
>>> 4/3*math.pi*5**3
523.59877559829886
See the solution at wolfram alpha
If you use floor division instead of true division you will get 392.6, which is what the hint was getting at:
>>> 4//3*math.pi*5**3
392.69908169872411
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With