0

Here's the code:

x = float(input("x1 = "))

y = float(input("y1 = "))

print ("your first point is " + str(x) + ", " + str(y))

tx = float(input("x2 = "))

ty = float(input("y2 = "))

print ("your second point is " + str(tx) + ", " + str(ty))

rise = ty / y

run = tx / x

slope = rise / run

tf = str(input("is these the correct points? - " + str(x) + "," + str(y) + " - " + str(tx) + "," + str(ty) + ": "))

if tf == str("yes") or str("Yes") or str("Y") or str("y") or str("oui"):
    rise = ty / y

run = tx / x

slope = rise / run

if x == tx:
    print("vertical line - slope underfined")

elif y == ty:
    print("horizontal line, slope = 0")

else:
    print ("slope of line is " + str(slope))


if tf == str("no") or str("No") or str("NO") or str("n") or str("N") or str("non"):
    print("understood, now restate points")
    x = float(input("x1 = "))

y = float(input("y1 = "))

print ("your first point is " + str(x) + ", " + str(y))

tx = float(input("x2 = "))

ty = float(input("y2 = "))

print ("your second point is " + str(tx) + ", " + str(ty))

rise = ty / y

run = tx / x

slope = rise / run

if x == tx:
    print("vertical line - slope underfined")

elif y == ty:
    print("horizontal line, slope = 0")

else:
    print ("slope of line is " + str(slope))

I expected it to end the program after entering "y" or "yes", but it continues.

TheOneMusic
  • 1,776
  • 3
  • 15
  • 39
bo_mor11
  • 3
  • 2

1 Answers1

0

That's because your if conditions are not correct. When comparing a variable with multiple possibilities, you should == for each one or use in with the list or tuple of possible values after it.

By the way, you don't need to wrap string with str() in python. So str("hello") and "hello" are the same.

Updated code:

x = float(input("x1 = "))
y = float(input("y1 = "))
print("your first point is " + str(x) + ", " + str(y))

tx = float(input("x2 = "))
ty = float(input("y2 = "))
print("your second point is " + str(tx) + ", " + str(ty))

rise = ty / y
run = tx / x
slope = rise / run

tf = input("is these the correct points? - " + str(x) + "," + str(y) + " - " + str(tx) + "," + str(ty) + ": ")

if tf in ("yes", "Yes", "Y", "y", "oui"):
    rise = ty / y

run = tx / x
slope = rise / run

if x == tx:
    print("vertical line - slope underfined")
elif y == ty:
    print("horizontal line, slope = 0")
else:
    print("slope of line is " + str(slope))

if tf in ("no", "No", "NO", "n", "N", "non"):
    print("understood, now restate points")
    x = float(input("x1 = "))

y = float(input("y1 = "))
print("your first point is " + str(x) + ", " + str(y))

tx = float(input("x2 = "))
ty = float(input("y2 = "))
print("your second point is " + str(tx) + ", " + str(ty))

rise = ty / y
run = tx / x
slope = rise / run

if x == tx:
    print("vertical line - slope underfined")
elif y == ty:
    print("horizontal line, slope = 0")
else:
    print("slope of line is " + str(slope))
TheOneMusic
  • 1,776
  • 3
  • 15
  • 39