Summit Middle School classes for Andrew Busch
Andrew Busch - Summit
  • Home
  • Algebra 1
    • Alg 1B - Last Week
    • Alg1B 14 HW - Intro to Functions
    • Alg 1B 11 - Rational Expressions
    • Alg 1B 12 - Radical Expressions
    • Alg 1B 10 v2.0 - Quadratic Functions >
      • 10b Graphing with Pennies - Desmos Tutorial
      • 10i Snowboard Quadratic - Alg1B
      • 10 Quadratics Project
    • Alg 1B 10 Book - Factoring Quadratics
    • Alg 1B 9 - Exponential Functions
    • Alg 1B 8.5 - Representing Data
    • Alg 1B 13 - Inequalities
    • Alg 1B 8 - Best Fit Lines and Linear Regression
    • Alg 1B 7 - Linearity
  • Geometry
    • Geom Last Week
    • Geom 12 - Probability
    • Geom 11 - Circumference, Area, Volume
    • Geom 10-Circles
    • Geom 9 - Right Triangles and Trigonometry
    • Geom 8 - Similarity
    • Geom 7 - Quadrilaterals and Other Polygons
    • Geom 6 - Relationships Within Triangles
    • Geom 5 - Congruent Trianlges
    • Geom 4 - Transformations
    • Geometry 3.5 - Constructions
    • Geom 3 - Parallel and Perpendicular Lines
    • Geom 2 - Reasoning and Proofs
    • Geom 1 - Basics of Geometry
  • Programming
    • Directions for Sharing Programs with Me
    • Hour of Code
    • Intro to Python >
      • Installing and Using Portable Python
      • Introduction to Programming
      • Interactive Storyteller
      • Sophisticated Calculator
      • Getting Started with Games
      • Word Length Frequency
      • Substitution Cipher
      • Simple Game of Paddleball
      • Animating Many Objects
      • Accelerator
      • Applying Trigonometry
      • GIFs
      • Programmatic Art
      • Battleship
      • Pong
      • CodeCademy.com Suggested Work
      • Python Resources
    • Advanced Python >
      • Python Installation
      • Review of Intro to Programming
      • Objects and Classes >
        • More on Classes: Functions, Methods, Inheritance
        • Quadrilaterals
      • tkinter >
        • Paddle Ball
        • Light Bike
        • Frogger
        • Snake Game
        • Breakout
      • Reading and Writing Files
      • Directories and Importing Modules
      • Raspberry Pi
      • API's
      • Python Puzzles
  • Clubs
  • Graphing Calculator
  • PARCC Practice

Objects and Classes

Object-oriented programming. Although you don't need to understand objects to make interesting programs, objects can help you make interesting programs a lot quicker and with a lot more readability. Instead of designing super complicated logical arguments in our programs, we use something called 'classes'.
I think Codecademy does a great job introducing the concept of classes in its Python Course. If you haven't already tried it, take a couple of hours and check out this lesson on classes. Be sure to log in to save your progress!
Picture
Sometimes going through the material a different way is helpful. You can check out http://greenteapress.com/thinkpython/html/thinkpython016.html for a different approach to classes. I suggest creating a module instead of using the interpreter.

Quick Review of Classes:

1) We make specific objects based off a class. A 'class' is like a generic person--kind of like a cookie cutter. You can say the person has some characteristics: gender, age, weight, IQ, ability to tell jokes, etc. We can then use the generic person class to create specific people, we call these instances of the class.

#here we define our generic person class.
class Generic_Person(object):
    #all classes start with an __init__ function  (two underscores before and after)
    #that takes "self" as an argument (or parameter) and defines the attributes of the class.

    def __init__ (self):
        self.gender = ' '
        self.tells_good_jokes = "True"

#here we make and instance of our class named "Andrew".
andrew = Generic_Person()

#we can give our person attributes. We use the form: "class.attribute = "
andrew.gender = 'male'

#we can use inheritance to see if our instance, Andrew, tells good jokes
>>>andrew.tells_good_jokes
True
​
2) Functions defined inside a class are called "methods".

class.method(argument)
​

3) We can have objects inherit the properties of other objects.

#this is the parent class
class Parent_class(object):
    def __init__(self):
        pass

#this child class inherits all the characteristics of the parent class. Notice the argument is the parent class name.
class Child_class(Parent_class):
    def __init__(self):
        pass

#this child class inherits all the characteristics of both the above parent classes. Notice the argument is the parent class name.
class Grandchild_class(Child_class):
    def __init__(self):
        pass

A More Extensive Review of Classes

If you're looking for more in the way of review, particularly regarding functions, methods, and inheritance. Here's where to go.
Let's try it:
As a practice program, we are going to create a hierarchy program which highlights the inheritance of classes. When creating a program, it is often helpful to spend some time thinking about the structure BEFORE you start coding. What are the relationships between the objects? What will the flow look like?
1) Quadrilaterals.
We'll do some games once we talk about tkinter together.

Powered by Create your own unique website with customizable templates.