1
def height(cent):
height= {}
height["feet"]= int(cent/30.48)
height["inch"]= int(cent%30.48)/2.54
print (height)
height (182.88)
print (182.88/30.48)
print (182.88%30.48)
的输出是: { '英寸':11,脚':6}问题与Python模
6.0
30.479999999999993
为什么182.88%30.48不等于零?
你为什么期待它呢? '182.88/30.48'是6.033,而不是6。 – chepner
[Similar questions/answer](https://stackoverflow.com/questions/14763722/python-modulo-on-floats) – Kyle
做尽可能少的浮点运算。计算'h = int(cent/2.54)',然后用整数运算来计算'feet,inches = divmod(h,12)'。 – chepner