Python question, Please answer the questions according to the output pattern in the example.
Posted: Mon May 09, 2022 7:08 am
Python question, Please answer the questions according to
the output pattern in the example.
. . Example 3 Enter a radius (centimeters): Hello Entry error: radius must be numerical. Try again. Enter a radius (centimeters): Goodbye Entry error: radius must be numerical. Try again. Enter a radius (centimeters): 0 A sphere with a radius of 0.0 centimeters will have: Volume: 0.00 centimeters cubed Circumference: 0.00 centimeters squared Surface Area: 0.00 centimeters squared . o PROBLEM 2: Designing objects and object methods (6 points) Design a class called Sphere which has the following attributes and methods: A constructor that accepts a single argument - a radius. A method called get_volume. o This method should accept no arguments and return the value of a sphere's volume as calculated by the formula V = (4/3)*3 A method called get circumference. This method should accept no arguments and return the value of a sphere's volume as calculated by the formula C = 21 A method called get_surfacearea. o This method should accept no arguments and return the value of a sphere's volume as calculated by the formula A = 4112 A method called sphere reporter This method should accept no arguments and print the volume, circumference, and surface area of a sphere using the object methods described above. o Use the format function to report only the first two digits of each value and to add commas as thousands separaters. . . Example 4 Enter a radius (centimeters): -5 Entry error: radius cannot be a negative number. Enter a radius (centimeters): 0 A sphere with a radius of 0.0 centimeters will have: Volume: 0.00 centimeters cubed Circumference: 0.00 centimeters squared Surface Area: 0.00 centimeters squared Write a program that will ask the user to input in a radius in centimeters). Instantiate an object with the input radius and use the sphere.sphere_reporter method to print the volume, circumference, and surface area of a sphere with that radius. Use try/except/else to print an error message if the user enters a string instead of a numerical value. The error message should print until the user enters in a proper radius value. Use the import statement to import the value of pi from the Python math module. . Below are some sample runnings of the program. Underlines indicate user input. Example 1 Enter a radius (centimeters): 5 A sphere with a radius of 5.0 centimeters will have: Volume: 523.60 centimeters cubed Circumference: 31.42 centimeters squared Surface Area: 314.16 centimeters squared Example 2 Enter a radius (centimeters): 123.4 A sphere with a radius of 123.4 centimeters will have: Volume: 7,871,075.68 centimeters cubed Circumference: 775.35 centimeters squared Surface Area: 191,355.16 centimeters squared
the output pattern in the example.
. . Example 3 Enter a radius (centimeters): Hello Entry error: radius must be numerical. Try again. Enter a radius (centimeters): Goodbye Entry error: radius must be numerical. Try again. Enter a radius (centimeters): 0 A sphere with a radius of 0.0 centimeters will have: Volume: 0.00 centimeters cubed Circumference: 0.00 centimeters squared Surface Area: 0.00 centimeters squared . o PROBLEM 2: Designing objects and object methods (6 points) Design a class called Sphere which has the following attributes and methods: A constructor that accepts a single argument - a radius. A method called get_volume. o This method should accept no arguments and return the value of a sphere's volume as calculated by the formula V = (4/3)*3 A method called get circumference. This method should accept no arguments and return the value of a sphere's volume as calculated by the formula C = 21 A method called get_surfacearea. o This method should accept no arguments and return the value of a sphere's volume as calculated by the formula A = 4112 A method called sphere reporter This method should accept no arguments and print the volume, circumference, and surface area of a sphere using the object methods described above. o Use the format function to report only the first two digits of each value and to add commas as thousands separaters. . . Example 4 Enter a radius (centimeters): -5 Entry error: radius cannot be a negative number. Enter a radius (centimeters): 0 A sphere with a radius of 0.0 centimeters will have: Volume: 0.00 centimeters cubed Circumference: 0.00 centimeters squared Surface Area: 0.00 centimeters squared Write a program that will ask the user to input in a radius in centimeters). Instantiate an object with the input radius and use the sphere.sphere_reporter method to print the volume, circumference, and surface area of a sphere with that radius. Use try/except/else to print an error message if the user enters a string instead of a numerical value. The error message should print until the user enters in a proper radius value. Use the import statement to import the value of pi from the Python math module. . Below are some sample runnings of the program. Underlines indicate user input. Example 1 Enter a radius (centimeters): 5 A sphere with a radius of 5.0 centimeters will have: Volume: 523.60 centimeters cubed Circumference: 31.42 centimeters squared Surface Area: 314.16 centimeters squared Example 2 Enter a radius (centimeters): 123.4 A sphere with a radius of 123.4 centimeters will have: Volume: 7,871,075.68 centimeters cubed Circumference: 775.35 centimeters squared Surface Area: 191,355.16 centimeters squared