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 12 months ago.
Improve this question
class Acc:
id=121
def _init_(self,id):
self.id=id;
acc=Acc(111)
print(Acc.id)
When I try to run this code , the code runs fine and gives 121 as output when I directly call the data member 'id' using class name Acc and remove the object creation line from the code but the code gives error "TypeError: Acc() takes no arguments" when I include the second last line i.e. the object creation line in my code.
You need to use double underscores when creating constructor method:
...
def __init__(self, id):
...
In your question code you just created a method _init_.
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 6 months ago.
Improve this question
I am trying to create a class object to reverse the given list.
Example: Input = [1,2] and the expected output will be [2,1]
This is my code:
class ListNode(object):
def __init__(self, nums):
self.nums = nums
def tryout (self):
self.nums.reverse()
print(self.nums)
p = ListNode([1,2])
p.tryout
However when I ran my code on Leetcode, it kept giving me the error below
NameError: global name 'Solution' is not defined
ret = Solution().reverseList(param_1)
Line 33 in _driver (Solution.py)
_driver()
Line 43 in <module> (Solution.py)
Can I check if there's any issue with my code? i tried to run on Jupyter and the codes work but it didnt work when i submit to Leetcode
Sounds like Leetcode is expecting your class name to be Solution and your method name to be reverseList
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 7 months ago.
Improve this question
Trying to build a Trie branch. I have looked at my indentation and there are no spaces, just tabs for that. I have also looked at other answers which either aren't reproducible or have no effect. What am I doing wrong? I expect the following outcome:
*
trie.py
class Trie:
def __int__(self):
self.root = '*'
main.py
import trie_test
if __name__ == '__main__':
trie = trie_test.Trie()
print(f'trie root: {trie.root}')
Error
line 13, in <module>
print(f'trie root: {trie.root}')
AttributeError: 'Trie' object has no attribute 'root'
def __int__ should be def __init__.
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 4 years ago.
Improve this question
Oh that's true. And now that code works but my long code still doesn't. Here it is https://pastebin.com/Z4qjGxCU. The problem with this one is that, when I call check_num() on the tiles, it works. But when I call check_mouse(), load_image() [which I've commented so you don't have to download the assets] or print_tile() they return an error such as this:
Traceback (most recent call last):
File "C:\Users\sergio\Desktop\Minesweeper\minesweeper.py", line 96, in <module>
grid[i][j].check_mouse()
AttributeError: 'Tile' object has no attribute 'check_mouse'
I've checked the code but I can't find anything that's wrong. Any ideas?
Define a class with class A: instead of def A()
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 4 years ago.
Improve this question
enter code here
class Movie() :
def __init__(self, movie_title, move_storyline , trailer_youtube):
self.title = movie_title
self.storyline = move_storyline
self.poster_image_url = poster_image_url
self.trailer_youtube_url = trailer_youtube
whats the erorr here !
You write self.poster_image_url = poster_image_url but you seem to have forgotten to include poster_image_url in your parameters to __init__. Add it and the number of arguments and parameters will match correctly.
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 8 years ago.
Improve this question
My qestion is that my def kept on getting a invalid syntax.
l=0
a=1
b=1
i=int(input("How many iterations?" )
def mains():
while i>l;
l=l+1
a=a+b
print(a)
def mains()
Here is the error.
File "Fibonacci.py", line 6
def mains():
^
SyntaxError: invalid syntax
I am currently using 3.4.1 version of python.
Well firstly you have incomplete ) on the previous line:
i=int(input("How many iterations?" ))
^
and secondly, it should be : not ;:
while i>l:
and thirdly, to call a method, you just do:
mains()
not def mains()