0% found this document useful (0 votes)
3 views3 pages

Distance Conversion and Operations

Python Practical

Uploaded by

rutujapawar.1408
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Distance Conversion and Operations

Python Practical

Uploaded by

rutujapawar.1408
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

[] #Q.1.

Define a class Distance with constructor that accept distance in


#foot and [Link] must convert inches in foot. Example
#Distance(2, 19) must convert to 3'7'".Define two methods to print() to
#print distance and meter () to return distance in meter.

class Distance:
Os

definit_(self, feet, inches) :


self. inches = inches % 12
self. feet = int((inches+feet*12) /12)
[Link] = (feet*12 + inches )* 0.0254
defprint_(self):
print("The distance is" [Link] [Link] ."!")
def meter(self):
print(" The distance in meters is" ,self . meters )
d=Distance(2, 19)
d._print_()
d. meter_)

E The distance is 3 7
The distance in meters is 1.0922
V[81 #[Link] class defined in [Link] the operator + to add two distances.
0s

V16] class Distance:


def init_(self, feet,inches) :
[Link] = inches % 12
[Link] = int((inches+feet*12)/12)
[Link] = ( 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 [Link], self. inchestother. inches
d1=Distance (2,19)
d1._print_0)
d1 meter0
d2=Distance (2,4)
d2._print_()
d2._meter_(O
print("The total distance is : ")
print (d1 +d2 )

The distance is 3' 7 ' '


The distance in meters is 1.0922
The distance is 2 ' 4 !
The distance in meters is 0.7111999999999999
The total distance is:
(5, 11)
Os [18] #Q.3. In class defined [Link] string operator to convert distance
#into string using _str_() method.

class Distance:
Os
def init_(self,feet, inches):
[Link] = inches % 12
[Link] = int((inches+feet*1 2)/12)
[Link] = ( 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 [Link]+other. feet, self. [Link]
def_str_(self):
return [Link], 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

E The distance is 3 '7


The distance in meters is 1.0922
The distance is 2 ' 4 !
The distance in meters is 0.7111999999999999

The total distance is: (5, 11)

Distance in string format is given as:


'(5, 11)'

You might also like