Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
def awesome_count():
if 'awesome' in dict:
return 1
else:
return 0
products['awesome']= products['word_count'].apply(awesome_count)
TypeError: awesome_count() takes no arguments (1 given)
what is the issue with calling the function. can somebody help?
Looks like your awesome_count function should take one argument, dict:
def awesome_count(dict):
....
You should really call it something besides dict though as that is a built-in data type. For something simple like this d would be fine.
Another thing to keep in mind is that Python is not javascript -- there is no apply method on dicts unless you have subclassed and added it yourself.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 months ago.
Improve this question
my question is how to take input from user in below code.I got error in this code (missing 1 required positional argument).
First consider copy and paste the code here instead of sending a link to image.
Then, your problems is that you are not passing the variable you called balance inside your functions that need to have a parameter.
so in line 19 instead of writing cust.deposit(), write this instead cust.deposit(balance) or cust.deposit(55).
Of course you need first to create an object of account in the right way. i.e. creating it with parameters it needs and that you defined in the class. e.g.
cust = Account(acno, name, balance)
and then: have your functions, e.g.:
cust.deposit(55)
You need to pass your variables as arguments to Account() as they are expected in the init.
Try
cust1 = Account(acno, name, balance)
and then
cust1.deposit(50) # or any other amount
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
Last question about this topic.
I didn't add the output as its not the issue rather then passing of the output. Basically the final output of each function is a list. I am running into a problem. So this is the code I have
def mean(studentp_file):
li = []
for line in studentp_file:
nameless = line[1:14]
for l in range(len(nameless)):
answer = sum(nameless)/len(nameless)
li.append(answer)
li.insert(0,"Needie Seagoon")
li.insert(2,"Eccles")
li.insert(4,"Bluebottle")
li.insert(6,"Henry Crun")
li.insert(8,"Minnie Bannister")
li.insert(10,"Hercules Grytpype-Thynne")
li.insert(12,"Count Jim Moriarty")
li.insert(14, "Major Dennis Bloodnok")
mean_li = li
return mean_li
passing_file = normalise("DB.csv.", "units.csv")
mean(passing_file)
"""
This function will print out the final mean average percentile for each student over
their computer science degree.
"""
def final(mean_li):
~ wanted to see if the code worked.~
print(mean_li)
mean_list = mean(studentp_file)
final(mean_list)
The problem I am having is passing the variable mean_li into the new function final(). I get the error mean_list = mean(student_file) is not defined? I was able to pass output of another function into the previous function but for some reason I can't do it here.
Any help would be great.
I guess the error is studentp_file is not defined. The variable studentp_file is only valid inside the definition of function mean. Outside of that function, you are using passing_file variable. This should work
mean_list = mean(passing_file)
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Suppose I have this code in Python:
def subThread():
libc.foo(56)
def mainThread():
libc.foo(56)
child = threading.Thread(target=subThread)
child.start()
and in C, foo would look like:
void foo(int a){
printf("foo: %d\n", a);
}
by executing the python program, I would end up with this output
foo: 56
foo: 130810240
Have anyone encountered this situation before? Is there any solution to this?
Thanks in advance.
How did you compile your C function to work with python? This method (https://docs.python.org/2/extending/extending.html) requires more complex argument parsing on the C side.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have this function:
def a(one, two, the_argument_function):
if one in two:
return the_argument_function
my the_argument_function looks something like this:
def b(do_this, do_that):
print "hi."
Both of the above are imported to a file "main_functions.py" for my ultimate code to look like this:
print function_from_main(package1.a, argument, package2.b(do_this, do_that)
The "if one in two" from "a"function works but "b"function still executes when being passed to "function_from_main" without waiting the check from "a" to see if it actually should execute.
What can I do?
package2.b(do_this, do_that) is a function call (a function name followed by parenthesis). Instead you should be passing only the function name package2.b the function a
You will also need to modify function a such that function be is called when the condition is satisfied
# function a definition
def a(one, two, the_argument_function, argument_dict):
if one in two:
return the_argument_function(**argument_dict)
def b(do_this, do_that):
print "hi."
# function call for a
a(one, two, b, {'do_this': some_value, 'do_that': some_other_value})
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am new to coding Python and I just can't seem to understand what a Def function is! I have looked and read many tutorials on it and I still don't quite understand. Can somebody explain to me what it is, what I use it for, and give me some examples. For the examples please make them easy and understandable for a newb to Python. Thanks!
def isn't a function, it defines a function, and is one of the basic keywords in Python.
For example:
def square(number):
return number * number
print square(3)
Will display:
9
In the above code we can break it down as:
def - Tells python we are declaring a function
square - The name of our function
( - The beginning of our arguments for the function
number - The list of arguments (in this case just one)
) - The end of the list of arguments
: - A token to say the body of the function starts now
The following newline and indent then declare the intentation level for the rest of the function.
It is just as valid (although uncommon) to see:
def square(number): return number * number
In this case, as there is no indentation the entirety of the function (which in this case is just one line) runs until the end of line. This is uncommon in practise and not considered a good coding style.