What it shows
The program reads present and total days from a CSV, works out the percentage and writes a second file listing those below 75 percent. It shows reading, calculating and writing data in one pipeline.
The science
Percentage is part divided by whole times 100. A script can apply the same formula to thousands of rows without mistakes. Reading with csv.DictReader gives each row by column name, and csv.writer writes the results to a new file that a spreadsheet can open. Many schools and colleges use 75 percent as a minimum attendance level.
Materials
Cost: free. Many items come from home or from waste; spare parts such as LEDs, motors and wire are in the store.
- A computer, laptop or phone with a browser (free)
- Python 3 with IDLE, or the free Thonny editor, or an online Python runner (all free)
- A CSV file attendance.csv with columns name,present,total for 15 made-up students
- A notebook and a pencil
Safety
This project uses safe, everyday materials. Still, read the rules below with a parent before you start.
Never use mains electricity: power models with cells, batteries or a low-voltage adapter. Sharp and hot tools, flames and lab chemicals need an adult or your teacher beside you. Keep magnets, button cells and small parts away from young children, and wash your hands after making.
All the safety rulesStep by step
8 steps. Do them in order, and test each part before you go on to the next. Write what you notice in a notebook as you go.
Make attendance.csv in Notepad with the first line name,present,total and 15 made-up rows such as Ravi,150,200.
Create attend.py and write import csv.
Open the input with with open("attendance.csv") as f: and reader = csv.DictReader(f), then rows = list(reader).
Make an empty list low = [] and loop for r in rows:.
Inside the loop work out pct = int(r["present"]) * 100 / int(r["total"]).
Add if pct < 75: low.append([r["name"], round(pct, 1)]).
Write the results with with open("low.csv", "w", newline="") as out: and w = csv.writer(out), w.writerow(["name", "percent"]) and w.writerows(low).
Print how many students are below 75 percent, open low.csv in a spreadsheet and check three values by hand.
What you should see
A new file low.csv lists every student under 75 percent with the correct percentage, and the program prints how many there are.
Viva questions
A teacher or a judge will ask how it works. Try to answer each question before you open it, then compare.
1What is the formula for percentage?
Part divided by whole, multiplied by 100.
2Why use newline="" when writing CSV?
To avoid blank lines between rows on Windows.
3What does writerows do?
It writes a whole list of rows at once.
4How can you check the program?
Calculate a few students by hand and compare.
Take it further
Also compute how many more days each student must attend to reach 75 percent if the term has 200 days.
Change one thing, measure what happens, and add a table or chart of your readings: that is what turns a model into your own investigation.
Free ebooks for this project
Computer & office
Excel Formulas Workbook
Sixty formulas and functions, each with a worked example from school, shop or office
