Computer Science, asked by ArizonaStark, 1 year ago

write a python program to accept hieght in centimeters and convert that into feet and inches​

Answers

Answered by fiercespartan
6

To do this, let's go to the basics first:

1 feet = 30.48 cm

1 inch = 2.54 cm

We will be using 2 mathematical operations in this program.

1) / --- This operation stands for division, it returns decimals too

2) // --- This operation is also division but returns only whole numbers. For example, 3/2 is 1.5 but, 3//2 is just 1.

We will be using // for the feet, because, feet should always be a whole number when it comes to height.

CODE:

height = input('Enter your height:')

feet = height//30.48

inches = (height - (feet*30.48))/2.54

print(f'You are {feet} feet and {inches} inches')

_______________________________________________

Answered by Equestriadash
20

The following codes will have to be typed in script mode, saved and then executed.

There are two possible codes. One is to assign the formula to a variable. The other is to directly type the fomula in the print statement.

CODE 1:

x = float(input("Enter your height [in centimeters]:"))

feet = x/30.48

inches = x/2.54

print("Your height in feet is", feet, "whereas your height in inches is", inches)

CODE 2:

x = float(input("Enter your height [in centimeters]:"))

print("Your height in feet is", x/30.48,"whereas your height in inches is", x/2.54)

Both codes will display the same output. You can choose to assign it to a variable or directly type in the required logic.

Similar questions