Class GeometricShapes - Python Programming Exercise

In this exercise, you will develop a Python project with the required classes, organizing them into separate files, according to a class diagram. This exercise is perfect for practicing class definition, inheritance, and project organization in Python. By implementing this project, you will gain hands-on experience in handling class definitions, inheritance, and project organization in Python. This exercise not only reinforces your understanding of object-oriented programming but also helps you develop efficient coding practices for managing user interactions.

 Category

OOP Object-Oriented Programming

 Exercise

Class Geometricshapes

 Objective

Develop a Python project with the required classes, organizing them into separate files, according to this class diagram.

 Example Python Exercise

 Copy Python Code
# PhotoAlbum class definition
class PhotoAlbum:
    def __init__(self, page_count=16):
        # Initialize the album with a default or specified page count
        self.__pageCount = page_count  # Private attribute for page count

    def getPageCount(self):
        # Return the total number of pages in the album
        return self.__pageCount


# LargePhotoAlbum class definition (inherits from PhotoAlbum)
class LargePhotoAlbum(PhotoAlbum):
    def __init__(self):
        # Initialize the large photo album with a default of 64 pages
        super().__init__(64)  # Calls the constructor of PhotoAlbum with 64 pages


# Test class to demonstrate the functionality
class AlbumTest:
    @staticmethod
    def Main():
        # Create a PhotoAlbum with the default constructor (16 pages)
        album1 = PhotoAlbum()
        print(f"Album 1 has {album1.getPageCount()} pages.")

        # Create a PhotoAlbum with 24 pages
        album2 = PhotoAlbum(24)
        print(f"Album 2 has {album2.getPageCount()} pages.")

        # Create a LargePhotoAlbum (64 pages)
        large_album = LargePhotoAlbum()
        print(f"Large PhotoAlbum has {large_album.getPageCount()} pages.")


# Main entry point for the program
if __name__ == '__main__':
    # Run the test class to demonstrate the functionality
    AlbumTest.Main()

 Output

python photo_album.py
Album 1 has 16 pages.
Album 2 has 24 pages.
Large PhotoAlbum has 64 pages.

 Share this Python Exercise

 More Python Programming Exercises of OOP Object-Oriented Programming

Explore our set of Python Programming Exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of Python. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in Python.

  •  Vehicle Classes

    In this exercise, you will develop a Python project with corresponding classes, spread across multiple files, based on the provided class diagram. Each class should h...

  •  Class Rectangle

    In this exercise, you will develop a Python project called "Shapes," incorporating a class named "Square." Each square will store the starting X and Y coordinates (re...

  •  Class Purchases

    In this exercise, you will develop a Python project with the necessary classes (distributed across multiple files) based on the given class diagram. Each class should...

  •  Class Colored Sphere

    In this exercise, you will develop a Python project and extend the previous exercise to include "Colored Circles". Each circle should have a radius, center coordinate...

  •  Classes: Learner and Instructor

    In this exercise, you will develop a Python program that incorporates a Person class. Then, create two additional classes, Student and Teacher, that inherit from Pers...

  •  Class Picture Collection

    In this exercise, you will develop a Python program with a class named "PhotoAlbum" that includes a private attribute "pageCount." This exercise is perfect for...