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 years ago.
Improve this question
I had an indented block error on line 4:
from SimPy.Simulation import *
from random import uniform
class Car(Process):
def init(self,id):
Process.init(self)
self.id=id
def carDriving(self,driveTime):
...
What might be causing it?
You have to indent classes and functions:
from SimPy.Simulation import *
from random import uniform
class Car(Process):
def __init__(self, id):
Process.init(self)
self.id = id
def carDriving(self, driveTime):
# do something here
pass
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 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_.
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()