Let's say I define the following function:
def roots(a,b,c):
top = (b*b - 4*a*c)**0.5
p1 = (- b + ( top ) )/(2*a)
p2 = (- b - ( top ) )/(2*a)
print(p1)
print(p2)
I want to be able to call roots(a,b,c) inside the python shell. How can I accomplish this?
I expect the result to be something like.
Python 3.8.6 (tags/v3.8.6:db45529, Sep 23 2020, 15:52:53) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> roots(2,3,1)
-0.5
-1.0
>>>
python3 -i your_file.pyit opens an interpreter session with the function available in scope. Otherwise you can just start an interpreter and runfrom your_file import rootswhich should be enough.