Skip to content

Commit

Permalink
created new folder for python practice, practiced objects
Browse files Browse the repository at this point in the history
  • Loading branch information
dgisolfi committed Jul 28, 2018
1 parent cc2f6ba commit 6190def
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pythonPractice/OOP/person_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/python3
# person_class.py
# 2018-07-28
# Purpose: To review python Object Oriented Programming

# To run an interactive python shell of this file add the -i tag when running
# EX: python3 -i class.py


class Person:

age = 20

def name(self, name):
return list(name)
45 changes: 45 additions & 0 deletions pythonPractice/OOP/pizza_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/python3
# person_class.py
# 2018-07-28
# Purpose: To review python Object Oriented Programming

# To run an instance of this file in a interactive python shell add the -i tag when running
# EX: python3 -i class.py

class Food:
def __init__(self, dish_name, place_origin, is_healthy):
self.dish_name = dish_name
self.place_origin = place_origin
self. is_healthy = is_healthy
print('creating food object')

def getDishName(self):
return self.dish_name

def getOrigin(self):
return self.place_origin

def getIsHealthy(self):
return self.is_healthy

def __del__(self):
print('destroying food object')

class Pizza(Food):
def __init__(self, toppings, size, price):
Food.__init__(self, 'Pizza', 'Italy', False)
self.toppings = toppings
self.size = size
self.price = price

def getToppings(self):
return self.toppings

def getSize(self):
return self.size

def getPrice(self):
return self.price


large_pepperoni_pie = Pizza(['pepperoni', 'cheese'], 'Large', 17.99)
46 changes: 46 additions & 0 deletions pythonPractice/OOP/special_classes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/python3
# person_class.py
# 2018-07-28
# Purpose: To review python Object Oriented Programming

# To run an instance of this file in a interactive python shell add the -i tag when running
# EX: python3 -i class.py

class Animal:
def __init__(self, name, species):
self.name = name
self.species = species

def getName(self):
return self.name

def getSpecies(self):
return self.species

def __del__(self):
#Destroys instance of class
print('Animal Destroyed :(')

class FourLegs:
def hasLegs(self):
return 4

#Dog Class inherits the Animal and FourLegs class methods and properties
class Dog(Animal, FourLegs):

def __init__(self, name, breed, is_big):
Animal.__init__(self, name, 'Dog')
self.breed = breed
self.is_big = is_big
print('Creating DOGO: ' + self.getName())

#Overide getSpecies method inherited from the Animal class
def getSpecies(self):
return self.species, self.breed

def getis_big(self):
return self.is_big


#Intialize a instance of the Animal class
kevin = Dog('Kevin', 'Shiba Inu', False)

0 comments on commit 6190def

Please sign in to comment.