def neg(formula: list):
if formula[3] == "-":
formula[4] = float("-" + str(formula[4]))
formula[3] = "+"
def conv(lis: list) -> list:
if len(lis) == 3:
lis += ["+", "0"]
lis[2] = float(lis[2])
lis[4] = float(lis[4])
return lis
def process(cmd: str, formula: list):
cmd = cmd.split(" ")
if len(cmd) == 3:
if cmd == ["x", "=", cmd[2]]:
neg(formula)
print("y =", float(cmd[2]) * formula[2] + formula[4])
elif cmd == ["y", "=", cmd[2]]:
neg(formula)
print("x =", (float(cmd[2]) - formula[4])/formula[2])
elif cmd == ["y-intercept"]:
print(formula[4])
elif cmd == ["x-intercept"]:
if formula[3] == "-":
formula[4] = float("-" + str(formula[4]))
print((0 - formula[4])/formula[2])
elif cmd == ["run", cmd[1]]:
for i in range(int(cmd[1])):
print("(" + str(i) + ", " + str(i * formula[2] + formula[4]) + ")")
formula = conv(input("Type the formula:\n").replace("x", "").split(" "))
print("\nCommands:")
while True:
process(input(), formula)
print()