179.5cm in feet: Given height in centimeters , the task is to convert the given height to feet and inches in Python.
Examples:
Example1:
Input:
Enter some random height in centimeters = 179.5
Output:
The given height 179.5 cm in inches = 70.72 inches The given height 179.5 cm in feet = 5.89 feet
Example2:
Input:
Enter some random height in centimeters = 165
Output:
The given height 165.0 cm in inches = 65.01 inches The given height 165.0 cm in feet = 5.41 feet
- Python Program to Convert a Decimal Number to Binary
- Python Program to Convert Binary to Decimal using While Loop
- Python Program to Convert Binary to Octal using While Loop
Program to Read Height in Centimeters and then Convert the Height to Feet and Inches in Python
179.5cm in feet: There are several ways to read height in centimeters and then convert it to feet and inches in Python some of them are:
Method #1:Python Static Input
- Give the height in centimeters as static input.
- Convert the given height in centimeters to feet by multiplying it with 0.0328 and store it in a variable.
- Convert the given height in centimeters to inches by multiplying it with 0.0.394 and store it in a variable.
- Print the height in feet and inches.
- Exit of Program.
Below is the implementation:
# Give the height in centimeters as static input. heightcm = 165 # Convert the given height in centimeters to feet by multiplying it with 0.0328 # and store it in a variable. heightfeet = 0.0328*heightcm # Convert the given height in centimeters to inches by multiplying it with 0.0.394 # and store it in a variable. heightinches = 0.394*heightcm # Print the height in feet and inches. print("The given height", heightcm, 'cm', 'in inches = ', round(heightinches, 2), 'inches') print("The given height", heightcm, 'cm', 'in feet = ', round(heightfeet, 2), 'feet')
Output:
The given height 165 cm in inches = 65.01 inches The given height 165 cm in feet = 5.41 feet
Explanation:
- Given the height in centimeters as static input.
- The height in centimeters is multiplied by 0.394 and saved in a new variable called height in inches.
- The height in centimeters is multiplied by 0.0328 and saved in a new variable called height in feet.
- It is printed the conversion height in inches and feet.
Method #2:Python User Input
Approach:
- Enter the height in centimeters as user input using float(input()) function .
- Convert the given height in centimeters to feet by multiplying it with 0.0328 and store it in a variable.
- Convert the given height in centimeters to inches by multiplying it with 0.0.394 and store it in a variable.
- Print the height in feet and inches.
- Exit of Program.
Below is the implementation:
# Enter the height in centimeters as user input using int(input()) function. heightcm = int(input('Enter some random height in centimeters = ')) # Convert the given height in centimeters to feet by multiplying it with 0.0328 # and store it in a variable. heightfeet = 0.0328*heightcm # Convert the given height in centimeters to inches by multiplying it with 0.0.394 # and store it in a variable. heightinches = 0.394*heightcma # Print the height in feet and inches. print("The given height", heightcm, 'cm', 'in inches = ', round(heightinches, 2), 'inches') print("The given height", heightcm, 'cm', 'in feet = ', round(heightfeet, 2), 'feet')
Output:
Enter some random height in centimeters = 169 The given height 169 cm in inches = 66.59 inches The given height 169 cm in feet = 5.54 feet
Explanation:
- As the height can be in decimals we take input using float(input()) function.
- The height in centimeters is multiplied by 0.394 and saved in a new variable called height in inches.
- The height in centimeters is multiplied by 0.0328 and saved in a new variable called height in feet.
- It is printed the conversion height in inches and feet.
Related Programs: