Syntax error using def on python [closed] - python

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()

Related

Why does class object have no attribute [closed]

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__.

printing data member using class name [closed]

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_.

Django TypeError: 'Library' object is not callable [closed]

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'm upgrading code to the latest version of Django Version: 3.1.2
from django.template import Variable, Library
register = Library()
def striplinebreaks(value, arg):
"""
Removes all values of arg from the given string.
"""
safe = isinstance(value, SafeData)
value = value.replace('\n', u'').replace('\r', u'').replace('\t', u'')
if safe and arg != ';':
return mark_safe(value)
return value
register('striplinebreaks')
getting this error
File "/home/sam/code/kpsga/lamusoftware/generic/templatetags/striplinebreaks.py", line 18, in <module>
register(striplinebreaks)
TypeError: 'Library' object is not callable

TypeError: __init__() takes exactly 4 arguments (5 given)udacity [closed]

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.

Python indented block error [closed]

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

Categories

Resources