Skip to content

aaadityapal/python-apis-oop-assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

College Assignment - OOP and HTTP Programming

A comprehensive collection of Python programming assignments covering Object-Oriented Programming (OOP) concepts and HTTP client development.

📚 Assignment Overview

This project contains 12 programming assignments designed to teach fundamental and advanced programming concepts:

Part 1: Object-Oriented Programming (Questions 1-5)

  • Q01: Basic OOP - Classes, attributes, and methods
  • Q02: Encapsulation - Private attributes, getters, setters, and properties
  • Q03: Inheritance - Class hierarchies and method overriding
  • Q04: Polymorphism - Duck typing and polymorphic functions
  • Q05: Advanced OOP - Composition, dunder methods, and class methods

Part 2: HTTP Client Programming (Questions 6-12)

  • Q06: Basic GET requests
  • Q07: GET requests with query parameters
  • Q08: POST requests with JSON data
  • Q09: PUT and DELETE operations
  • Q10: HTTP status code classification
  • Q11: Practical status handling with error management
  • Q12: Complete CLI HTTP client application

🚀 Getting Started

Prerequisites

  • Python 3.7 or higher
  • Internet connection (for HTTP assignments)

Installation

  1. Clone or download the project

    git clone <repository-url>
    cd college_assignment
  2. Install dependencies

    pip install -r requirements.txt

Project Structure

college_assignment/
├── src/
│   ├── q01_oop_book_basics.py
│   ├── q02_oop_encapsulation.py
│   ├── q03_oop_inheritance.py
│   ├── q04_oop_polymorphism.py
│   ├── q05_oop_all_in_one.py
│   ├── q06_requests_get.py
│   ├── q07_requests_get_params.py
│   ├── q08_requests_post.py
│   ├── q09_requests_put_delete.py
│   ├── q10_http_status_classifier.py
│   ├── q11_fetch_with_status_handling.py
│   └── q12_cli_http_client.py
├── tests/
│   ├── smoke_tests.py
│   └── simple_smoke_tests.py
├── requirements.txt
└── README.md

💻 Running the Assignments

Individual Assignment Execution

Each assignment can be run independently:

# OOP Assignments
python src/q01_oop_book_basics.py
python src/q02_oop_encapsulation.py
python src/q03_oop_inheritance.py
python src/q04_oop_polymorphism.py
python src/q05_oop_all_in_one.py

# HTTP Assignments
python src/q06_requests_get.py
python src/q07_requests_get_params.py
python src/q08_requests_post.py
python src/q09_requests_put_delete.py
python src/q10_http_status_classifier.py
python src/q11_fetch_with_status_handling.py

CLI HTTP Client Usage

The Q12 assignment provides a complete CLI tool:

# GET request
python src/q12_cli_http_client.py GET https://jsonplaceholder.typicode.com/posts/1

# POST request with JSON
python src/q12_cli_http_client.py POST https://jsonplaceholder.typicode.com/posts '{"title":"Test","body":"Content","userId":1}'

# PUT request
python src/q12_cli_http_client.py PUT https://jsonplaceholder.typicode.com/posts/1 '{"title":"Updated"}'

# DELETE request
python src/q12_cli_http_client.py DELETE https://jsonplaceholder.typicode.com/posts/1

🧪 Testing

Smoke Tests

Run all assignments to ensure they execute without errors:

# Simple smoke test
python tests/simple_smoke_tests.py

# Detailed smoke test with reporting
python tests/smoke_tests.py

Expected Output

=== Smoke Tests for College Assignment ===
Testing 12 files from: C:\...\college_assignment\src
--------------------------------------------------
Running q01_oop_book_basics.py ...
  [PASS] Passed
...
SUMMARY: 12 passed, 0 failed
[PASS] All 12 files passed smoke tests!

📖 Learning Objectives

Object-Oriented Programming Concepts

  • Encapsulation: Data hiding and controlled access
  • Inheritance: Code reuse and hierarchical relationships
  • Polymorphism: One interface, multiple implementations
  • Composition: Building complex objects from simpler ones
  • Dunder Methods: Python's special methods (__init__, __str__, etc.)
  • Class Methods: Alternative constructors and factory patterns

HTTP Programming Concepts

  • REST API Interaction: GET, POST, PUT, DELETE operations
  • Request/Response Handling: Status codes, headers, JSON data
  • Error Handling: Network timeouts, connection errors, HTTP errors
  • Query Parameters: URL parameter construction and handling
  • JSON Processing: Parsing and formatting JSON data
  • CLI Development: Command-line interface design

🌟 Key Features

Educational Design

  • Progressive Learning: Each assignment builds on previous concepts
  • Real-World Examples: Book management system with Indian pricing
  • Practical Applications: CLI tools and API clients
  • Error Handling: Comprehensive exception management
  • Best Practices: Clean code, documentation, and validation

Technical Implementation

  • Python 3.7+ Compatible: Modern Python features
  • Minimal Dependencies: Only standard library + requests
  • Cross-Platform: Works on Windows, macOS, and Linux
  • Unicode Safe: Proper handling of international characters
  • Well-Documented: Clear comments and docstrings

📋 Assignment Details

Assignment Topic Key Concepts
Q01 Basic OOP Classes, attributes, methods
Q02 Encapsulation Private attributes, properties
Q03 Inheritance Subclasses, method overriding
Q04 Polymorphism Duck typing, polymorphic functions
Q05 Advanced OOP Composition, dunder methods
Q06 HTTP GET Basic API requests
Q07 GET with Params Query parameters
Q08 HTTP POST Creating resources
Q09 PUT & DELETE Updating and removing resources
Q10 Status Codes HTTP response classification
Q11 Error Handling Practical status management
Q12 CLI Client Complete HTTP client tool

🛠️ Dependencies

  • Python Standard Library: sys, json, pathlib, subprocess
  • External Library: requests (for HTTP functionality)

🌍 API Endpoints Used

All HTTP assignments use the JSONPlaceholder API:

  • Base URL: https://jsonplaceholder.typicode.com
  • Endpoints: /posts, /comments, /posts/{id}
  • Methods: GET, POST, PUT, DELETE

💡 Tips for Success

  1. Run assignments in order - Each builds on previous concepts
  2. Read the code comments - They explain the implementation details
  3. Experiment with modifications - Try changing parameters and data
  4. Use the smoke tests - Validate your environment setup
  5. Check network connectivity - HTTP assignments require internet access

🎯 Learning Path

graph TD
    A[Q01: Basic OOP] --> B[Q02: Encapsulation]
    B --> C[Q03: Inheritance]
    C --> D[Q04: Polymorphism]
    D --> E[Q05: Advanced OOP]
    E --> F[Q06: HTTP GET]
    F --> G[Q07: GET with Params]
    G --> H[Q08: HTTP POST]
    H --> I[Q09: PUT & DELETE]
    I --> J[Q10: Status Codes]
    J --> K[Q11: Error Handling]
    K --> L[Q12: CLI Client]
Loading

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages