I've got a program that prompts the user for both the volume and dimensions of an n-ball. I figured out all the coding necessary to do all this and it works just fine when i run the program as volume+dimension.
How would I go about typing in the formula for the volume of an n-ball found here http://en.wikipedia.org/wiki/Volume_of_an_n-ball
1
Expert's answer
2013-09-25T12:44:16-0400
For Python 2.7.x:
import math math.pi**(float(n)/2) / math.gamma(float(n)/2+1) * (R**n)
For Python 3.x:
import math volume = math.pi**(n/2) / math.gamma(n/2+1) * (R**n)
The difference is in the conversion of the integer n to the real value variable.
Comments
Leave a comment