Help me to solve this error... ! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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)

31st Dec 2016, 12:22 PM
Chamara Janaka Bandara
Chamara Janaka Bandara - avatar
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
14th Feb 2020, 10:40 AM
Olajumoke Fasoranti
Olajumoke Fasoranti - avatar
+ 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.
31st Dec 2016, 12:40 PM
Dao
Dao - avatar
+ 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)
1st Jan 2017, 8:19 PM
Dao
Dao - avatar
+ 2
You're giving Hem as a parameter to me's constructor, even though Hem is defined the line after.
31st Dec 2016, 12:33 PM
Dao
Dao - avatar
+ 2
class Student { Public: int age; public: Student(int a) { setAge(a); } void setAge(int a) { age = a; } Int getAge() { Return age; } };
16th May 2020, 12:05 AM
Maher AlOmari
Maher AlOmari - avatar
+ 1
class Student { private: int age; public: Student(int a) { setAge(a); } void setAge(int a) { age = a; } getAge() { age; } };
23rd Apr 2020, 10:20 AM
V.SATHYA
V.SATHYA - avatar
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?...
31st Dec 2016, 12:36 PM
Chamara Janaka Bandara
Chamara Janaka Bandara - avatar
0
thanks... :)
31st Dec 2016, 12:44 PM
Chamara Janaka Bandara
Chamara Janaka Bandara - avatar
0
But what is "jan" in your function?
1st Jan 2017, 7:01 PM
Shirley Zhao
0
class Student { private: int age; : Student(int a) { setAge( ); } void setAge(int a) { age = a; } getAge() { age; } };
17th Apr 2018, 2:16 PM
Riddhi tank
Riddhi tank - avatar
0
class student{ private: int age; _______: student(int a) { set age(__); } void setAge(int A) { } ___getAge() { _____age; } };
13th Nov 2018, 11:44 AM
Johandi Christian
Johandi Christian - avatar
0
Answer is class and function.
17th Dec 2018, 1:24 PM
ISSAM ES SOUFY
ISSAM ES SOUFY - avatar
0
help please class Student { private: int age; : Student(int a) { setAge( ); } void setAge(int a) { age = a; } getAge() { age; } };
27th Oct 2019, 10:40 AM
Ardiansyah Ardiansyah
Ardiansyah Ardiansyah - avatar
0
: 8?????
1st Apr 2020, 6:26 AM
KHLIFI SALEH
KHLIFI  SALEH  - avatar
0
What's the solution 8
1st Apr 2020, 10:41 AM
KHLIFI SALEH
KHLIFI  SALEH  - avatar
0
class Student { private: int age; : Student(int a) { setAge( ); } void setAge(int a) { age = a; } getAge() { age; } };
18th May 2020, 9:16 AM
Saurabh Kumar
Saurabh Kumar - avatar
0
class Student { private: int age; public Student(int a) { setAge( ); } void setAge(int a) { age = a; } int getAge() { return age; } };
21st May 2020, 3:49 PM
Abdelhadi Mastakou
Abdelhadi Mastakou - avatar
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 )
10th Jun 2020, 4:48 PM
Ira Pendleton
Ira Pendleton - avatar
0
Fill in the blanks to evaluate the R-squared on the testing data: model.score(X_test, Y_test)
21st Nov 2020, 4:45 AM
Jason Chew
Jason Chew - avatar
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)
21st Nov 2020, 4:46 AM
Jason Chew
Jason Chew - avatar