问题是:
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")
当我运行程序并输入特定的米数时,我会得到正确的英尺数,但很多时候以英寸为单位的测量是错误的。
要从米中获取英寸部分,需要使用
% 1
来获取meters / .3048
的小数部分。然后你可以通过乘以12
把它转换成英寸。相关问题 更多 >
编程相关推荐