Python question, Please answer the questions according to the output pattern in the example.

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Python question, Please answer the questions according to the output pattern in the example.

Post by answerhappygod »

Python question, Please answer the questions according to
the output pattern in the example.
Python Question Please Answer The Questions According To The Output Pattern In The Example 1
Python Question Please Answer The Questions According To The Output Pattern In The Example 1 (271.81 KiB) Viewed 29 times
. . 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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply