Computer Science, asked by ixbghrasdqcyrkhdxc, 8 months ago

Q-1: Write a program to accept two distances(first distance in feet and inches & second distance in feet and inches……….4 values are to be accepted by user).Display the sum of these two distances with feet & inches. Python

Answers

Answered by poojan
2

PYTHON PROGRAM FOR ADDING TWO DISTANCES IN INCH - FEET SYSTEM.

Language used : Python Programming.

Program :

print("INFO ABOUT FIRST DISTANCE")

xfeet=int(input("Enter no.of feets : "))

xinches=float(input("Enter no.of inches : "))

print("\nINFO ABOUT SECOND DISTANCE")

yfeet=int(input("Enter no.of feets : "))

yinches=float(input("Enter no.of inches : "))

feet = xfeet + yfeet

inches = float(xinches+yinches)

#As 1 foot = 12 inches, if the sum goes >12, a feet gets add up to the feet var, and corresponding 12 inches get reduced.

if inches>=12:

   feet = feet+1

   inches = inches-12

print("\nSUM OF THE DISTANCES IS {0} FEET, {1} INCHES.".format(feet, inches))

Input :

INFO ABOUT FIRST DISTANCE

Enter no.of feets : 13

Enter no.of inches : 11.1

INFO ABOUT SECOND DISTANCE

Enter no.of feets : 46

Enter no.of inches : 3.4

Output :

SUM OF THE DISTANCES IS 60 FEET, 2.5 INCHES.

Explanation :

  • Take corresponding feet and inches information of distance 1 as an input from the user and store them into their respective variables.

  • Do the same with distance 2's information.

  • Then sum up the values in variables of feet of 2 distances with each other and store it in a variable. Do the same with inches too.

  • As we know that 1 foot = 12 inches, check if the sum variable of inches hold the value greater than or equal to 12.

  • If yes, increment the feet value by 1 and subtract 12 from inches variable.

  • Else, leave them alone.

  • Then, print out the summed up values. That's it!

Learn more :

1) Write a Python function sumsquare(l) that takes a nonempty list of integers and returns a list [odd,even], where odd is the sum of squares all the odd numbers in l and even is the sum of squares of all the even numbers in l.

brainly.in/question/15473120

2) Python program to find absolute difference between the odd and even numbers in the inputted number.

brainly.in/question/11611140

Attachments:
Similar questions