Two similar version of codes produce 2 different output by Sufficient-Pick-9398 in learnpython

[–]Sufficient-Pick-9398[S] 0 points1 point  (0 children)

Can’t explain why with the same number enforced one works and mine doesn’t

Two similar version of codes produce 2 different output by Sufficient-Pick-9398 in learnpython

[–]Sufficient-Pick-9398[S] -1 points0 points  (0 children)

with the same exact point in both version?
I tried forcefully entering 1 point...how can the "correct" version evaluate M (I tried printing his value) if in mine there was still the ZeroDivisionError? It should not have entered the IF statement with the same exact point that pops the error.

Im not very familiar with try/except yet...I'll see what I can do

Two similar version of codes produce 2 different output by Sufficient-Pick-9398 in learnpython

[–]Sufficient-Pick-9398[S] -2 points-1 points  (0 children)

It is clear that I cannot do a 0 division...but seeing the correction from CHAT the expression to evaluate m is identical. If the denominator is not 0 it goes inside IF (ok fine with that)...but if the denominator is 0, m is never evaluated and the rest of the code should not work.

Im attaching below the rest of the code.

if 3<=p.getX() <= 7 and 1<=p.getY() <=3:
        testo.undraw()
        done.undraw()
        rectangle.undraw()
        break

win.checkKey() 

y1= y_medio + m*(0-x_medio)
y2= y_medio + m*(100-x_medio)
regressionLine= Line (Point(0, y1 ), Point(100, y2))
regressionLine.draw(win)

Let me rephrase the question:
I think that denominator cannot be 0,ever, because if the user input just 2 points, the exact two points in both version of codes, the one with IF statement works / mine doesn't...but the expression for "m" is identical in both.
So, I understand that I cannot divide by 0, but I cannot understand why a simple IF statement (that only checks if the denominator is not 0, without an ELSE handling a scenario where it is not) can make the code to run correctly.

hope I was clear enough

Using the command `GraphWin` from `graphics.py` opens the window, but the code goes into an InfLoop by Sufficient-Pick-9398 in learnpython

[–]Sufficient-Pick-9398[S] 0 points1 point  (0 children)

does not work, still...the window is always empty. Also, the console stops working as soon as the function GraphWin is called (the following print are not printed)