Python program to add two distances entered by the user.
Problem Description: We need to find the sum of distances that are provided by the user as input in km, m and cm format.
Steps to find the sum of distances:
- Step 1: Take both the distances in cm, m and km format.
- Step 2: Add both the distances, adding cm, m and km. Also, use adequate conversion.
1 m = 100 cm
1 km = 1000 m
Program to add two distances using class
Output:
In the above code, we have created a class Distance that defines methods that perform basic operations like reading input from the user, adding the distances and printing output. Then we have created the objects of the class to get two inputs and then another object to store the sum of distances.
need an explanation for this answer? contact us directly to get an explanation for this answer