Monday 28 December 2020

Python Program to Read Height in Centimeters and then Convert the Height to Feet and Inches

 This is a Python Program to read height in centimeters and then convert the height to feet and inches

Problem Description

The program reads the height in centimeters and then converts the height to feet and inches.

Problem Solution

1. Take the height in centimeters and store it in a variable.
2. Convert the height in centimeters into inches and feet.
3. Print the length in inches and feet.
4. Exit.

Program/Source Code

Here is source code of the Python Program to Calculate the Average of Numbers in a Given List. The program output is also shown below.

 
cm=int(input("Enter the height in centimeters:"))
inches=0.394*cm
feet=0.0328*cm
print("The length in inches",round(inches,2))
print("The length in feet",round(feet,2))
Program Explanation

1. User must enter the height in centimeters.
2. The height in centimeters is multiplied by 0.394 and stored in another variable which now contains the height in inches.
3. The height in centimeters is multiplied by 0.0328 and stored in another variable which now contains the height in feet.
4. The converted height in inches and feet is printed.

Runtime Test Cases
 
Case 1:
Enter the height in centimeters:50
The length in inches 19.7
The length in feet 1.64
 
Case 2:
Enter the height in centimeters:153
The length in inches 60.28
The length in feet 5.02

No comments:

Post a Comment