Skip to content

paldebarun/python-projects

Repository files navigation

assignment 1 problem statement :

Assignment: Income Manager with Store Inventory and Billing System

Topics Covered:

  • Python basics: Syntax, data types, functions.
  • Control flow: if-else, loops, break, continue.
  • Data structures: Lists, dictionaries, sets.
  • File handling: Reading and writing to files.
  • Exception handling.

Problem Statement:

Develop a Store Inventory and Billing System with Income Management for a small business. The application should manage:

  1. Store Inventory:

    • Maintain a list of items in inventory with attributes: Item Name, Quantity, and Price (per unit).
    • Allow the user to add, update, or delete items in the inventory.
    • Save and load the inventory data from a file.
  2. Billing System:

    • Allow to purchase items from the store.
    • Deduct purchased quantities from the inventory.
    • Generate a bill with the total cost and display it to the customer.
    • Save the billing details to a file for record-keeping.
  3. Income Management:

    • Track the store’s total income based on the generated bills.
    • Allow the user to view the daily income and compare it with a daily target.
  4. Error Handling:

    • Handle exceptions, such as invalid item inputs, quantities exceeding availability, or file errors.

Functional Requirements:

1. Inventory Management

  • The system should allow the user to:

    • Add a new item to the inventory.
    • Update the quantity or price of an existing item.
    • Delete an item from the inventory.
    • View all items currently in the inventory.
  • Input Example:

    • Add new item: (Should ask for Item name, Quantity and Rate per unit)
    • Update price of Apples: (Should ask for item name and then price or quantity to be updated)
    • Delete item: The item name and amount should be requested before being deleted; if the quantity is the same as in inventory, the entire item object should be erased.

2. Billing System

  • Allow customers to purchase items from the inventory.

  • Deduct purchased quantities from the inventory.

  • Display a detailed bill including:

    • Item Name, Quantity, Unit Price, and Total Price for each item.
    • Final amount to be paid.
  • Input Example:

    It should ask for items in loop, when prompted to generate bill it should close the loop and show the bill.
    
  • Output Example: (For Reference)

    • Bill for the customer:
      Item       Quantity     Unit Price     Total  
      Apples     5            25             125  
      Bananas    10           10             100  
      --------------------------------------------  
      Total Amount: 225  
      

3. Income Management

  • Track and calculate the total income of the store from all bills generated.

  • Allow the user to:

    • View the daily income.
    • Compare it with the daily income target.
  • Input Example: (For reference)

    • Daily target: 1000
    • Bills generated:
      Bill 1: 225  
      Bill 2: 500  
      
  • Output Example:

    Total Income for the day: 725  
    Target: 1000  
    Difference: -275 (below target)  
    

Non-Functional Requirements:

  1. Data Persistence:

    • Inventory data must persist between program runs using a file.
    • Billing details should be saved in a file with timestamps.
  2. User Experience:

    • Clear prompts and error messages for invalid inputs.

Implementation Flow:

Step 1: Inventory Management

  1. Load inventory data from file (or create an empty file if it doesn’t exist).
  2. Provide options to:
    • Add new items.
    • Update or delete existing items.
    • View all items in the inventory.

Step 2: Billing System

  1. Allow the user to enter items and quantities purchased by a customer.
  2. Check inventory for availability.
  3. Generate and display the bill.
  4. Deduct purchased quantities from inventory and save the updated inventory to the file.
  5. Save the bill details to file.

Step 3: Income Management

  1. Read the bill to calculate total income for the day.
  2. Compare total income with the daily target.

Assignment 2 problem statement:

Assignment 4: Enhanced Log Generator and Analyzer

Topics Covered:

  • File Handling
  • Exception Handling
  • Lists
  • Modular Programming (functions and separate modules)
  • Optional: Console log formatting with colors using any library.

Problem Statement:

