01 Practice: Review Python
Purpose
Review how to write a Python program that gets input from a user,
uses variables, performs arithmetic using the math
module, and outputs results.
Problem Statement
The surface area of a right circular cone can be computed with this formula:
- A is the surface area of the cone
- r is the radius of the cone
- h is the height of the cone
Assignment
Write a Python program named cone_surface_area.py
that reads from the keyboard the radius and height of a right
circular cone and computes and outputs the surface area of that
cone.
Helpful Documentation
The Python
math
module contains mathematical constants and functions including
math.pi
and
math.sqrt.
Testing Procedure
Verify that your program works correctly by following each step in this testing procedure:
- Run your program and enter the inputs shown below. Ensure that your program’s output matches the output below.
> python cone_surface_area.py This program computes and outputs the surface area of a right circular cone. Enter the radius of a cone: 5 Enter the height of a cone: 8 The surface area is 226.7
- Run your program again and enter the values: -5 and 8. Did your program output valid results? What should your program do when a user enters negative numbers?
Sample Solution
When your program is finished, compare your program to the sample solution for this assignment. Before looking at the sample solution, you should work to complete this practice program.