Skip to content

Commit 158f629

Browse files
committed
Python Programs
1 parent f91402f commit 158f629

9 files changed

+55
-0
lines changed

OOP/P01_ClassDefinition.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#Author: OMKAR PATHAK
12
#In this program we will see how to define a class
23

34
class MyFirstClass():

OOP/P02_InstanceMethods.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#Author: OMKAR PATHAK
12
#In this example we will be seeing how instance methods are used
23
#Instance methods are accessed by: instance.method()
34

OOP/P03_InstanceAttributes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#Author: OMKAR PATHAK
12
#In this example we will be seeing how instance Attributes are used
23
#Instance attributes are accessed by: object.attribute
34
#Attributes are looked First in the instance and THEN in the class

OOP/P04_InitConstructor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#Author: OMKAR PATHAK
12
#This example shows the use of __init__ constructor
23

34
class Vehicle():

OOP/P05_FirstProgramusingOOP.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#Author: OMKAR PATHAK
12
#In this assignment we would see the use of OOP
23

34
class MaxSizeList(object):

OOP/P06_Inheritance.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#Author: OMKAR PATHAK
12
#This program illustrates the concept of inheritance
23
#Python looks up for method in following order: Instance attributes, class attributes and the
34
#from the base class

OOP/P07_MoreOnInheritance.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#Author: OMKAR PATHAK
12
#This program illustrates the advanced concepts of inheritance
23
#Python looks up for method in following order: Instance attributes, class attributes and the
34
#from the base class

OOP/P08_MultipleInheritence.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#Author: OMKAR PATHAK
12
#This program shows the order in which the classes are accessed in case of multiple inheritance
23
#Python uses DEPTH FIRST SEARCH algorithm for lookups
34

Programs/P34_Stack.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#Author: OMKAR PATHAK
2+
#This program illustrates an example of Stack implementation
3+
#Stack Operations: push(), pop(), isEmpty(), top(), stackSize()
4+
5+
class Stack(object):
6+
def __init__(self, size):
7+
self.index = []
8+
self.size = size
9+
10+
def __str__(self):
11+
myString = ' '.join(str(i) for i in self.index)
12+
return myString
13+
14+
def push(self, data):
15+
''' Pushes a element to top of the stack '''
16+
self.index.append(data)
17+
18+
def pop(self):
19+
''' Pops the top element '''
20+
return self.index.pop()
21+
22+
def isEmpty(self):
23+
''' Checks whether the stack is empty '''
24+
return len(self.index) == []
25+
26+
def isFull(self):
27+
''' Checks whether the stack if full '''
28+
return len(self.index) == self.size
29+
30+
def top(self):
31+
''' Returns the top element of the stack '''
32+
return self.index[-1]
33+
34+
def stackSize(self):
35+
''' Returns the current stack size '''
36+
return len(self.index)
37+
38+
if __name__ == '__main__':
39+
myStack = Stack(10)
40+
for i in range(0, 10):
41+
myStack.push(i)
42+
print(myStack.isEmpty()) #False
43+
print(myStack.isFull()) #True
44+
print(myStack) #0 1 2 3 4 5 6 7 8 9
45+
print(myStack.stackSize()) #10
46+
print(myStack.pop()) #9
47+
print(myStack) #0 1 2 3 4 5 6 7 8

0 commit comments

Comments
 (0)