You are tasked to create a Log Generator and Analyzer tool that works in two modules:

  1. Log Generator Module:

    • This module generates a log file based on user input.
    • Users can specify:
      • File Path: Where the log file will be saved or which file to be modified.
      • Number of Lines: How many lines the log file should have.
    • Each line should include:
      • A log type chosen randomly from 5 types:
        • DEBUG, INFO, WARNING, ERROR, and CRITICAL.
      • A timestamp in ascending order (ensuring logs are chronologically ordered).
      • A random log message chosen from a fixed list provided by the user.
    • Optional: Add color formatting to logs in console.
  2. Log Analyzer Module:

    • This module analyzes the log file and provides insights.
    • It should allow the user to filter logs based on:
      • Date Range: Display logs within a specific date range.
      • Log Type: Filter logs by DEBUG, INFO, WARNING, ERROR, or CRITICAL.
      • Search Keyword: Display logs containing a specific keyword in the message.
    • Generate a filtered log file (filtered_logs.log) based on user-selected filters.
    • Count and display the total number of each log type (DEBUG, INFO, etc.) in the filtered logs.
    • Identify and display the most frequent log type in the log file.
    • Handle invalid user inputs, such as:
      • File not found.
      • Invalid date range.
      • Log file not containing any matching logs.

Implementation Details:

Log Generator Module

  1. Input Requirements:

    • File path for the log file (server.log).
    • Number of lines to generate.
    • Fixed list of log messages.
  2. Log Structure:

    [LOG_TYPE] YYYY-MM-DD HH:MM:SS: Random Log Message  
    
  3. Key Tasks:

    • Validate the file path.
    • Randomly select a log type from DEBUG, INFO, WARNING, ERROR, and CRITICAL.
    • Generate a log message from the fixed list.
    • Ensure timestamps are in ascending order (start with the current time and increment).
    • Write logs to the specified file.
  4. Example Logs:

    [INFO] 2025-01-27 09:30:10: Application started successfully.  
    [WARNING] 2025-01-27 09:35:15: High CPU usage detected.  
    [ERROR] 2025-01-27 09:40:20: Unable to connect to database.  
    [DEBUG] 2025-01-27 09:45:25: Function 'process_data' executed.  
    [CRITICAL] 2025-01-27 09:50:30: System failure! Immediate attention required.  
    
  5. Optional Colors (Console Display):

    • Use the colorama library to color logs as:
      • DEBUG: White
      • INFO: Green
      • WARNING: Yellow
      • ERROR: Red
      • CRITICAL: Bold Red

Log Analyzer Module

  1. Input Requirements:

    • File path of the log file to analyze.
    • Filter options:
      • Date Range: Start date and end date.
      • Log Type: Choose one or more types (e.g., INFO, ERROR).
      • Search Keyword: Any word or phrase to search in log messages.
  2. Analysis Tasks:

    • Validate the file path.
    • Filter logs based on:
      • Date Range: Only include logs within the specified range.
      • Log Type: Filter logs matching the selected type(s).
      • Keyword: Include logs containing the keyword in their message.
    • Write the filtered logs to a file.
    • Count and display the total number of logs for each type in the filtered logs.
    • Identify and display the most frequent log type.
  3. Output Example:

    • Filtered Logs (filtered_logs.txt):

      [INFO] 2025-01-27 09:30:10: Application started successfully.  
      [ERROR] 2025-01-27 09:40:20: Unable to connect to database.  
      
    • Analysis Output (Console):

      Total Logs Analyzed: 50  
      Filtered Logs: 10  
      Count by Type:  
        DEBUG: 2  
        INFO: 4  
        WARNING: 1  
        ERROR: 2  
        CRITICAL: 1  
      Most Frequent Log Type: INFO  
      

Additional Challenges:

  1. Handle Invalid Inputs:

    • File not found: Display an error message and prompt the user to enter a valid file path.
    • Invalid date range: Ensure the start date is earlier than the end date.
    • Empty filtered logs: Display a message if no logs match the filters.
  2. Dynamic Log Message Input (for Generator):

    • Allow users to add custom log messages before generating the file.
  3. Performance Considerations (Optional):

    • Optimize file reading for large log files using buffered reading or line-by-line processing.

Exception Handling:

  1. File Handling Exceptions:

    • FileNotFoundError: If the file path doesn’t exist.
    • PermissionError: If the user doesn’t have write permissions.
  2. Input Validation Exceptions:

    • Handle invalid date formats.
    • Ensure numeric inputs (e.g., number of lines to generate) are valid integers.
  3. KeyError / IndexError:

    • Handle issues when accessing non-existent data (e.g., missing log type in user input).

Assignment 3 problem statement:

Problem 1: Data Analysis with Nested Control Flow and File Handling

Problem Statement: You are working for an NGO that receives daily reports of donations and their details in multiple text files. Each file contains information in the following format:

Date: YYYY-MM-DD
Donor: <Name>
Amount: <Integer>
Payment Method: <Cash/Card/UPI>
------------------------------------

