Learn with Yasir

Share Your Feedback

Problem Statement: Python Class and Instance Attributes


Problem Statement: Python Class and Instance Attributes

Create a Python program to manage student information using class attributes and instance attributes.

Define a class named Student with the following requirements:

  • A class attribute named school_name with the value "Ghazi University".
  • Instance attributes:

    • name
    • roll_no
    • marks

These instance attributes should be initialized using the constructor __init__().

Tasks

  1. Create at least three student objects with different data.
  2. Display each student’s:

    • Name
    • Roll Number
    • Marks
    • School Name
  3. Change the class attribute school_name to another value and show that the change affects all student objects.
  4. Change the marks of only one student and demonstrate that other students’ marks remain unchanged.
  5. Add a method named display_info() to print the complete student information.

Sample Output

School: Ghazi University
Name: Ali
Roll No: 101
Marks: 85

Learning Objectives

By completing this practical exam, students will be able to:

  • Understand the difference between class attributes and instance attributes
  • Use constructors in Python classes
  • Create and manage objects
  • Access and modify class and instance data

Based on concepts from Python class and instance attributes. (Learn with Yasir)