Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Python Program to Read Height in Centimeters and convert the Height to Feet and Inches
Converting height from centimeters to feet and inches is a common unit conversion task. Python provides built-in functions like round() to handle decimal precision in calculations.
Basic Conversion Method
Here's a simple approach to convert centimeters to both feet and inches separately ?
height_cm = int(input("Enter the height in centimeters: "))
# Convert to inches and feet
height_inches = 0.394 * height_cm
height_feet = 0.0328 * height_cm
print("The height in inches is:", round(height_inches, 2))
print("The height in feet is:", round(height_feet, 2))
Enter the height in centimeters: 178 The height in inches is: 70.13 The height in feet is: 5.84
Converting to Feet and Remaining Inches
A more practical approach is to express height in feet and remaining inches format ?
height_cm = 178
# Convert to total inches first
total_inches = height_cm / 2.54
# Calculate feet and remaining inches
feet = int(total_inches // 12)
remaining_inches = round(total_inches % 12, 1)
print(f"Height: {height_cm} cm")
print(f"Converted: {feet} feet {remaining_inches} inches")
Height: 178 cm Converted: 5 feet 10.1 inches
Comparison of Methods
| Method | Formula | Result Format | Use Case |
|---|---|---|---|
| Direct conversion | cm × 0.0328 | Decimal feet | Simple calculations |
| Feet and inches | cm ÷ 2.54 ÷ 12 | X feet Y inches | Real-world usage |
Key Conversion Factors
1 inch = 2.54 cm (exact conversion)
1 foot = 12 inches = 30.48 cm
0.394 factor is an approximation (1÷2.54)
0.0328 factor is an approximation (1÷30.48)
Complete Example with Input Validation
try:
height_cm = float(input("Enter height in centimeters: "))
if height_cm <= 0:
print("Height must be positive!")
else:
# More accurate conversion
total_inches = height_cm / 2.54
feet = int(total_inches // 12)
inches = round(total_inches % 12, 1)
print(f"\nHeight conversion:")
print(f"{height_cm} cm = {feet}' {inches}"")
print(f"Total inches: {round(total_inches, 1)}")
print(f"Decimal feet: {round(total_inches / 12, 2)}")
except ValueError:
print("Please enter a valid number!")
Enter height in centimeters: 175 Height conversion: 175.0 cm = 5' 8.9" Total inches: 68.9 Decimal feet: 5.74
Conclusion
Use the feet-and-inches format for practical applications, as it's more intuitive. The exact conversion factor is 1 inch = 2.54 cm, which provides more accurate results than the approximation factors.
---Advertisements
