Skip to content

Instantly share code, notes, and snippets.

@mickelsonm
Created April 9, 2015 01:58
Show Gist options
  • Save mickelsonm/4980c1980794bb86f71a to your computer and use it in GitHub Desktop.
Save mickelsonm/4980c1980794bb86f71a to your computer and use it in GitHub Desktop.
class Animal:
def __init__(self):
self.name = ""
self.sound = ""
def makeSound(self):
if self.name != "" and self.sound != "":
print self.name + " sounds '" + self.sound + "'"
class Dog(Animal):
def __init__(self):
self.sound = "bark bark"
def woof(self):
print "I am woofing!"
def main():
#yes...this is where it all starts when learning a new programming language
print "Hello World!"
#a for range loop
for i in range(0, 10):
print i
#iterate over an array
fruits = ['apples', 'oranges', 'pears', 'apricots']
for fruit in fruits:
print fruit
#key/value pair
lookup = {'a': 1, 'b': 2, 'c': 3};
for key in lookup:
print 'key = ', key, ' value = ', lookup[key]
#a simple while loop
y = 10
while y >= 0:
if y == 5:
print "Johnny Five!"
print y
y -= 1
#create a simple object
a = Animal()
a.name = "Jackalope"
a.sound ="blurp blurp"
a.makeSound()
#basic inheritance example
d = Dog()
d.name = "Sparky"
d.makeSound()
d.woof()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment