Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13951

Errors with quadratic formula and multithreading in Python

$
0
0

My code:

import mathimport threadingA = input("What is your a? ")B = input("What is your B? ")C = input("What is your C? ")a = int(A)b = int(B)c = int(C)def Quad_pt1():    Pt1 = b*-1    return Pt1def Quad_pt2():    Pt2 = math.sqrt(pow(2, b)-(4*a*c))    return Pt2def Quad_pt3():    Pt3 = 2*a    return Pt3t1 = threading.Thread(target=Quad_pt1())t2 = threading.Thread(target=Quad_pt2())t3 = threading.Thread(target=Quad_pt3())t1.start()t2.start()t3.start()t1.join()t2.join()t3.join()print(t1, t2, t3)exit()print((Pt1+Pt2)/Pt3)print((Pt1-Pt2)/Pt3)

I have the exit function there to terminate before the other print statements as I don't need them right now. My output is:

What is your a? 23What is your B? 26What is your C? 73<Thread(Thread-1, stopped 6149271552)> <Thread(Thread-2, stopped 6166097920)> <Thread(Thread-3, stopped 6182924288)>Exception in thread Thread-1:Traceback (most recent call last):  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1038, in _bootstrap_innerException in thread Thread-2:Traceback (most recent call last):  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1038, in _bootstrap_innerException in thread Thread-3    self.run():Traceback (most recent call last):  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1038, in _bootstrap_inner  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 975, in run    self.run()  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 975, in run    self.run()  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 975, in run    self._target(*self._args, **self._kwargs)TypeError    self._target(*self._args, **self._kwargs)TypeError: 'int' object is not callable: 'float' object is not callable    self._target(*self._args, **self._kwargs)TypeError: 'int' object is not callableProcess finished with exit code 0

It would also helpful to find a fix for handling numbers that would result in a squaring issue:

What is your a? 1What is your B? 1What is your C? 1Traceback (most recent call last):  File "/Users/sterlingrussell/PycharmProjects/many math solvers/quadratic formula.py", line 19, in <module>    t2 = threading.Thread(target=Quad_pt2())                                 ^^^^^^^^^^  File "/Users/sterlingrussell/PycharmProjects/many math solvers/quadratic formula.py", line 13, in Quad_pt2    Pt2 = math.sqrt(pow(2, b)-(4*a*c))          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ValueError: math domain errorProcess finished with exit code 1

In some cases, I get an error saying that my integer is too big to convert to float. Any suggestions on how to fix that? I realize I will not be dealing with numbers greater than 100k, but the program should be able to handle large inputs.


Viewing all articles
Browse latest Browse all 13951

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>