简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM