Download presentation
Presentation is loading. Please wait.
1
Lab Demo 1 Dr. Mai Elshehaly
2
What is Python? An interpreted language
Executes instructions directly, without previously compiling a program into machine-language instructions
3
Hello World
4
Indentation acts as {}
5
Classes in Python A class is a way to group variables and functions that work together to define a certain functionality in your code. Let’s say we want to write code to simulate a dog We will create a class named “Dog” Let’s do this!
6
Create a new file and name it “dog.py”
7
Class definition
8
Class definition
9
Run your code. Nothing happens! Why?
What we wrote so far is a class definition This is equivalent to saying: Hypothetically if there is any dog in the street, we assume that it can bark, and it can jump. This doesn’t mean we’re talking about a specific dog So we haven’t actually seen a real dog We only know what dogs in general can do
10
Now let’s instantiate our class
Meaning: we will create an object which is an instance of the class Dog This will mean a specific dog Now we can execute some of his actions (functions) and/or read his properties
11
Now run
12
Try this: remove the word self from line 6
13
What happened? We defined the variable canJump twice
The first is a member of the class definition, we can refer to it using the keyword self The second is local
14
The __init__ function Notice how we had to call the stopJumpint() method in our code Nothing happened when we instantiated the class because the class has no entry point The __init__ function is a special function we define for our class It gets executed as soon as an object is created
16
What we learned so far: How to define a class
How to create initialization code in __init__ function How to create an object to instantiate the class How to call member functions of a class
17
Create a new file: dataMaker.py
18
Import + Class definition
19
Instantiate and run (multiple times)
20
Refresher: Equation of a line passing through 2 points
A + Bx + Cy = 0 Where, A = xB*yA – xA*yB B = yB – yA C = xA – xB
21
Generate points on both sides of the line
Define a vector V of coefficients for the line equation Calculate new points X by using dot product For any point on the line: x.V = 0 For any point below the line: x.V is negative For any point above the line: x.V is positive
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.