CSE 110 | Programming Building Blocks

03 Teach: Team Activity

Areas of Shapes

Instructions

Face-to-face students will complete this activity in class. You should have several people working around the same laptop together.

Online students should arrange for a one hour synchronous meeting to work through the activity together. Make sure that each person has a way to see the code that is being typed. At the end of the activity, please share the final python file with everyone on the team.

Keep in mind that the goal of this activity is to work together and teach and learn from one another. The vision is to help everyone understand the material rather than moving through it as quickly as you can.

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.

Assignment

Start by completing the core requirements, then when that part is complete, if you have time, see if you can complete some of the stretch challenges as well.

Core Requirements

Write a program to compute the areas of three different shapes. Prompt for the necessary information, then compute and display the area, as follows:

Make sure that your program can appropriately handle decimal values as well as whole numbers.

  1. Square—The area is the length of a side squared.

  2. Rectangle—The area is the length multiplied by the width.

  3. Circle—The area is Pi (you can use 3.14) multiplied by the radius squared.

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

Stretch Challenge

Once you have finished the core requirements, you are welcome to move on to the stretch challenges. These can be more difficult and may require finding solutions that weren't directly covered in the reading. These aren't specifically required for the assignment, but are a great chance to dive deeper into the concepts of the lesson.

The stretch challenges for this activity are:

  1. Instead of using 3.14 for your value of Pi, see if you can find and use the built-in value of Pi included in the python "math" module. Hint, you might try searching on the internet for something like, "python how to get the value of pi."

  2. Prompt the user for a single length value, then compute and display the areas of a square with that length of side, a circle with that radius, and then the volumes of a cube with that side and a sphere with that radius, all from the same value from the user.

  3. For each of the three areas in the core requirements, change the prompt for the user to ask for the value in centimeters. Then, display the resulting area in both square centimeters and square meters. Keep in mind that a centimeter is 1/100 of a meter, and a square centimeter is 1/10,000 of a square meter.

Sample Solution

When your program is finished, please view the sample solution for this program to compare it to your approach.

You should work to complete this team activity for the one hour period first, without looking at the sample solution. However, if you have worked on it for at least an hour and are still having problems, you may feel free to use the sample solution to help you finish your program.

Submission

When complete, please report your progress in the associated I-Learn quiz.

If you decided to do additional work on the program after your team activity, either by yourself or with others, feel free to include that additional work when you report on your progress in I-Learn.