-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses_objects.py
More file actions
63 lines (42 loc) · 1.66 KB
/
classes_objects.py
File metadata and controls
63 lines (42 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#this program is an implementation of the classes and objects in python
# classes serve as an blueprint for making objects in an code
# everything in OOP is regarded as an object
# the properies defined in the class are called attributes and the functions are called methods
class Human:
def __init__(self,name,age,gender): ## the init function is executed whenever a class is initiated // we can use this function to pass parameters to the object when it is created
## this func is also called a constructor
self.name = name
self.age = age
self.gender = gender
def greet(self): ## self refers to the name of the object that is being creatd using this class
print("Hello I am " + self.name)
print("HI EVERYBODY !!")
class Robot:
def introduce_self(self):
print("my name is ",self.name) ##
print("my weight is " ,self.weight)
print("my address is ", self.addr)
class Animal:
def __init__(self):
self.name = input("enter the name of the animal :")
self.age = int(input("enter the age of the animal :"))
self.habitat = input("enter the habitat of this animal :")
self.owner = input("enter the name of owner :")
self.care_taker_robo = r1
def info(self):
print("I am a ",self.name)
print("my age is ",self.age)
print("my owner is :",self.owner)
H1 = Human("David",32,"male")
print(H1.name)
print(H1.age)
print(H1.gender)
H1.greet()
r1 = Robot()
r1.name = "ROBO1"
r1.weight = 30
r1.addr = "USA"
r1.introduce_self()
a1 = Animal()
a1.info()
a1.care_taker_robo.introduce_self()