Mar-24-2022, 06:09 AM
There is so much wrong that this really can't be called Python code.
In response to one of your earlier posts I mentioned that you do not define functions inside loops. Instead of this:
Syntax errors are not exceptions, they are invalid code. You need to correct the code. Try/except cannot catch a syntax error because syntax errors prevent running your program.
You should not use == when comparing float numbers. Your equation may return a value really close to zero, but it is unlikely any combination of arguments will produce a result that is exactly zero. That is just the nature of floating point math on computers; ridiculous resolution, but almost never results that are exactly right. Read about it here:
https://docs.python.org/3/tutorial/floatingpoint.html
Instead of testing == 0, use math.is_close() or numpy.is_close().
https://docs.python.org/3/library/math.html
https://numpy.org/doc/stable/reference/g...close.html
In response to one of your earlier posts I mentioned that you do not define functions inside loops. Instead of this:
for i in range(10): def square(): return i**2Do this:
def square(number): # Declare function outside of loop return number**2 for i in range(10): print(square(i)) # Call function inside of loop.I don't know what you are trying to do with this:
try: ht == 0 if True: lh0 = i, o[0], o[1], l return lh0 print(lh0) except: passAre you trying to do this?
if ht == 0: return i, o[0], o[1], ltry/except catch exceptions. An exception is raised when your program tries to do something but fails. An example is trying to open a file. Your program has a reasonable expectation that opening a file should work, but maybe the file was deleted. Exceptions are not used to fix bad code, they are used to handle potential errors that can occur when executing correct code.
Syntax errors are not exceptions, they are invalid code. You need to correct the code. Try/except cannot catch a syntax error because syntax errors prevent running your program.
You should not use == when comparing float numbers. Your equation may return a value really close to zero, but it is unlikely any combination of arguments will produce a result that is exactly zero. That is just the nature of floating point math on computers; ridiculous resolution, but almost never results that are exactly right. Read about it here:
https://docs.python.org/3/tutorial/floatingpoint.html
Instead of testing == 0, use math.is_close() or numpy.is_close().
https://docs.python.org/3/library/math.html
https://numpy.org/doc/stable/reference/g...close.html
if math.isclose(ht, 0, abs_tol=1.0e-9)Try to clean up some of these errors and if you are still having problems post your updated code and an explanation of what you are trying to do. Last time I tried to help I was hindered by never really knowing what you wanted to do, and your code was not helping my understanding.