Assignment 7

less than 1 minute read

Due: by the end of the calendar day on Wednesday, March 22, 2023

Assignment Requirements

Implement the <, ==, and <= operators in the FeetInches class, and test that all of your comparison operators work. Name your Python file feetinches.py.

For reference, here is the FeetInches class that we started with, thought we probably got a little further than this when we worked together in the classroom.

class FeetInches:
    
    def __init__(self,f,i):
        self.feet = f
        self.inches = i
        
    def simplify(self):
        """
        if the number of inches is > 12, 
        this regroups the excess into feet
        """
        self.feet += self.inches // 12
        self.inches = self.inches % 12
    
    def __repr__(self):
        return str(self.feet)+"ft. "+str(self.inches)+"in."
    
    def __add__(self,other_measurement):
        total_feet = self.feet + other_measurement.feet
        total_inches = self.inches + other_measurement.inches
        
        #create an new FeetInches object with the new measurements
        total_FI = FeetInches(total_feet,total_inches)
        total_FI.simplify()
        return total_FI
    

measurement1 = FeetInches(3,6)
measurement2 = FeetInches(2,6)
total = measurement1 + measurement2
print(total)

What to turn in

Submit your feetinches.py file to codePost for the Assignment 7: Compare FeetInches assignment on codePost. I have written a script which will import your code and test it against several possible feet-inches values like this:

measurement1 = FeetInches(3,6)
measurement2 = FeetInches(2,18)
print(measurement1 == measurement2) #expecting True

Grading

This is a 4-point assignment. See the rubric from the syllabus.