Python: 有没有办法 'cleanly' 除两个 float 和 int 类型的数字?

Python: is there a way to 'cleanly' divide two numbers of type float and int?

python 的新手,面临的问题基本上与求余“%”函数相反。例如,如果我想将 81.5 除以 20,我的输出将是 4。我最好的尝试如下:

amount = 81.504
round(amount, 2)

num20s = amount / 20
int(num20s)

我尝试了上述代码的几种不同组合,但到目前为止没有任何效果。这是我最接近我想要的,但它在边缘情况下不起作用,并且由于某种原因仍然代表末尾带有“.0”的数字,所以最后一行不能做任何事情.

python 中的整数除法运算符是“//”。

>>> amount = 81.504
>>> amount // 20
Out[3]: 4.0
>>> int(amount // 20)
Out[4]: 4