Computing Programming With Python (W5)
Computing Programming With Python (W5)
Write a program that reads a CSV file of student grades, calculates the average
grade for each student, and writes the results to a new CSV file. Use the csv module
to read and write CSV files “import csv”, and define functions to calculate the
average grade and format the results.
What is object-oriented programming?
● Object-oriented programming (OOPs) is a programming approach.
● Objects are software bundles like people or car or robot or etc.
● Objects hold data and code together.
● Objects are analogous to real-world objects with properties and behaviors.
● Objects have nature and behavior, such as the remote control of a
television.
● Object have attributes/properties.
● oBjects have behaviours/methods.
Attributes and Methods Attributes → variables
Methods → functions
● OOP is used in Python to create classes, which act as templates for creating
objects with similar attributes and behaviors.
● A class is defined using the 'class' keyword, followed by the class name and a
colon. The class body contains the attributes and methods for the class.
● Attributes are variables that hold data for each object, and methods are
functions that perform operations on the object's data.
● When an object is created, it is called an instance of the class. The 'self'
parameter is used to refer to the instance within the class.
● Objects can interact with each other through their methods, and inheritance can
be used to create new classes that inherit attributes and methods from a parent
class.
What is a Python class?
Source: https://thevaluable.dev/abstraction-type-software-example/
Define a dog object
Abstraction of dog object
Abstraction of dog object
Abstraction of dog object
Declaring Objects (Also called instantiating a class)
Practice time
Print statement: prints a statement showing the account number, owner name, and
current balance.
Practice time
Student Class
Write a Python class for a student. The class should have the following attributes: