assignment 1 problem statement :
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.
Develop a Store Inventory and Billing System with Income Management for a small business. The application should manage:
-
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.
-
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.
-
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.
-
Error Handling:
- Handle exceptions, such as invalid item inputs, quantities exceeding availability, or file errors.
-
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.
- Add new item:
-
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
- Bill for the customer:
-
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
- Daily target:
-
Output Example:
Total Income for the day: 725 Target: 1000 Difference: -275 (below target)
-
Data Persistence:
- Inventory data must persist between program runs using a file.
- Billing details should be saved in a file with timestamps.
-
User Experience:
- Clear prompts and error messages for invalid inputs.
- Load inventory data from file (or create an empty file if it doesn’t exist).
- Provide options to:
- Add new items.
- Update or delete existing items.
- View all items in the inventory.
- Allow the user to enter items and quantities purchased by a customer.
- Check inventory for availability.
- Generate and display the bill.
- Deduct purchased quantities from inventory and save the updated inventory to the file.
- Save the bill details to file.
- Read the bill to calculate total income for the day.
- Compare total income with the daily target.
Assignment 2 problem statement:
- File Handling
- Exception Handling
- Lists
- Modular Programming (functions and separate modules)
- Optional: Console log formatting with colors using any library.
You are tasked to create a Log Generator and Analyzer tool that works in two modules:
-
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, andCRITICAL.
- A timestamp in ascending order (ensuring logs are chronologically ordered).
- A random log message chosen from a fixed list provided by the user.
- A log type chosen randomly from 5 types:
- Optional: Add color formatting to logs in console.
-
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, orCRITICAL. - 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.
-
Input Requirements:
- File path for the log file (
server.log). - Number of lines to generate.
- Fixed list of log messages.
- File path for the log file (
-
Log Structure:
[LOG_TYPE] YYYY-MM-DD HH:MM:SS: Random Log Message -
Key Tasks:
- Validate the file path.
- Randomly select a log type from
DEBUG,INFO,WARNING,ERROR, andCRITICAL. - 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.
-
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. -
Optional Colors (Console Display):
- Use the
coloramalibrary to color logs as:DEBUG: WhiteINFO: GreenWARNING: YellowERROR: RedCRITICAL: Bold Red
- Use the
-
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.
-
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.
-
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
-
-
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.
-
Dynamic Log Message Input (for Generator):
- Allow users to add custom log messages before generating the file.
-
Performance Considerations (Optional):
- Optimize file reading for large log files using buffered reading or line-by-line processing.
-
File Handling Exceptions:
FileNotFoundError: If the file path doesn’t exist.PermissionError: If the user doesn’t have write permissions.
-
Input Validation Exceptions:
- Handle invalid date formats.
- Ensure numeric inputs (e.g., number of lines to generate) are valid integers.
-
KeyError / IndexError:
- Handle issues when accessing non-existent data (e.g., missing log type in user input).
Assignment 3 problem statement:
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:
-
Input:
- Accept the path to a folder containing multiple
.txtfiles. 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.
- Accept the path to a folder containing multiple
-
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.txtfile.
-
Output:
- Save the summary as a new
summary_report.txtfile 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.
- Save the summary as a new
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 :
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.
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.
-
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().
-
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.
-
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.
-
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).
-
Most Ordered Items:
- Aggregate the most ordered menu items by counting occurrences. Use Python’s
collections.Counterto track the frequency of items.
- Aggregate the most ordered menu items by counting occurrences. Use Python’s
-
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
datetimemodule and proper sorting.
- Search by Customer Name: Look for feedback from a specific customer.
- Search by Rating: Allow users to filter feedback by rating (e.g., show only 5-star ratings).
- Search by Date: Allow filtering feedback based on a specific date or range of dates.
- Keyword-Based Search: Implement a flexible search by comment content, matching substrings (not just exact words).
-
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.
- Save the raw feedback in a formatted text file (
-
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" -
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.
-
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).
-
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.
- Before deleting any old feedback, archive it into a separate folder (
-
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).
- 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.
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!
- 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"
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.
-
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:
- Create a vault: Provide the name, category, and a passcode.
- Add items to a vault: Enter an item that is encrypted before storage.
- View vault items: Decrypt and display items only after validating the passcode.
- Delete items: Mark items as "deleted" but allow recovery.
- Recover items: Restore previously deleted items.
- Export items: Save vault items to a file for backup.
- 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).
- Each vault should have a corresponding text file (
- 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.
- 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.
- Example: For each character in the item, shift it by a fixed number (e.g.,
- Use loops to display a menu repeatedly until the user exits.
- Include conditions for validating inputs (e.g., numeric passcodes, unique vault names).
- Handle exceptions for:
- Invalid passcodes or vault names.
- File-related errors (e.g., file not found when recovering vaults).
- Failed decryption attempts.
-
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.
Display the following options:
- Create a Vault
- Add Item to Vault
- View Vault Items
- Delete Vault Item
- Recover Deleted Item
- Export Vault Items
- Exit
-
Create a Vault:
- Input: "Vault Name: SecretBox," "Category: Secrets," "Passcode: 1234."
- Output: "Vault 'SecretBox' created."
-
Add Item to Vault:
- Input: Vault Name: SecretBox, Passcode: 1234, Item: "Hidden Map."
- Output: "Item encrypted and added to the vault."
-
View Vault Items:
- Input: Vault Name: SecretBox, Passcode: 1234.
- Output: "Decrypted Items: ['Hidden Map']."
-
Delete an Item:
- Input: Vault Name: SecretBox, Passcode: 1234, Item: "Hidden Map."
- Output: "Item 'Hidden Map' moved to deleted items."
-
Recover an Item:
- Input: Vault Name: SecretBox, Passcode: 1234.
- Output: "Item 'Hidden Map' recovered."
-
Export Vault Items:
- Input: Vault Name: SecretBox, Passcode: 1234.
- Output: "Vault items exported to 'vault_SecretBox.txt'."
Vault Name: SecretBox
Category: Secrets
Passcode: 1234
Items (Encrypted): [\u201chpgh#Map\u201d] # Basic character shift encryption
Deleted Items: []
- 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.
- Manage multiple vault files, one for each vault.
- Ensure files persist across multiple program runs.
- Handle edge cases:
- Empty vault names.
- Duplicate vault names.
- Invalid passcodes.
- Allow multiple vaults with independent passcodes and data.
- Submit a single Python file containing the full implementation.
- Ensure your code is modular and uses classes effectively.
- Include comments for readability.