Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

Manual 11 - Classes & Objects (OOP) in python

manual python computer

Uploaded by

rahidsaleemcool
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Manual 11 - Classes & Objects (OOP) in python

manual python computer

Uploaded by

rahidsaleemcool
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Department of Avionics Engineering

Introduction to Information Technology

Lab Manual 11

Student Name: ___________________________


Registration Number: ___________________________
Section: ___________________________
Deadline: ___________________________
Date of Submission: ___________________________

Institute of Space Technology, Islamabad


Introduction to Information Technology Session: 2024 (AVE-10)

Important Instructions
1. Every student should have lab manual in the lab; otherwise, there will be no evaluation and
attendance.
2. The lab manual should be printed on both sides of the paper. Color printing is not required.
3. Those students who have Laptop must bring it in the lab.
4. Students should read the manual before coming to the lab.
5. Every student will have to submit assignments individually. Assignments after the due date
will not be accepted.

Department of Avionics Engineering,


Institute of Space Technology, Islamabad 2|Page
Introduction to Information Technology Session: 2024 (AVE-10)

Experiment No. 11
Classes & Objects (OOP) in Python
Learning objectives
The main objective is to explore OOP basics in Python. After you’ve completed this manual, you'll be able to:
• Create classes, user-defined behaviors & magic/dunder functions.
• Instantiate objects and their attributes.

Task 0:
Create a python file with title “FirstName_Reg.No_Lab11.py” and define all the classes in this file.
[i.e., This file will have class definitions only]

Create another python file with title “main_Reg.No_Lab11.py” and create all the objects and demonstration
work in this file. [Import the above module in this file as directly available.]

>>from Reg.No_FirstName_Lab11 import *

Task 1:
Create a class named Tesla that has two Instance attributes: color & acceleration and a user defined behavior
named print_data(self). Since the attributes are instance attributes, these must be declared inside
Constructor(__init__(self,.)) as shown.

Instantiate an object from Tesla class and call the behavior print_data(self) and observe the output.

Output: ______________________________________________________________

Department of Avionics Engineering,


Institute of Space Technology, Islamabad 3|Page
Introduction to Information Technology Session: 2024 (AVE-10)

Create __str__(self) magic/dunder method in above class to overload the print() method(Concept of Method
Overloading as discussed in class) as shown:

Note that the __str__ method must have return statement and the string to be returned.
Now instead of calling the print_data() function, print the c1 object directly as print(c1) and observe the
output.

Output: ______________________________________________________________

Task 2:
Create a class named StudentsData that has three instance attributes: name, Reg_No, & age (declare inside
Constructor) and override the default __str__ method to print these attributes directly through print()
command. Instantiate an object from StudentsData class and print it to observe the output.
Write your Code here:

Output:

Department of Avionics Engineering,


Institute of Space Technology, Islamabad 4|Page
Introduction to Information Technology Session: 2024 (AVE-10)

Task 3:
Create a class named Polygon that has two Instance attributes: number_of_sides & side_lengths[] (an array
that will store the side lengths).
Create a user-defined behavior named inputSides(self). Observe & understand the code, recall the concepts
of List comprehension, dictionary etc.
Also, create a user-defined behavior named find_Area(self) as shown below.

Instantiate a triangle object from Polygon class and call the behaviors input_sides() and findArea() and
observe the output.

Output:

Department of Avionics Engineering,


Institute of Space Technology, Islamabad 5|Page
Introduction to Information Technology Session: 2024 (AVE-10)

Similarly, Instantiate a rectangle object from Polygon class and call the behaviors input_sides() and
findArea().
Write your Code here:

Output:

Task4:
List down the names of all the concepts used in this Manual.

Department of Avionics Engineering,


Institute of Space Technology, Islamabad 6|Page

You might also like