Independent Practical Task
14. Independent Practical Task
Now complete the following exercises independently.
The exercises are arranged from beginner to advanced level.
D. Practical Programming Tasks (2)
Question 12. Monthly Electricity Consumption
A household records electricity consumption over six months.
| Month |
Units Consumed |
| January |
250 |
| February |
280 |
| March |
260 |
| April |
300 |
| May |
320 |
| June |
350 |
Create a line chart that:
- Displays monthly electricity consumption.
- Includes a title and axis labels.
- Uses a blue line with circular markers.
- Displays gridlines.
- Shows the numerical values beside each point.
- Explains the overall trend.
Question 13. Compare Two Departments
A university wants to compare student enrollment in two departments.
| Month |
Computer Science |
Mathematics |
| January |
40 |
30 |
| February |
45 |
35 |
| March |
50 |
38 |
| April |
55 |
42 |
| May |
65 |
45 |
| June |
70 |
50 |
Create a multiple line chart that:
- Displays both departments.
- Uses different colors and markers.
- Uses different line styles.
- Includes a title and axis labels.
- Displays a legend.
- Displays gridlines.
- Identifies which department has higher enrollment.
Exercise 1: Beginner – Monthly Shop Sales
Scenario
A shop owner wants to monitor monthly sales.
Use the following dataset:
| Month |
Sales (PKR) |
| January |
20,000 |
| February |
25,000 |
| March |
22,000 |
| April |
30,000 |
| May |
35,000 |
| June |
40,000 |
| July |
38,000 |
| August |
45,000 |
| September |
50,000 |
| October |
48,000 |
| November |
55,000 |
| December |
65,000 |
Requirements
- Prepare two Python lists.
- Create a line chart using
plt.plot().
- Add an appropriate chart title.
- Label both axes.
- Change the line color to green.
- Add circular markers.
- Display gridlines.
- Display the chart.
Questions
- Which month has the highest sales?
- Which month has the lowest sales?
- During which month did sales decrease?
- What is the overall sales trend?
Scenario
A teacher records the attendance of students over 15 working days.
Use the following dataset:
| Day |
Students Present |
| Day 1 |
35 |
| Day 2 |
38 |
| Day 3 |
36 |
| Day 4 |
40 |
| Day 5 |
42 |
| Day 6 |
39 |
| Day 7 |
43 |
| Day 8 |
45 |
| Day 9 |
41 |
| Day 10 |
44 |
| Day 11 |
46 |
| Day 12 |
48 |
| Day 13 |
45 |
| Day 14 |
47 |
| Day 15 |
50 |
Requirements
- Prepare the attendance dataset.
- Create a line chart.
- Add a suitable title.
- Label the X-axis and Y-axis.
- Add circular markers.
- Change the line color.
- Add gridlines.
- Display data labels for each point.
- Rotate the X-axis labels if necessary.
Questions
- Which day has the highest attendance?
- Which day has the lowest attendance?
- How many students were present on Day 10?
- Did attendance generally increase or decrease?
Exercise 3: Advanced – Department-wise Student Enrollment
Scenario
A university wants to compare enrollment in three departments over 12 months.
Use the following dataset:
| Month |
Computer Science |
IT |
Mathematics |
| Jan |
50 |
40 |
30 |
| Feb |
55 |
45 |
32 |
| Mar |
60 |
48 |
35 |
| Apr |
65 |
55 |
38 |
| May |
70 |
60 |
40 |
| Jun |
75 |
65 |
45 |
| Jul |
80 |
70 |
48 |
| Aug |
85 |
75 |
50 |
| Sep |
90 |
80 |
55 |
| Oct |
95 |
85 |
58 |
| Nov |
100 |
90 |
60 |
| Dec |
110 |
100 |
65 |
Requirements
- Prepare four Python lists.
- Create a multiple line chart.
- Display all three departments on the same chart.
- Use different colors for each department.
- Use different markers.
- Use different line styles.
- Add a chart title.
- Label both axes.
- Add a legend.
- Add gridlines.
- Display the chart using
plt.show().
Questions
- Which department has the highest enrollment?
- Which department has the lowest enrollment?
- Which department shows the greatest overall growth?
- Do all three departments show an increasing trend?
- Why is a multiple line chart suitable for this comparison?