How to Convert Centimeters to Feet and Inches in Python

In this tutorial, we will learn how to program "How to Convert Centimeters to Feet and Inches in Python." The objective is to accurately convert a given value in centimeters into feet and inches. This tutorial will guide you step by step through the entire process of properly performing the unit conversion. By the end of this tutorial, you will have a solid understanding of how to implement this task effectively in Python, helping you strengthen your problem-solving abilities and enhance your coding skills.

This topic is straightforward to understand. Just follow the instructions provided, and you will be able to complete it with ease. The program will guide you through the process of converting centimeters to feet and inches. So, let’s dive into the coding process!

Getting Started:

First you will have to download & install the Python IDLE's, here's the link for the Integrated Development And Learning Environment for Python https://www.python.org/downloads/.

Creating Main Function

This is the main function of the application. The following code will display a simple GUI in terminal console that will display program. To do this, simply copy and paste these blocks of code into the IDLE text editor.
  1. while True:
  2.     print("\n=============== Convert Centimeters to Feet and Inches ===============\n")
  3.  
  4.     cm=int(input("Enter the height in centimeters: "))
  5.     inches=0.394*cm
  6.     feet=0.0328*cm
  7.     print("The length in inches ",round(inches,2))
  8.     print("The length in feet ",round(feet,2))
  9.  
  10.     opt = input("\nDo you want to try again?(yes/no): ")
  11.            
  12.     if opt.lower() == 'yes':
  13.         ret=False
  14.     elif opt.lower() == 'no':
  15.         ret=True
  16.         print("Exiting program....")
  17.     else:
  18.         print("Please enter yes/no:")
  19.         break
  20.  
  21.     if ret == False:
  22.         continue

This program converts a given height from centimeters to both feet and inches. It repeatedly prompts the user to enter a height in centimeters, then calculates and displays the equivalent values in inches (using the conversion factor 1 cm = 0.394 inches) and feet (1 cm = 0.0328 feet), rounded to two decimal places. After each conversion, the user is given the option to try again or exit the program.

Output:

There you have it we successfully created How to Convert Centimeters to Feet and Inches in Python. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

More Tutorials for Python Language

Python Tutorials