相关疑难解决方法(0)

如何检查浮点值是否为整数

我试图找到一个最大的立方根,它是一个整数,小于12,000.

processing = True
n = 12000
while processing:
    n -= 1
    if n ** (1/3) == #checks to see if this has decimals or not
Run Code Online (Sandbox Code Playgroud)

我不知道怎么检查它是否是一个整数但是!我可以将它转换为字符串然后使用索引来检查结束值并查看它们是否为零,但这似乎相当麻烦.有更简单的方法吗?

python floating-point

167
推荐指数
8
解决办法
20万
查看次数

如何制作python print 1而不是1.0

我正在制作一个数学求解程序,它将整数打印为小数.像1是1.0,5是5.0,我的代码是:

print("Type in the cooridinates of the two points.")
    print("")
    print("---------------------")
    print("First point:")
    x1 = int(input("X: "))
    y1 = int(input("Y: "))
    print("")
    print("---------------------")
    print("Second point:")
    x2 = int(input("X: "))
    y2 = int(input("Y: "))
    m = (y1-y2) / (x1-x2)
    b = y1 - m * x1
    round(m, 0)
    round(b, 0)
    print("Completed equation:")
    print("")
    if b < 0:
        print("Y = "+ str(m) +"X - "+ str(b) +".")
    elif b > 0:
        print("Y = "+ str(m) +"X + "+ str(b) +".")
    elif b …
Run Code Online (Sandbox Code Playgroud)

python int

2
推荐指数
1
解决办法
5429
查看次数

如果数学上是 int,如何将 float 更改为 int?2.0 -&gt; 2. 2.5 -&gt; 2.5

例如

def asdf(x): 
    return (x / 2) 


asdf(4.0)
asdf(5.0)
Run Code Online (Sandbox Code Playgroud)

的返回值 2.0将被转换为22.5不会被转换为2.

python

0
推荐指数
1
解决办法
69
查看次数

标签 统计

python ×3

floating-point ×1

int ×1