English

Write a program to find sum of two distances with feet and inches.

Advertisements
Advertisements

Question

Write a program to find sum of two distances with feet and inches.

Code Writing
Advertisements

Solution

Add feet and inches; if inches are 12 or more, convert them into feet.

feet1 = int(input("Enter first distance in feet: "))
inches1 = int(input("Enter first distance in inches: "))
feet2 = int(input("Enter second distance in feet: "))
inches2 = int(input("Enter second distance in inches: "))

feet = feet1 + feet2
inches = inches1 + inches2

if inches >= 12:
    feet += inches // 12
    inches %= 12

print("Sum of distances =", feet, "feet", inches, "inches")
shaalaa.com
  Is there an error in this question or solution?
Chapter 1: Review of Phython - EXERCISE [Page 27]

APPEARS IN

CBSE Computer Science with Python [English] Class 12
Chapter 1 Review of Phython
EXERCISE | Q 18. | Page 27
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×