Skip to main content
  1. Posts/

Cm to Feets Conversion Program

·197 words·1 min
Table of Contents

Hello, today I made a program that converts cm to feets heres how I do it:

How I made it #

First I made a program under the name of conversion_library that has my other program convert-celsius-to-fahreneit, I named this function convert_cm_to_ft and passed it to a variable called feet and using the conversion method (cm / 30.48 = feets) and returned feets lastly I called the function.

Heres the code:

def convert_cm_to_ft(cm):
    feet = cm / 30.48
    return(feet)

if __name__ == '__main__':
    print(convert_cm_to_ft(1))

Heres the sample output:

0.03280839895013123

Last step I imported the program to another program called convert_cm_to_ft and used the try & except (check my last blog convert celsius to fahrenheit)

Heres what it should look like:

from conversion_library import convert_cm_to_ft

try:
    i = int(input("Enter a number to convert to feets: "))
    print(f"{i}cm is {convert_cm_to_ft(i)} in feets ")
except:
    print("You did not enter a number >:(")

Heres the sample output if you type it correctly:

Enter a number to convert to feets: 1
1 cm is 0.03280839895013123 in feets

Heres the sample output if you dont type it correctly

Enter a number to convert to feets: a
You did not enter a number>:(

The end:3