diff --git a/README.md b/README.md index df3297e..6b9a953 100644 --- a/README.md +++ b/README.md @@ -167,11 +167,3 @@ print("cetak perulangan kelipatan 5 yang < 50 : ") for i in range(5,50,+5): print(i) ``` - -### Perulangan While -```python -i = 0 -while i < 10: - print("*_* " + " -_-") - i=i+1 -``` \ No newline at end of file diff --git a/encapsulation_oop.py b/encapsulation_oop.py new file mode 100644 index 0000000..1e25054 --- /dev/null +++ b/encapsulation_oop.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +""" +Created on Wed Nov 20 21:22:28 2019 + +@author: DELL +""" +class Computer: + def __init__(self): + self._maxprice=900 + + def sell(self): + print("Selling price: {}".format(self._maxprice)) + + def setMaxPrice(self,price): + self._maxprice=price + +c= Computer() +c.sell() + +# Change The Price +c._maxprice=1000 +c.sell() + +#Using Setter Function +c.setMaxPrice(1500) +c.sell() \ No newline at end of file diff --git a/inheritance_oop.py b/inheritance_oop.py new file mode 100644 index 0000000..2366135 --- /dev/null +++ b/inheritance_oop.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +""" +Created on Wed Nov 20 21:36:14 2019 + +@author: DELL +""" +#Parent class + +class bird: + def __init__(self): + print("Bird Is ready ") + + def whoisthis (self): + print("Bird") + + def swim(self): + print("Swim Faster") + +#Child Class + +class Penguin(bird): + def __init__ (self): + super(). __init__() + print("Penguin is Ready") + + def whoisthis(self): + print("Penguin") + + def run(self): + print("Run Faster") + +imam=Penguin() +imam.whoisthis() +imam.swim() +imam.run() + \ No newline at end of file diff --git a/method_oop.py b/method_oop.py new file mode 100644 index 0000000..cea0858 --- /dev/null +++ b/method_oop.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +""" +Created on Wed Nov 20 21:43:46 2019 + +@author: DELL +""" +class Employee: + 'common base class for all emplyes' + empCount =0 + + def __init__(self,name,salary): + self.name =name + self.salary=salary + Employee.empCount+=1 + + def displaycount(self): + print("Total Employee %d "%Employee.empCount) + + def displayemployee(self): + print("name :",self.name,",salary :",self.salary) + +emp1=Employee("meng",1000000) +emp=Employee("yogi",2000000) +emp.displaycount() +emp.displayemployee() +emp1.displayemployee() +Employee.empCount \ No newline at end of file diff --git a/oop1.py b/oop1.py new file mode 100644 index 0000000..1d19e96 --- /dev/null +++ b/oop1.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +""" +Created on Wed Nov 20 22:24:39 2019 + +@author: DELL +""" + +class Employee: + 'common base class for all emplyes' + empCount =0 + def Employee(self): + print("Total Employee %d"%Employee.empCount) + + def __init__(self,name,salary): + print("Constructor created") + self.name =name + self.salary=salary + Employee.empCount+=1 + + def displaycount(self): + print("Total Employee %d "%Employee.empCount) + + def displayemployee(self): + print("name :",self.name,",salary :",self.salary) +"This would create first object employee class" +emp1=Employee("zara",2000) +emp1.displayemployee() +"This would create second object employee class" +emp2=Employee("yogi",4000) \ No newline at end of file diff --git a/overloading_oop.py b/overloading_oop.py new file mode 100644 index 0000000..0e1071e --- /dev/null +++ b/overloading_oop.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +""" +Created on Wed Nov 20 22:04:01 2019 + +@author: DELL +""" + +class A: + def __init__ (self,a): + self.a =a + # adding two Object + def __add__(self,o): + return self.a + o.a + +ob1=A(1) +ob2=A(2) +ob3=A("geeks") +ob4=A("For") + +print(ob1 + ob2) +print(ob3 + ob4) \ No newline at end of file diff --git a/polymorphism_oop.py b/polymorphism_oop.py new file mode 100644 index 0000000..e915f76 --- /dev/null +++ b/polymorphism_oop.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +""" +Created on Wed Nov 20 22:11:36 2019 + +@author: DELL +""" + +class Parrot : + def fly(self): + print("Parrot can fly ") + def swim (self): + print("Parrot can't Swim") +class Penguin: + def fly(self): + print("Penguin can't fly") + def swim(self): + print("Penguin can swim") + +#Common Interface +def flying_test(bird): + bird.fly() + +#instance object +blu=Parrot() +peggy=Penguin() +#passing the object +flying_test(blu) +flying_test(peggy) \ No newline at end of file