The NGO wants a Python program to process these files and generate a summary report. The program should do the following:

  1. Input:

    • Accept the path to a folder containing multiple .txt files. Each file follows the above format and contains records for a single day.
    • If the path is invalid or the folder is empty, the program should raise appropriate exceptions.
  2. Tasks:

    • Parse all files and extract data for donations. Ensure each file is processed only once.
    • Calculate the total donation amount, number of donations per payment method, and donor with the highest total donation amount across all files.
    • Detect and log any anomalies:
      • Donations with amounts <= 0.
      • Missing or corrupted fields (e.g., missing "Date" or "Amount").
      • Save these anomalies into a separate anomalies.txt file.
  3. Output:

    • Save the summary as a new summary_report.txt file in the same folder with the following format:
      Total Donations: <Integer>
      Donations by Payment Method:
          Cash: <Integer>
          Card: <Integer>
          UPI: <Integer>
      Top Donor: <Name> (<Total Donation>)
      
    • If no valid data exists, print an appropriate message and do not generate the report.

Constraints:

  • Use control flow (if-else, loops) to handle complex conditions like anomalies and processing logic.
  • Use functions for modular design (e.g., one for reading files, one for processing data, one for generating the report).
  • Use dictionaries for tracking donors and payment method counts.
  • Handle file reading/writing operations with proper exception handling (e.g., FileNotFoundError, IOError).

Assignmet 4 problem statement :

Advanced Customer Feedback and Analytics Management System

Problem Statement

Create an Advanced Customer Feedback and Analytics Management System for a café. This system should allow the café to collect, store, analyze, and manage customer feedback with robust features. The program should simulate an industry-standard application with modularity, clean data management, and detailed reports.

Key Features and Complexity

1. Modular System Architecture

Split the system into multiple modules to allow for separation of concerns. Interns should create:

  • Feedback Module: Manages the collection, storage, and validation of feedback.
  • Analytics Module: Responsible for generating insights, aggregating data, and computing statistics.
  • File Management Module: Handles all file operations (read/write JSON, export data).
  • Search Module: Manages searching and filtering of data.
  • Visualization Module: Manages any ASCII-based visual output (ratings distribution, feedback length).
  • Cleanup Module: Handles data cleaning and removal of old feedback.
  • Exception Handling Module: Catches errors and ensures smooth operation.

Each of these modules should be designed in separate Python files and should be easily extensible for future modifications. This will ensure the interns are thinking in terms of software architecture and reusability.


2. Feedback Management (Core Features)

  1. Add Feedback:

    • Validate Input: Ratings should be integers between 1-5. Ensure comments are not empty.
    • Multiline Comments: Comments should accept multiline input, terminated by END.
    • Store Order Details: Allow the user to input the list of items ordered (e.g., "Coffee, Sandwich"). Handle case sensitivity, extra spaces, and invalid entries.
    • Automatic Timestamps: Save feedback with an automatically generated timestamp using datetime.now().
  2. Persistent Storage:

    • JSON File: Store feedback in a structured format in a JSON file. If the file doesn’t exist, create it. Handle cases where the file might get corrupted or data is missing.

3. Advanced Analytics

  1. Calculate Rating Distribution:

    • Display the number of feedback entries for each rating from 1 to 5 using hash-based ASCII art.
    • Additionally, compute and display the median rating using Python’s statistics.median() function.
  2. Generate Feedback Statistics:

    • Most Common Feedback: Identify the most frequently mentioned word(s) in comments (excluding stopwords like "the", "and").
    • Sentiment Analysis: Categorize each comment as Positive, Neutral, or Negative based on specific keywords. Implement a simple logic (e.g., if the comment contains "good", "excellent", it’s Positive; if it contains "bad", it’s Negative).
  3. Most Ordered Items:

    • Aggregate the most ordered menu items by counting occurrences. Use Python’s collections.Counter to track the frequency of items.
  4. Advanced Aggregations:

    • Feedback by Day: Show the number of feedback entries received on a given date.
    • Feedback by Hour: Provide analytics of feedback based on the time of day it was submitted.
    • Implement efficient algorithms for this using the datetime module and proper sorting.

4. Search & Filtering (Advanced Search Logic)

  1. Search by Customer Name: Look for feedback from a specific customer.
  2. Search by Rating: Allow users to filter feedback by rating (e.g., show only 5-star ratings).
  3. Search by Date: Allow filtering feedback based on a specific date or range of dates.
  4. Keyword-Based Search: Implement a flexible search by comment content, matching substrings (not just exact words).

