
Intro to Object Oriented Programming: Class Attributes
Presentation
•
Computers
•
6th - 8th Grade
•
Practice Problem
•
Medium
Kimberly Lewis
Used 6+ times
FREE Resource
15 Slides • 5 Questions
1
Object Oriented Programming: Class Attributes
2
What are some things each of them has?
I have a group of people.
3
Name
Age
Height
Weight
Hair color
Eye color
Skin color
4
If we think about data types, we could consider doing all of this in lists based on individuals. Then we can pull the information from the list.
Lists
5
Every list is new information!
How big can we really make the lists?
What if you don't have the same number of fields?
No inheritance (we'll cover this later!)
Cons
You've done it before
Relatively simple
Pros
Pros and Cons to Lists
6
Classes let us make smaller files, and more advanced programs
7
Let's look at the Enterprise crew as a class.
8
An instance is a single crew member.
9
Think of it this way...
A class is a blueprint.
The instance is the actual data.
10
Multiple Choice
You want to create a game that has several people playing at once. Should you build it using a list for each player or a class?
Lists
Class
11
Multiple Choice
Your game has a bunch of different food items the characters eat to gain health. Would you create a class just for the food?
Yes
No
12
Multiple Choice
Now you plan on having players fight monsters in the game. Should the monsters have their own class?
Yes
No
13
We start by adding the class statement. This tells python that everything after it is a class. Then we name it. pass is just a way to tell the code that there will be code here.
So how do we code it?
14
We create a function called __init_ that we add some of the properties we want in all of the dogs.
Now we give it properties.
15
What's in the parentheses?
These are called arguments. This is telling the code exactly how many and where we will be specifying this information when we make our instance. It reminds the code what it needs when you make an instance, and where to put that information.
16
The code self.name = name creates an attribute called "name" and assigns the value of the variable "name" to it. The same goes for the age and the breed.
Back to the code...
17
Fill in the Blanks
18
Just like when we call a function, we put the name of the class with the parentheses to tell the computer we're creating a new instance. But look at the red squigglies! We're not done yet!
Running the class
19
Now we add our instance information to the class in the parentheses! We have an instance of Dog()!
We add the variable information here!
20
Multiple Choice
What's wrong with the code here?
Nothing
You're calling a function with a variable
You haven't added the instance values to the class
The name in the variable isn't capitalized
Object Oriented Programming: Class Attributes
Show answer
Auto Play
Slide 1 / 20
SLIDE
Similar Resources on Wayground
15 questions
Natural Selection
Presentation
•
6th - 8th Grade
15 questions
Independent & Dependent Variables
Presentation
•
6th - 8th Grade
15 questions
Respiratory System
Presentation
•
6th - 8th Grade
15 questions
LCM and GCF Review
Presentation
•
6th - 8th Grade
15 questions
Informational Summary Writing
Presentation
•
6th - 8th Grade
13 questions
Google Sheets Basics
Presentation
•
6th - 9th Grade
17 questions
Computer Software
Presentation
•
7th Grade
15 questions
Context Clues
Presentation
•
6th - 8th Grade
Popular Resources on Wayground
10 questions
GPA Lesson
Presentation
•
9th - 12th Grade
7 questions
Albert Einstein
Quiz
•
3rd Grade
31 questions
Bridge A Review
Quiz
•
3rd Grade
6 questions
Blue Sue and Red Ruth
Quiz
•
3rd Grade
8 questions
(Day12 HW) Inverse Trig Ratios
Quiz
•
9th Grade
20 questions
Summer Geometry QUIZ (Week3)
Quiz
•
9th Grade
16 questions
Theme Practice
Quiz
•
7th Grade
20 questions
Taxes
Quiz
•
9th - 12th Grade