__init__() Takes Exactly 2 Arguments (1 Given)?
Solution 1:
Your Student_Record.__init__()
method takes two arguments, self
and s
. self
is provided for you by Python, but you failed to provide s
.
You are ignoring s
altogether, drop it from the function signature:
classStudent_Record(object):
def__init__(self):
self.s = "class_Library"print"Welcome!! take the benifit of the library"
Next, you are calling the method rec.Student_details()
passing in an argument, but that method only takes self
, which is already provided for you by Python. You don't need to pass it in manually, and in your case the name is not even defined in that scope.
Solution 2:
if you do
classStudent_Record(object):def__init__(self, s):
self.s = ""defStudent_details(self):
print " Please enter your details below"
when you create the object of class Student_Record
it should accept a parameter despite for itself (self
). so it looks like:
record = Student_Record("text")
and in __init__
you can do whatever with the passed-in variable s
. For example, self.s = s
and you can call it anywhere in the class with self.s
because it has been initialized.
Solution 3:
Your code should be like this..(python indent):
classStudent_Record(object):
def__init__(self,s="class_Library"):
self.s=s
print"Welcome!! take the benifit of the library"defStudent_details(self):
print" Please enter your details below"
a=raw_input("Enter your name :\n")
print ("your name is :" +a)
b=raw_input("Enter your USN :\n")
print ("Your USN is:" ,int(b))
c=raw_input("Enter your branch :\n")
print ("your entered baranch is" +c)
d=raw_input("Enter your current semester :\n")
print ("your in the semester",int(d))
rec=Student_Record()
rec.Student_details()
s
in def __init__
should have a default value or you can pass a value from rec=Student_Record()
.
Post a Comment for "__init__() Takes Exactly 2 Arguments (1 Given)?"