03 Teach : Team Activity
Overview
Write a class in Python 3 to hold rational numbers (i.e., fractions). Your rational number class should contain an integer for the numerator and denominator.
Instructions
Special Instructions for Online Students
You need to coordinate a one hour synchronous meeting with your team where you can share screens and work together on the same code (e.g., Skype, Google Hangouts, etc.).
Team activities are designed to be completed in teams.
You should prepare for the activity by completing the preparation material and at least Checkpoint A before your meeting. You are welcome, but not expected, to look over these instructions before your meeting, but keep in mind that the goal is not to complete the assignment individually first so you can rush your team through it.
With all this in mind, some students find they want extra time to let the problem sink in before the meeting. In this case, it is appropriate to look at the problem and start on it individually before meeting with the team. But then, when working with the team, you should help coach your teammates through the problem.
Working on the same code
The vision for these team activities is to have multiple people "pair programming" on the same code. In the classroom, this looks like 3 people huddled around a single laptop. For online students, this means you have a way to share your screen so that everyone can see, comment, and contribute to the program that is being written.
Make sure to alternate the main "driver" of the keyboard each week, so that everyone gets a chance to do this.
At the end of the activity, please distribute the code you have written to each member of the team.
Requirements and Expectations
Each activity will be divided into 3 core requirements and 3 stretch challenges. If you are prepared for the activity, you should be able to get through the core requirements during the one hour period.
In any case, at the end of the one hour meeting period, you are welcome to continue working on any part of the activity either individually or with your team, but you are not necessarily expected to. Completing the core requirements can get you to the 100% threshold for the assignment, and the stretch challenges are worth 10% additional credit.
Requirements
Core Requirements
Define your class at the top of the file, then make a main function to create a new rational number and call the appropriate methods to demonstrate the functionality as follows:
-
Have your class initialize the numerator to 0 and the denominator to 1 (Hint: Use the
__init__
function). Then create adisplay
member function (method) that displays the number in the format: "top/bottom", such as: "3/4" or "0/1". No need to reduce the fraction at this point.Have main create a new rational number and display it. Verify that your result looks correct.
Create a
prompt
member function (aka method) that prompts the user for the numerator and the denominator. Then change main so that it creates a new object, displays it, calls prompt, and displays it again.Create an additional display method called
display_decimal
that displays the fraction in decimal form (e.g., 3/4 would display as 0.75). Then, add a line at the end of main to display the decimal version of your number in addition to the standard version.
An example run could look something like the following:
0/1
Enter the numerator: 3
Enter the denominator: 4
3/4
0.75
Stretch Challenges
After finishing the core requirements, help everyone on your team complete them. When everyone has completed the core requirements, please move on to these stretch challenges.
Please be aware these are a little tricky.
Change your
display
function so that if the value is an improper fraction (larger on top than bottom), it displays it as a mixed number, such as: "1 1/4", rather than "5/4".Create a
reduce
function, that reduces rational numbers to their most basic equivalent form (e.g., 2/6 becomes 1/3). Modify your main function to demonstrate it.Write a
multiply_by
function that accepts another rational number and changes the value of the current object (multiply the two numerators to get the new numerator and the two denominators to get the new denominator). Modify your main function to demonstrate it.
Instructor's Solution
As a part of this team activity, you are expected to look over a solution from the instructor, to compare your approach to that one. One of the questions on the I-Learn submission will ask you to provide insights from this comparison.
Please DO NOT open the solution until you have worked through this activity as a team for the one hour period. At the end of the hour, if you are still struggling with some of the core requirements, you are welcome to view the instructor's solution and use it to help you complete your own code. Even if you use the instructor's code to help you, you are welcome to report that you finished the core requirements, if you code them up yourself.
After working with your team for the one hour activity, click here for the instructor's solution.
Submission
When you have finished this activity, please fill out the assessment in I-Learn. You are welcome to complete any additional parts of this activity by yourself or with others after class before submitting the assessment.