samedi 25 avril 2020

Bad Argument type for built-in error Python

I'm writing a Python script as a school exercise. It should be able to solve linear 2x2 and 3x3 equations. I check if there's for example only +y to make it +1y. This works without any issues if I run the script but if I debug it I get an TypeError when I compare strings in an if statement. This is my code:

step11 = equation1.split("=")
if step11[0][0] == "x" or step11[0][1] == "x":
    if step11[0][0] == "x":
        step11[0] = step11[0][:0] + '1' + step11[0][0:]
    elif step11[0][0] == "-" and step11[0][1] == "x":
        step11[0] = step11[0][:1] + '1' + step11[0][1:]
step12 = step11[0].split("x")
if step12[1][0] == "y" or step12[1][1] == "y":
    if step12[1][0] == "y":
        step12[1] = step12[1][:0] + '1' + step12[1][0:]
    elif step12[1][0] == "-" and step12[1][1] == "y":
        step12[1] = step12[1][:1] + '1' + step12[1][1:]
step13 = step12[1].split("y")

I get the error in line 8:

if step12[1][0] == "y" or step12[1][1] == "y":

I don't understand why this error occurs and why it's only occurring in debug mode. How could I solve this issue?

Edit: The linear equations are like that: ax+by=c dx+ey=f

Aucun commentaire:

Enregistrer un commentaire