# Metric to imperial

 Chanamon Chaiyakul · July 30, 2015 Hello,I'm new to python and I am trying to convert metres to feet and inches. I could't print out the right answer..FEET_PER_METRE = 3INCHES_PER_FOOT = 12metre = int(input("Please enter a number in metre: "))length_imp = FEET_PER_METRE  * metre length_metric = length_imp * INCHES_PER_FOOT print("equals", length_imp, "feet", length_metric, "inches")Thanks!

## Replies

 Chanamon Chaiyakul · August 1, 2015 Thank you for your help Pavel!  I'm still trying to understand this part of the code:"remaining_inches_to_feet = length_in_feet_and_inches\            % int(length_in_feet_and_inches)length_in_inches = remaining_inches_to_feet * INCHES_PER_FOOTlength_in_inches = round(length_in_inches, 2)          length_in_feet = int(length_in_feet_and_inches)print("Equals {} feet {} inches".format(length_in_feet, length_in_inches))  "Can this part of the code be made any shorter or is this as short as it gets? Can I use other function instead of round() Chanamon Chaiyakul · August 1, 2015 I'm just having trouble understanding this particular line:remaining_inches_to_feet = length_in_feet_and_inches\    % int(length_in_feet_and_inches)Thanks! Pavel Dimi · August 2, 2015 The ``remaining_inches_to_feet = length_in_feet_and_inches\% int(length_in_feet_and_inches)``is pretty much when you have the feet and inches like 6.55 which is 6 feet and 0.55 of a feet you just get the remainder 0.55by doinga moduls devision its like 6.55 devided by int(6.55) wihch is 6 so it is 6.55%6 whichi is 0.55 if you dont know modulous division look it up. And yes it can be written shorter but in the sense of making it a bit more logicali separated i wrote it like this. It is a simpe computiation. The round function is used just to drop some of the numbers like 6.66666666 is now 6.66 Halcyon Abraham Ramirez · August 2, 2015 if you wanted a function here they are``def meters_to_inches(meter):    return meter * 39.3701def meters_to_feet(meter):    return meter * 3.28084``if not then here is a simple version:``meter = float(input("how many meters? "))print( str(meter) + " meters to feet is " + str(meter * 3.28084) + " feet")print(str(meter) + " meters to inches is " + str(meter * 39.3701) + " inches")`` Chanamon Chaiyakul · August 3, 2015 Thank you to both of you! Pavel Dimi · July 30, 2015 I guess you mean something like this ?``FEET_PER_METRE = 3.28INCHES_PER_FOOT = 12metre = float(input("Please enter a number in metre: "))length_in_feet_and_inches = FEET_PER_METRE * metreremaining_inches_to_feet = length_in_feet_and_inches\    % int(length_in_feet_and_inches)length_in_inches = remaining_inches_to_feet * INCHES_PER_FOOTlength_in_inches = round(length_in_inches, 2)length_in_feet = int(length_in_feet_and_inches)print("Equals {} feet {} inches".format(length_in_feet, length_in_inches))``
• 1

## Python

131,275 followers