Answer to Question #35357 in Python for Kevin

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
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.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS