+ 1
Help me to solve this error... !
"Hem" is not defined, ..! class mother: def __init__(self, sons, housband,name,age): self.sons = sons self.housband = housband self.name = name self.age = age class me: def __init__(self,name,age,gender,height,mother): self.name = name self.age = age self.gender = gender self.height = height self.mother = mother jan = me ("Jan",23,"male",6,Hem) Hem = mother(jan,"Ban","Hem",42) print (jan.mother.name)
26 Answers
+ 6
Answer
class Person:
def __init__(self, age):
self.age = int(age)
@property
def isAdult(self):
if self.age > 18:
return True
else:
return
False
+ 4
It's not about the classes themselves, but the class instances. The mother you're trying to give to me's constructor doesn't exist yet. Try removing mother's initialization from the __init__, and make a separate function to initialize it.
+ 3
Hey, this is pretty late, but since I was bored, I modified your code to make it work. It has a restriction: You cannot create a child before creating a mother (just like in real life!).
class mother:
def __init__(self, husband, name, age):
self.husband = husband
self.name = name
self.age = age
def SetChild(self, child):
self.child = child
class me:
def __init__(self,name,age,gender,height,mother):
self.name = name
self.age = age
self.gender = gender
self.height = height
self.mother = mother
self.mother.SetChild(self)
Hem = mother("Ban","Hem",42)
Jan = me("Jan",23,"male",6,Hem)
print (Jan.mother.name)
+ 2
You're giving Hem as a parameter to me's constructor, even though Hem is defined the line after.
+ 2
class Student {
Public:
int age;
public:
Student(int a) {
setAge(a);
}
void setAge(int a) {
age = a;
}
Int getAge() {
Return age;
}
};
+ 1
class Student {
private:
int age;
public:
Student(int a) {
setAge(a);
}
void setAge(int a) {
age = a;
}
getAge() {
age;
}
};
0
yep,.. in such situation why can't it call the 2nd class to get details of it to the 1st class
is there any way to do it?...
0
thanks... :)
0
But what is "jan" in your function?
0
class Student {
private:
int age;
:
Student(int a) {
setAge(
);
}
void setAge(int a) {
age = a;
}
getAge() {
age;
}
};
0
class student{
private:
int age;
_______:
student(int a) {
set age(__);
}
void setAge(int A) {
}
___getAge() {
_____age;
}
};
0
Answer is class and function.
0
help please
class Student {
private:
int age;
:
Student(int a) {
setAge(
);
}
void setAge(int a) {
age = a;
}
getAge() {
age;
}
};
0
: 8?????
0
What's the solution 8
0
class Student {
private:
int age;
:
Student(int a) {
setAge(
);
}
void setAge(int a) {
age = a;
}
getAge() {
age;
}
};
0
class Student {
private:
int age;
public
Student(int a) {
setAge(
);
}
void setAge(int a) {
age = a;
}
int
getAge() {
return age;
}
};
0
Fill in the blanks to make the egg attribute strongly private and access it from outside of the class.
class Test:
egg = 7
t = Test()
print(t.
Test
)
0
Fill in the blanks to evaluate the R-squared on the testing data:
model.score(X_test, Y_test)
0
Complete the code to train a multivariate linear regression model to predict the MEDV based on features RM, LSTAT, and CRIM (per capita crime rate by town):
X3 = boston[['RM', 'LSTAT', ‘CRIM’]]
Y = boston['MEDV']
X3_train, X3_test, Y_train, Y_test = train_test_split
(X3, Y, test_size= 0.3, random_state=1)
model3 = LinearRegression() model3.fit(X3_train, Y_train)