5. Data Export and Reporting

  1. Export Feedback Data:

    • Save the raw feedback in a formatted text file (feedback_raw.txt).
    • Save detailed insights into a separate report file (feedback_insights.txt), including statistics like average rating, most common items, and sentiment analysis.
  2. CSV Export: Add an option to export feedback and insights to a CSV file. The intern should implement a custom function to write feedback to CSV format:

    Name, Rating, Comments, Date, Order
    John, 5, "Great service!", 2025-01-27, "Coffee, Sandwich"
    
  3. Email Report (Bonus): Implement a mock email functionality that generates a summary of the day’s feedback and sends it to a pre-defined recipient. This could be done by writing the report as a text file, with the email sending function simply being a placeholder.


6. Data Cleanup

  1. Remove Feedback Older Than X Days:

    • Prompt the user to specify a number of days. Delete feedback older than this threshold from the feedback file.
    • Ensure feedback is properly cleaned from both the JSON file and any other export files (e.g., feedback_raw.txt).
  2. Archiving Feedback:

    • Before deleting any old feedback, archive it into a separate folder (archived_feedback/) by copying the JSON content to a separate file. This ensures data is not lost, and a backup is available.

7. Performance Considerations

  • Efficient Aggregation: When computing statistics (like the average rating, rating distribution, most common items), ensure that the program doesn’t re-scan the entire dataset multiple times. Use efficient data structures and algorithms.

  • File I/O Optimization: Minimize the number of times the program reads and writes to files. Implement an in-memory cache for feedback data and write to files only when necessary (e.g., when data changes or the user explicitly requests it).


8. Exception Handling

  • Input Validation: Ensure all user inputs are validated (e.g., ratings, dates, comments).
  • File Handling Errors: Catch any errors during file reading and writing operations and prompt the user with useful messages (e.g., "File not found" or "Invalid file format").
  • Empty Feedback Handling: Handle the case when no feedback is available, ensuring that the program doesn't crash or produce errors when generating insights or reports.

Expected Program Workflow

Welcome to the Advanced Customer Feedback System

1. Add Feedback
2. Generate Insights
3. Export Data
4. Search Feedback
5. Advanced Filtering
6. Feedback Cleanup
7. Exit

Enter your choice: 1

Enter Customer Name: John
Enter Rating (1-5): 5
Enter Comments (type 'END' to finish):
Great service and delicious food!
END
Enter Order Details: Coffee, Sandwich

Feedback added successfully!

Enter your choice: 2

Generating Insights...
Average Rating: 4.5
Ratings Distribution:
5 stars: #### (4 customers)
4 stars: ### (3 customers)
3 stars: ## (2 customers)
2 stars: # (1 customer)

Most Ordered Item: Coffee
Sentiment: Positive

Enter your choice: 3
Exporting Data...
Data exported successfully to `feedback_raw.txt` and `feedback_insights.txt`.

Enter your choice: 4
Search Feedback:
1. By Name
2. By Rating
3. By Date
4. By Keyword
Enter your choice: 2
Enter rating: 5
Results: (List of 5-star feedback)

Enter your choice: 7
Exiting program. Goodbye!

Skills & Concepts Covered

  • Modular Programming: Building a clean and structured system with multiple modules.
  • Advanced Data Handling: Efficient algorithms for analyzing and aggregating large datasets.
  • File Management: Complex file reading, writing, and error handling.
  • Data Persistence: Storing data across program runs using JSON and CSV.
  • Exception Handling: Gracefully managing errors and invalid inputs.
  • Text-Based Visualizations: Representing data with ASCII art.
  • Optimizations: Implementing performance-friendly data aggregation and file operations.
  • Backup and Archiving: Handling data deletion and archiving.


assignment 5 problem statement:

Assignment: "Mystery Vault Simulation"

Problem Statement:

You are tasked with creating a Mystery Vault Simulation program. The Mystery Vault is a digital system where users can store "vault items" under various vault categories (e.g., treasures, puzzles, secrets) and manage them. Each vault can contain encrypted information that only authorized users with valid passcodes can access.

The program should handle multiple vaults and allow users to perform operations like creating vaults, adding items, viewing decrypted items, and even recovering deleted items.

This program should heavily emphasize Python basics, control flow, operators, functions, file handling, exception handling, and object-oriented programming.


Requirements:

