Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Zybooks – python sphere volume challenge

Scenario: Given sphere_radius and pi, compute the volume of a sphere and assign to sphere_volume. Volume of sphere = (4.0 / 3.0) π r^3

Sample output with input: 1.0
Sphere volume: 4.19


pi = 3.14159
sphere_volume = 0.0

sphere_radius = float(input())

”’ Your solution goes here ”’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

sphere_volume = (4.0/3.0) * pi * sphere_radius

print('Sphere volume: {:.2f}'.format(sphere_volume))

Test Results:

(Correct) Testing volume with input: 1.0
Your output
Sphere volume: 4.19

(Incorrect) Testing volume with input: 5.5
Output differs. See highlights below.
Your output
Sphere volume: 23.04
Expected output
Sphere volume: 696.91


I’m getting the 1st half of the tests complete but when it runs the code again, it fails the 2nd portion.

>Solution :

You must cube radius value in the formula:

pi = 3.14159 
sphere_volume = 0.0

sphere_radius = float(input())
sphere_volume = (4.0/3.0)*pi*(sphere_radius)**3

print('Sphere volume: {:.2f}'.format(sphere_volume))

Output:

1
Sphere volume: 4.19
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading