66 994
Assignments Done
99,2%
Successfully Done
In November 2018

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

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions