The formula for calculating the circumference of a circle is 2*π*r. The formula for calculating the area of a circle is π*r*r. Write a Python class named Wheel, constructed by a radius and two methods, which will calculate the perimeter (circumference) and the surface area of a wheel (circle). The script should ask for the user's input for the radius, create a Wheel object, and print out its surface area and perimeter. It should ask for the user's input again after it prints the surface area and perimeter each time. You should use the math modules and set the pi constant as your value for pi. Our aim here is to practice defining methods in a class. Open the file named main.py. Define the Wheel class and the Wheel constructor method. Create the wheel_area calculation method, which returns the surface area of the wheel. Create the wheel_perimeter calculation method, which returns the perimeter of the wheel. Create the swap_radius method, which sets new_radius as the radius of the wheel when requested from user input. After the class definition, add the code that requests for user input for the radius of the wheel. Create a __main__ and add a while loop so that the request for user input runs multiple times. In the while loop, we'll request the user input, change the Wheel object's radius using the swap_radius method, and then print out the surface area and perimeter of the wheel. Make sure that your program terminates properly when the user indicates they would like to quit. You can run the script by using python3 main.py command. The script will ask for user input, calculate the surface area and perimeter, print that out, and ask for your input again.
The formula for calculating the circumference of a circle is 2*π*r. The formula for calculating the area of a circle is π*r*r.
Write a Python class named Wheel, constructed by a radius and two methods, which will calculate the perimeter (circumference) and the surface area of a wheel (circle).
- The script should ask for the user's input for the radius, create a Wheel object, and print out its surface area and perimeter.
- It should ask for the user's input again after it prints the surface area and perimeter each time.
- You should use the math modules and set the pi constant as your value for pi.
Our aim here is to practice defining methods in a class.
-
Open the file named main.py.
-
Define the Wheel class and the Wheel constructor method.
-
Create the wheel_area calculation method, which returns the surface area of the wheel.
-
Create the wheel_perimeter calculation method, which returns the perimeter of the wheel.
-
Create the swap_radius method, which sets new_radius as the radius of the wheel when requested from user input.
-
After the class definition, add the code that requests for user input for the radius of the wheel.
-
Create a __main__ and add a while loop so that the request for user input runs multiple times. In the while loop, we'll request the user input, change the Wheel object's radius using the swap_radius method, and then print out the surface area and perimeter of the wheel.
Make sure that your program terminates properly when the user indicates they would like to quit.
- You can run the script by using python3 main.py command. The script will ask for user input, calculate the surface area and perimeter, print that out, and ask for your input again.
Unlock instant AI solutions
Tap the button
to generate a solution








