Write a Python program that asks for your height in cm and then converts your height to feet and inches.(1 foot=12 inches, 1 inch =2.54 cm).
Please hurry up I'll definitely Mark you Brain list
Answers
Height Conversion - Python
First we will take user input of height in cm. We first convert this to inches by dividing by 2.54
After that, we use Floor Division // and Modulo % by 12 to get feet and inches respectively. The inches will be in a lot of decimals. We round this off to 2 decimal places and finally print out the converted height.
Here's the code.
# Take user input for height in cm
height_cm = float(input("Enter your height in cm: "))
# Convert height to inches
height_in = height_cm / 2.54
# Get feet by taking floor division with 12
feet = height_in // 12
# Get inches by taking modulo division with 12
inches = height_in % 12
# Round off the inches to 2 decimal places
inches_rounded = format(inches, ".2f")
# Print out the height in feet and inches
print(f"Height is {feet} ft {inches_rounded} in")