Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
2.3k views
in Python Classes and Objects by (54.9k points)
closed by

Write a menu driven program to read, display, add and subtract two distances? 

1 Answer

+1 vote
by (49.3k points)
selected by
 
Best answer

class Dist:

def_init_(self):

self, dist 1=0

self.dist 2=0

def read(self):

self.dist 1=int(input(“Enter distance 1”))

self.dist 2=int(input(“Enter distance 2”))

def disp(self):

print(“distance 1” , self.dist 1)

print(“distance 2” , self.dist 2)

def add(self):

print(“Total distances” , self.dist 1+self.dist 2)

def sub(self):

print(“Subtracted distance” , self.dist 1-self.dist 2) 

d=Dist( )

choi = “y”

while(choi == “y”):

print(” 1. accept \n 2. Display \n 3. Total \n 4. Subtract”)

ch = int(input(“Enter your choice”))

if(ch==l):

d.read( )

elif(ch==2):

d.disp( )

elif(ch==3):

d.add( )

elif(ch==4):

d.sub( )

else: 

print(“Invalid Input…”)

choi = input(“Do you want to continue”)

Output:

1. Accept

2. Display

3. Add

4. Subtract

Enter your choice : 3

Enter distance 1 : 100

Enter distance 2 : 75

Do you want to continue .. y

1. Accept

2. Display

3. Add

4. Subtract

Enter your choice : 3

Total distances : 175

Do you want to continue .. y

1. Accept

2. Display

3. Add

4. Subtract

Enter your choice : 2

Enter distance 1 : 100

Enter distance 2 : 75

Do you want to continue .. y

1. Accept

2. Display

3. Add

4. Sub

Enter your choice : 4

Subtracted distance : 25

Do you want to continue .. N

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

...