0

My question is how I can fix the following: I can get the right m and b value for the equation of the line but how do I print it in that format.

`import math
m=0
b=0
point1X = int(input("Input the first x value of a point in the line...."))
point1Y = int (input("Input the first y value of a point in the line...."))

point2X = int(input("Input the second x value of a point in the line...."))
point2Y = int (input("Input the second y value of a point in the line...."))


def equation (m,b):
    m = (point2Y-point1Y)/(point2X-point2Y)
    b = point1Y - (m*point1X)
    return (m,b)
print (equation(m,b))
print (m,'x''+',b)`

3 Answers3

1

You can also use string formatting in one of the various forms

print("{m}x + {b}".format(m=m, b=b))
print("{}x + {}".format(m, b))

or

print("%dx + %d" % (m, b))
0

You need to set (m, b) equal to the output of your equation function:

(m, b) = equation(m, b)
print(m,'x +',b)
Derek O
  • 16,770
  • 4
  • 24
  • 43
0

You can also use a formatted print like this:

print(f'{m}x + {b}')

The f in front of the string says that it is formatted, and then you can use the variable names as you would normally between the curly braces.

Hunter
  • 201
  • 3
  • 17