I am making a math solving program, it keeps printing the whole numbers as decimals. Like 1 is 1.0, 5 is 5.0, and my code is:
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.")
Since you're dividing integers, Python represents the result as a float
, not as an int
. To format the float
s as you'd like, you'll have to use string formatting:
>>> print('{:g}'.format(3.14))
3.14
>>> print('{:g}'.format(3.0))
3
So plugging it into your code:
print("Y = {:g}X - {}.".format(m, b))
Try this,
> x = 10.0
> print int(x)
10
> print x
> 10.0
Is this what you are really looking for?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With