Python Practical 13
Python Practical 13
class Distance:
Os
E The distance is 3 7
The distance in meters is 1.0922
V[81 #0.2.In class defined in Q.1.overload the operator + to add two distances.
0s
class Distance:
Os
def init_(self,feet, inches):
self.inches = inches % 12
self.feet = int((inches+feet*1 2)/12)
self.meters = ( feet*12 + inches )* 0.0254
def print(self):
print("The distance is" , self. feet , , self. inches ")
def meter (self) :
print ("The distance in meters is" ,self. meters )
def add_(self, other):
return self.feet+other. feet, self. inchestother.inches
def_str_(self):
return self.feet, self. inches
d1=Distance (2,19)
d1. print_()
d1 meter)
d1._str_0
d2=Distance (2,4)
d2._print_(0
d2. meter_)
d2._str_)
d3=d1+d2
print(f"\nThe total distance is:{d3} ")
print("\nDistance in string format is given as: ")
d3._str