将以米为单位的高度转换为英尺和英寸?

2024-05-13 19:02:15 发布

您现在位置:Python中文网/ 问答频道 /正文

问题是:

Given that 1 foot = .3048 meters, write a Python script that will convert a height given meters to a height given in feet and inches.

我看了教授那天给我的笔记,我正在按照每一步做,但我的程序似乎没有正常工作。以下是我所拥有的:

print("This program will convert a height given meters to a height given in feet and inches.")
meters = float(input("Enter height in meters:"))
meters_in_ft = meters // .3048
meters_in_in = meters_in_ft % 12
print("The height is", meters_in_ft,"feet and",meters_in_in, "inches")

当我运行程序并输入特定的米数时,我会得到正确的英尺数,但很多时候以英寸为单位的测量是错误的。


Tags: andtoin程序convertthatwillgiven