-1
votes

I just started using python a week ago although I have some background in C++. I'm just making some simple user defined functions. Code is below.

def quads():
    print "We are going to solve polynomials using the standard quadratic formula.  Imagine ax^2+bx+c=0"
    a = input('enter a: ')
    b = input('enter b: ')
    c = input('enter c: ')
    root=(b**2)-(4*a*c)
    root=root**.5
    results=(-b+root)/(2*a)
    return results

after I open the compiler I import the file that holds the function, then call the function and I get some very strange output. See below

import quadratic
quadratic.quads
<function quads at 0x02AC6AB0>

has anyone ever seen this input. I usually just google my issues and find an easy fix, but I haven't found anything on this. I have written two or three simple functions but all are returning a similar output.

2
Change your code to quadratic.quads(), so that you are calling the function - David Robinson

2 Answers

1
votes

Like David Robinson said in his comment, I think the function will run correctly if you enter

quadratic.quads()

This runs it as a function, as all functions have the two parentheses. Without it, it would be considered a variable in a class.

0
votes

You need to use () to call the function.

Here's a simple test example of defining a trivial function and then calling it using use the name and then the name with () to illustrate the difference:

Python 2.7.3 (default, Dec 18 2014, 19:10:20) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def my_func():
...     print "yo!"
... 
>>> my_func
<function my_func at 0x7f3c84c74578>
>>> my_func()
yo!
>>>