TalentJR

🐍 Python for kids · Class 7 · Lesson 6 of 18 · Free

Data Projects – Find the Story in Numbers

⏱ About 35 minutes · ▶ run real Python here — nothing to install · no sign-in

In this lesson you will

  • Work out the total, average, highest and lowest of a data list.
  • Draw a text bar chart from a dictionary of values.
  • Plan and build a small data project with functions, lists and dictionaries.

Which month had the most rain in your city? Which snack sells best in the canteen? People answer such questions with data. Today you will turn plain lists of numbers into clear answers and simple charts.

What is a data project?

A data project starts with a question, like "Which day was hottest this week?"

Then you collect data, clean it, work out answers, and show the result clearly.

You already have every tool you need: lists, dictionaries, loops and functions from Lessons 1 to 5.

Real data scientists use bigger tools later, but the thinking is exactly the same.

🎬 How Python thinks — step 1 of 5Python is about to run line 1
▶temps = [31, 33, 35, 34, 36, 32, 30]
2print("Days recorded:", len(temps))
3print("Hottest:", max(temps))
4print("Coolest:", min(temps))
📦 Variables (memory boxes)

No variables yet.

🖥️ Output
▌
✏️ Change this code and run it yourself
🐍 Python — you can edit this code
Output
Days recorded: 7
Hottest: 36
Coolest: 30

How do I find the average of a list in Python?

The average, or mean, is the total divided by how many values there are.

sum() gives the total and len() gives the count. round(x, 1) keeps one digit after the point.

Always check that the list is not empty first. Dividing by zero crashes the program.

🎬 How Python thinks — step 1 of 9Python is about to run line 1
▶def average(values):
2 if len(values) == 0:
3 return 0
4 return round(sum(values) / len(values), 1)
5
6runs = [45, 12, 78, 33, 61]
7print("Average runs:", average(runs))
8print("Empty list:", average([]))
📦 Variables (memory boxes)

No variables yet.

🖥️ Output
▌
✏️ Change this code and run it yourself
🐍 Python — you can edit this code
Output
Average runs: 45.8
Empty list: 0

How do I find which item has the highest value?

max() gives the biggest number, but often you want to know whose number it is.

Store the data in a dictionary, then loop and remember the best key so far.

This "best so far" pattern works for top scorer, rainiest month or cheapest shop.

best starts at -1, lower than any real value. So the very first month always becomes the best so far.

🎬 How Python thinks — step 1 of 18Python is about to run line 1
▶rain_mm = {"Jun": 520, "Jul": 840, "Aug": 610, "Sep": 330}
2best_month = ""
3best = -1
4for month, mm in rain_mm.items():
5 if mm > best:
6 best = mm
7 best_month = month
8print(f"Rainiest month: {best_month} with {best} mm")
📦 Variables (memory boxes)

No variables yet.

🖥️ Output
▌
✏️ Change this code and run it yourself
🐍 Python — you can edit this code
Output
Rainiest month: Jul with 840 mm

💡 These numbers are made up, but they look like Mumbai's monsoon months.

How do I make a bar chart in Python without a library?

A picture shows a pattern faster than a table. You can draw bars with text.

"#" * 5 gives five # signs. So each bar is a # repeated once for every unit of data.

If the numbers are large, divide them first so the bars fit on the screen.

For example, with sales in the hundreds, draw one # for every 10 items using n // 10.

🐍 Python — you can edit this code
Output
Canteen sales today
Samosa   |############## 14
Idli     |######### 9
Sandwich |###### 6
Poha     |########### 11

💡 {item:9} pads each name to 9 characters, so all the bars start in the same column.

How do I clean messy data before using it?

Real data is messy. People type extra spaces, mix capital letters, or leave answers blank.

Cleaning means fixing these before counting. strip() removes spaces and lower() makes all letters small.

Skip empty answers with continue, so they do not become a fake category.

Without cleaning, Cricket and CRICKET would be counted as two different sports.

🐍 Python — you can edit this code
Output
{'cricket': 3, 'football': 1, 'kabaddi': 1}

