Question #35357

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

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

Expert's answer

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.

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.

Learn more about our help with Assignments: Python

## Comments

## Leave a comment