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 ”’
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