我正在制定一个数学解决方案,它不断打印整数作为小数。像1是1.0,5是5.0,我的代码是:如何使蟒蛇打印1而不是1.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 == 0:
print("Y = "+ str(m) +"X.")
input("Press enter to continue.")
非常感谢,只是测试它,它的工作。感谢您让我的第一篇文章愉快! –
没问题。祝你程序顺利! – Blender
您可能想要显示''{:g}''和''{:.0g}''之间的区别,因为我认为后者可能是他真正想要的。 (值得指出的是,他已经试图将他的数字舍入到最接近的整数,但它不起作用。) – abarnert