W02 Code-along Activity: Areas of Shapes
Code-along Activity Overview
For this activity, you will code along with an instructor video that walks you through each step of the activity below. Make sure that you pause the video, or watch sections over if you need to, so that you are able to complete the entire activity.
Your instructor will post a link to the video in Microsoft Teams.
Overview
Python can be used to calculate values for data analysis and complex mathematical and scientific problems. In this activity, you will practice using variables and expressions for straight-forward math calculations. The purpose of the assignment is to help you become more comfortable using variables to accomplish a problem, not to focus on the actual math at hand.
Program Requirements
Write a program to compute the areas of three different shapes: a square, a rectangle, and a circle. Prompt for the necessary information, then compute and display the area, as follows:
Square—The area is the length of a side squared.
Rectangle—The area is the length multiplied by the width.
Circle—The area is Pi (approximately 3.14) multiplied by the radius squared.
Make sure that your program can appropriately handle decimal values as well as whole numbers.
An example run of the program might look something like the following:
What is the length of a side of the square? 5
The area of the square is: 25.0
What is the length of rectangle? 6
What is the width of the rectangle? 7
The area of the rectangle is: 42.0
What is the radius of the circle? 5
The area of the circle is: 78.5
Another run could be the following:
What is the length of a side of the square? 3.5
The area of the square is: 12.25
What is the length of rectangle? 6
What is the width of the rectangle? 7.5
The area of the rectangle is: 45.0
What is the radius of the circle? 8.2
The area of the circle is: 211.1336
Enhancement
Once you have that working, ask for the value in centimeters, then display the results in both square centimeters and square meters. A centimeter is 1/100 of a meter, and a square centimeter is 1/10,000 of a square meter.
Instructions
Find the video that your instructor has posted for this assignment and code along with them for each of the following steps.
Please work through the requirements in order with the instructor rather than jumping ahead to more complicated steps, to ensure that you are understanding the fundamental concepts.
Sample Solution
In addition to the instructor video, you can also view this sample solution. (This solution may be slightly different than the final code that you and your instructor created.)
Alternative Video Link
In addition to the link that your instructor posted, you are also welcome to watch the following code walkthrough or use its transcript:
- Areas of Shapes Code-along Video (27 minutes)
Submission
Please pause and re-watch any sections of the instructor video necessary until you have completed the entire activity and your program runs the same as the instructor's. When you are finished:
- Return to Canvas to take the quiz.
Up Next
- W02 Project: Meal Price Calculator
Other Links:
- Return to: Week Overview | Course Home