Define a class for representing a distance with one


Need help in simple Python form.

Define a class for representing a distance (with one attribute that represents the distance in inches). You will also need to implement the following:

1) A method that takes no extra arguments and returns the distance as a number of inches. So for example, if you created a Distance object with the command dist1 = Distance(1,2), then dist1.to_inches() should return 25 (because two feet plus one inch is 25 inches).

2) A method that takes no extra arguments and returns the distance as a number of feet. So for example, if you created a Distance object by dist1 = Distance(18), then dist1.to_feet() should return 1.5 (because 18 inches is 1.5 feet).

3) A method that takes no extra arguments and returns a tuple of two numbers representing the Distance in inches and feet (with the inches first).

So for example, if you created a Distance object with the command dist1 = Distance(30), then dist1.to_inches_and_feet() should return (6,2) (because 30 inches is equal two feet, six inches). Note that the inches part can be a float, but the feet part must be an integer (so (2.5,1) is okay, but (1, 1.5)is not).

4) A method called .__str__() which takes no extra arguments and returns a string in the format feet'inches". You'll probably want to use the .to_inches_and_feet() method you created earlier.

The .__str__() method is very similar to the .__repr__() method, only it is used to create strings that are meant to be displayed to the user instead of to another programmer. That's why the format is different. This method will automatically get used when you try to print() a Distanceobject.

So for example, if you created a Distance object with the command dist1 = Distance(30), then print(dist1) should display 2'6" on the screen. Similarly, the command str(dist1)should return the string '2\'6"'.

Request for Solution File

Ask an Expert for Answer!!
Python Programming: Define a class for representing a distance with one
Reference No:- TGS02873545

Expected delivery within 24 Hours