我试图找到一个最大的立方根,它是一个整数,小于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)
我不知道怎么检查它是否是一个整数但是!我可以将它转换为字符串然后使用索引来检查结束值并查看它们是否为零,但这似乎相当麻烦.有更简单的方法吗?
我正在制作一个数学求解程序,它将整数打印为小数.像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) 例如
def asdf(x):
return (x / 2)
asdf(4.0)
asdf(5.0)
Run Code Online (Sandbox Code Playgroud)
的返回值 2.0将被转换为2而2.5不会被转换为2.