How do I put a full data project together?

Let us join every step. A class survey asks how many hours each student sleeps.

One function cleans and stores the answers. Another builds a summary. A third prints a report.

Splitting the work this way makes each part easy to test and easy to change later.

🐍 Python — you can edit this code
Output
Student 1 sleep hours: 9
Student 2 sleep hours: 7
Student 3 sleep hours: 8
Student 4 sleep hours: 6
Student 5 sleep hours: 9
Student 6 sleep hours: 10
Average sleep: 8.2 hours
less than 8 |## 2
8 or more   |#### 4

💡 Doctors suggest about 9 hours of sleep at your age. What does your class data say?

🤔 Predict the output

Think like Python: read the code and choose what it prints. You get the reason straight away.

Question 1. What does this print?

marks = [60, 80, 70, 90]
print(sum(marks) / len(marks))

Question 2. What does this print?

data = {"A": 3, "B": 1}
for k, v in data.items():
    print(k + "*" * v)

Question 3. What does this print?

words = [" Mango", "mango ", "APPLE"]
clean = set()
for w in words:
    clean.add(w.strip().lower())
print(len(clean))

🧩 Your challenge

Pocket-money tracker. Read how much you spent on each of 5 days into a list. Print the total, the average (1 decimal place), the highest day number and amount, and a text bar chart with one # for every 10 rupees.

Expected output (with the inputs given):
Day 1 spend: 40
Day 2 spend: 25
Day 3 spend: 70
Day 4 spend: 10
Day 5 spend: 55
Total: 200
Average: 40.0
Highest: day 3, 70 rupees
Day 1 |#### 40
Day 2 |## 25
Day 3 |####### 70
Day 4 |# 10
Day 5 |##### 55
🐍 Python — you can edit this code

⚠️ Common mistakes (and how to fix them)

❌ Wrong

scores = []
print(sum(scores) / len(scores))

ZeroDivisionError: division by zero

✅ Right

scores = []
if len(scores) > 0:
    print(sum(scores) / len(scores))
else:
    print("No data yet")

An empty list has length 0, and dividing by 0 is not allowed. Check the length first.

❌ Wrong

votes = ["Tea", "tea", "Coffee", "tea "]
count = {}
for v in votes:
    count[v] = count.get(v, 0) + 1
print(count)

No error message – but tea is split into three groups: 'Tea', 'tea' and 'tea '.

✅ Right

votes = ["Tea", "tea", "Coffee", "tea "]
count = {}
for v in votes:
    v = v.strip().lower()
    count[v] = count.get(v, 0) + 1
print(count)

Python sees different spellings as different keys. Clean each answer with strip() and lower() before counting.

❌ Wrong

prices = ["20", "35", "15"]
print(sum(prices))

TypeError: unsupported operand type(s) for +: 'int' and 'str'

✅ Right

prices = ["20", "35", "15"]
numbers = []
for p in prices:
    numbers.append(int(p))
print(sum(numbers))

Data that was typed in is text. Convert it with int() before doing maths.

📌 Remember

  • A data project goes: question, collect, clean, calculate, show.
  • sum(), len(), max() and min() answer most simple data questions.
  • Average = sum / len; check for an empty list first.
  • Use the "best so far" loop to find which key has the highest value.
  • "#" * n draws a text bar; padding like {name:9} lines the bars up.
  • Clean text with strip() and lower() before you count it.

Finished the quiz and the challenge?

Questions students ask

How do I calculate an average in Python?

Divide the total by the count: sum(values) / len(values). Use round(answer, 1) to keep one decimal place.

Can I make charts in Python without matplotlib?

Yes. Repeat a character with "#" * n to draw text bars. Libraries like matplotlib draw nicer charts once you install them.

What is data cleaning?

It means fixing messy data before using it. Common steps are removing spaces, using the same case, and skipping blanks.

What are good data project ideas for students?

Track your screen time, class heights, cricket scores, daily temperature, or canteen sales. Start with one clear question.