1. Vault Features:

  • Each vault should have:

    • A unique vault name.
    • A category (e.g., "Puzzles," "Secrets," or "Treasures").
    • A secure 4-digit passcode.
    • A list of stored items.
  • Users should be able to:

    1. Create a vault: Provide the name, category, and a passcode.
    2. Add items to a vault: Enter an item that is encrypted before storage.
    3. View vault items: Decrypt and display items only after validating the passcode.
    4. Delete items: Mark items as "deleted" but allow recovery.
    5. Recover items: Restore previously deleted items.
    6. Export items: Save vault items to a file for backup.

2. Data Management:

  • Store and retrieve vault data using file handling.
    • Each vault should have a corresponding text file (vault_<vault_name>.txt) storing:
      • Metadata (name, category, passcode).
      • Encrypted items.
      • Deleted items (if any).

3. Security & Validations:

  • Passcode Validation:
    • Users must enter the correct 4-digit passcode to access a vault.
    • Lock access after three failed attempts.
  • Vault Name Validation:
    • Ensure unique vault names.
    • Reject invalid or empty names.

4. Encryption (Basic):

  • Use a basic encryption logic (e.g., shifting characters using ASCII).
    • Example: For each character in the item, shift it by a fixed number (e.g., +3).
    • Store only the encrypted version in the vault file.

5. Control Flow & Loops:

  • Use loops to display a menu repeatedly until the user exits.
  • Include conditions for validating inputs (e.g., numeric passcodes, unique vault names).

6. Error Handling:

  • Handle exceptions for:
    • Invalid passcodes or vault names.
    • File-related errors (e.g., file not found when recovering vaults).
    • Failed decryption attempts.

7. Object-Oriented Design:

  • Vault Class:

    • Attributes: Name, category, passcode, items (list), deleted_items (list).
    • Methods:
      • add_item: Encrypt and store an item.
      • view_items: Decrypt and display items after passcode verification.
      • delete_item: Move an item to the deleted_items list.
      • recover_item: Restore an item from deleted_items to items.
      • export_items: Write the current items to a file.
  • VaultManager Class:

    • Manages all vaults.
    • Methods:
      • create_vault: Add a new vault.
      • get_vault: Retrieve a specific vault by name.
      • list_vaults: Display all available vaults.

Functional Requirements:

1. Main Menu:

Display the following options:

  1. Create a Vault
  2. Add Item to Vault
  3. View Vault Items
  4. Delete Vault Item
  5. Recover Deleted Item
  6. Export Vault Items
  7. Exit

2. Example Interaction:

  1. Create a Vault:

    • Input: "Vault Name: SecretBox," "Category: Secrets," "Passcode: 1234."
    • Output: "Vault 'SecretBox' created."
  2. Add Item to Vault:

    • Input: Vault Name: SecretBox, Passcode: 1234, Item: "Hidden Map."
    • Output: "Item encrypted and added to the vault."
  3. View Vault Items:

    • Input: Vault Name: SecretBox, Passcode: 1234.
    • Output: "Decrypted Items: ['Hidden Map']."
  4. Delete an Item:

    • Input: Vault Name: SecretBox, Passcode: 1234, Item: "Hidden Map."
    • Output: "Item 'Hidden Map' moved to deleted items."
  5. Recover an Item:

    • Input: Vault Name: SecretBox, Passcode: 1234.
    • Output: "Item 'Hidden Map' recovered."
  6. Export Vault Items:

    • Input: Vault Name: SecretBox, Passcode: 1234.
    • Output: "Vault items exported to 'vault_SecretBox.txt'."

Example File Output (vault_SecretBox.txt):

Vault Name: SecretBox
Category: Secrets
Passcode: 1234
Items (Encrypted): [\u201chpgh#Map\u201d]  # Basic character shift encryption
Deleted Items: []

Challenges:

1. Encryption:

  • Use a custom logic to encrypt and decrypt items (e.g., shift characters or replace letters).
  • Ensure data security so users cannot directly read the files.

2. File Handling:

  • Manage multiple vault files, one for each vault.
  • Ensure files persist across multiple program runs.

3. Validations:

  • Handle edge cases:
    • Empty vault names.
    • Duplicate vault names.
    • Invalid passcodes.

4. Multi-Vault Support:

  • Allow multiple vaults with independent passcodes and data.

Submission Guidelines:

  • Submit a single Python file containing the full implementation.
  • Ensure your code is modular and uses classes effectively.
  • Include comments for readability.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages