- Understand what Task 4a requires
- Learn to analyze system and user requirements
- Identify what needs to be added to existing code
- Plan your coding approach effectively
- Understand secure coding requirements
What is Task 4a?
Task 4a is the coding task where you extend existing Python code to add new functionality. You'll receive:
- A CSV file with sales data (Date, Car Model, New/Used, Value, Salesperson)
- Existing Python code that already works
- New system and user requirements to implement
- 4 hours to complete the task
Understanding the Scenario
Context: T-Learn Automotives (or similar company) has a working sales analysis system. They want additional features added.
What You're Given
- Task4a_data.csv: Sales records with Date, Car Model, New/Used, Value, Salesperson
- Task4a_code.py: Working Python code from a "Senior Developer"
- New requirements: Additional functionality to implement
What the Existing Code Does
The provided code typically includes:
- Menu system for user interaction
- CSV file reading with pandas
- Basic data analysis (e.g., total sales by model)
- Some data visualization
Your job: Add NEW features while keeping existing code working.
Reading the Requirements
System Requirements
These tell you WHAT functionality to add:
- Example: "Identify trends and patterns over time for new and used car sales"
- Example: "Identify trends and patterns for different salespeople"
- Example: "The solution must be secure"
User Requirements
These tell you HOW to present the solution:
- Easy to use: Clear menus, input validation, helpful messages
- Display information meaningfully: Organized, clear labels, appropriate formatting
- Textual, numerical, and graphical output: Use text, numbers, AND graphs
Breaking Down the Requirements
Example Requirement Analysis
Requirement: "Identify trends and patterns over time for new and used car sales"
What this means:
- Separate data into "New" and "Used" categories
- Show how sales change over time (by date/month)
- Calculate totals for each category
- Create visualizations showing trends
What you need to code:
- Filter data by New/Used column
- Group by date or time period
- Calculate sums for each group
- Create line graph or bar chart
- Add menu option for this feature
Example Requirement Analysis 2
Requirement: "Identify trends and patterns for different salespeople"
What this means:
- Analyze sales performance by salesperson
- Show totals, averages, or counts per salesperson
- Compare salespeople performance
- Visualize the comparison
What you need to code:
- Group data by Salesperson column
- Calculate metrics (total sales, number of sales, average value)
- Create bar chart comparing salespeople
- Add menu option for this feature
Planning Your Approach
Step 1: Read the Existing Code
- Understand how the menu system works
- See how CSV data is loaded
- Identify existing functions and their purpose
- Note the coding style and conventions used
Step 2: List What Needs Adding
Create a checklist:
- ☐ New menu options
- ☐ New functions for each feature
- ☐ Data filtering/grouping logic
- ☐ Calculations required
- ☐ Visualizations needed
- ☐ Input validation
- ☐ Security measures
Step 3: Plan Your Functions
For each new feature, plan:
- Function name: descriptive and consistent with existing code
- Parameters: what data does it need?
- Processing: what calculations/operations?
- Output: what does it display/return?
Security Requirements
"The solution must be secure" means you need to:
Input Validation
- Validate user menu choices
- Check file exists before opening
- Handle invalid data gracefully
- Use try-except blocks
Error Handling
- Catch file not found errors
- Handle invalid data types
- Prevent program crashes
- Display helpful error messages
Data Validation
- Check CSV has expected columns
- Validate data types (numbers are numbers, dates are dates)
- Handle missing or empty values
Code Quality Requirements
Maintainable Code
- Use clear function names
- Add comments explaining complex logic
- Keep functions focused on one task
- Avoid code duplication
Readable Code
- Use meaningful variable names
- Consistent indentation (4 spaces)
- Blank lines between functions
- Follow existing code style
Functional Code
- Code must run without errors
- All features must work as specified
- Existing functionality must still work
- Outputs must be correct
Common Requirements Patterns
Pattern 1: Comparison Analysis
Compare two categories (New vs Used, Salesperson A vs B)
- Filter data into groups
- Calculate totals for each group
- Create side-by-side bar chart
- Display numerical comparison
Pattern 2: Trend Over Time
Show how something changes over time
- Group data by date/month
- Calculate totals for each period
- Create line graph
- Show increasing/decreasing trends
Pattern 3: Top Performers
Identify best/worst in a category
- Group and sum by category
- Sort by value
- Display top N results
- Create bar chart of top performers
Exam Strategy
Initial Steps
- Read ALL requirements carefully
- Run the existing code to see how it works
- Examine the CSV data structure
- Plan what functions you need to add
- Sketch out menu structure
Main Coding Phase
- Start with menu additions
- Code one feature at a time
- Test each feature before moving on
- Add error handling as you go
- Keep existing code working
Final Steps
- Test all features thoroughly
- Add any missing error handling
- Improve code comments
- Check code quality
- Save files correctly (PDF, .txt, .py)
Tips for Success
Understanding Requirements
- Highlight key words in requirements
- List each feature separately
- Identify what data columns you need
- Note what outputs are required
Working with Existing Code
- Understand the existing structure and style
- Follow the same coding conventions
- Reuse existing functions where possible
- Test that your changes work correctly
Adding New Features
- Add new menu options to existing menu
- Create new functions for new features
- Use pandas for data manipulation
- Use matplotlib for visualizations
- Test incrementally