Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
class Solution:
def remove(self,arr,target):
if target in arr:
arr.remove(target)
remove(arr,target)
return len(arr),arr
else:
return "not in the array"
ans=Solution()
print(ans.remove([3,2,2,3],3))
This is the Error
Traceback (most recent call last):
File "c:\Users\ashut\Practice\scrap.py", line 10, in <module>
print(ans.remove([3,2,2,3],3))
File "c:\Users\ashut\Practice\scrap.py", line 5, in remove
remove(arr,target)
NameError: name 'remove' is not defined
Somehow the above program runs in google colab and I've tried restarting the runtime
You have to add the "self" tag before calling the function inside ur function.
class Solution:
def remove(self,arr,target):
if target in arr:
arr.remove(target)
self.remove(arr,target)
return len(arr),arr
else:
return "not in the array"
ans=Solution()
print(ans.remove([3,2,2,3],3))
The temp variable name is arr, is that mean Array?
If so, the code "remove(arr, target)" is no need, remove this line, is OK.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I want to call a function (my_function), where clearly in my code I am calling it but if the function is not executing.
Someone knows what this is??
Here is my code:
import pandas as pd
my_variable = "1"
if my_variable == "1":
my_function()
global my_function
def my_function():
def tryloc(df, col, idx, default=None):
try:
return df.iloc[col, idx]
except IndexError:
return default
print("hello")
edit = pd.read_csv("priv/productos.csv")
product = tryloc(edit, 1, 0)
print(product)
and the second problem is that it says that this function does not exist when I am declaring it globally
Thanks if you answer!
Despite popular belief, "it's not working" isn't adequate information to diagnose a problem. That said, you are calling the function before it is even declare. You must declare a function before it can be called, always.Try moving
myFunction();
after where you defined it. But, there is a lot more going on here that's wrong and the question doesn't explain what the desired outcome is so I'm not sure how to help. I recommend going back and checking out some python scope documents.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
In the following code, if I run it on IDLE, it gives me no outcome.
But with the command return True, wasn't supposed to give me True on the outcome?
Or do I have to add something like print True?
data = [2,4,5,7,8,9,12,14,17,19,22,25,27,28,33,37]
target = 28
#Linear Search
def linear_search(data, target):
for i in range(len(data)):
if data[i] == target:
return True
return False
Only defining the function is not enough you also need to call it.
In your case so add following:
print(linear_search(data,target))
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
my project error showing exit button? what can i do...i checked more times
def iExit():
iExit = tkinter.messagebox.askyesno("Customer Billing system","Confirm if you want to exit")
if iExit > 0:
root.destoy()
return
Error....
t__.py", line 2095, in __getattr__
return getattr(self.tk, attr)
AttributeError: '_tkinter.tkapp' object has no attribute 'destoy'
It is grammatical mistakes.check the spelling of destroy...
After if `iExit > 0:` check this `root.destroy()`
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
While testing some code, I was given an error:
TypeError: breadth_first_search() takes from 2 to 3 positional arguments but 4 were given
The parameter bit of the function declaration looks like this:
def breadth_first_search(self, id: int, level=None)
The call looks like this:
tree.breadth_first_search(parent_id)
As far as I'm aware, this should be correct. I don't know why it would interpret my one argument (or two, including self) as four. Is there something plain that I'm missing?
--
For completeness, here's the traceback:
Traceback (most recent call last):
File "test.py", line 4, in <module>
tree = FeatureQuery.load_feature_tree("general", inventory)
File "D:\Speechcraft\Python\core\ling_query.py", line 201, in load_feature_tree
FeatureQuery.load_feature_node_recursive(feature_inventory, tree, results, l)
File "D:\Speechcraft\Python\core\ling_query.py", line 221, in load_feature_node_recursive
parent = tree.breadth_first_search(parent_id)
File "D:\Speechcraft\Python\core\phonological_units.py", line 37, in breadth_first_search
return self.breadth_first_search(self, id, next_level)
TypeError: breadth_first_search() takes from 2 to 3 positional arguments but 4 were given
It turned out to be a silly mistake. I accidentally included self as a parameter in the recursive call. Thanks go to user2357112 supports monica.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
regardless of what the functions have to return, my code seems to not call the first function properly, as when I try to pass some doctest it raises the error:
File "preg3.py", line 27, in mesDivisions
if nombreDivisions(llista[0],m)>=nombreDivisions(llista[1],m):
NameError: global name 'nombreDivisions' is not defined
here is my code:
def nombreDivisons(n,m):
x=0
def aux(n,m):
if n<m:
return x
else:
if n%m==0:
x=x+1
return aux(n/m,m)
else:
return x
def mesDivisions(llista,m):
if len(llista)==1:
return llista[0],nombreDivisions(llista[0],m)
else:
if nombreDivisions(llista[0],m)>=nombreDivisions(llista[1],m):
del llista[1]
return mesDivisions(llista,m)
else:
del llista[0]
return mesDivisions(llista,m)
any ideas why?
Check your white space. You want at least one and according to pep8 two blank lines between functions.
You failure is a typo though. It should be nombreDivisions but you left out the i so it is nombreDivisons.