Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task BasicCourse Prayogi #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
26 changes: 26 additions & 0 deletions encapsulation_oop.py
Original file line number Diff line number Diff line change
@@ -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()
36 changes: 36 additions & 0 deletions inheritance_oop.py
Original file line number Diff line number Diff line change
@@ -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()

27 changes: 27 additions & 0 deletions method_oop.py
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions oop1.py
Original file line number Diff line number Diff line change
@@ -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)
21 changes: 21 additions & 0 deletions overloading_oop.py
Original file line number Diff line number Diff line change
@@ -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)
28 changes: 28 additions & 0 deletions polymorphism_oop.py
Original file line number Diff line number Diff line change
@@ -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)