In the previous lesson, we learned how to make our programs “remember” things. By reading and writing files, students mastered how to save data into CSV and JSON formats. CSV files work like tables, storing rows of structured information, while JSON can handle more complex data, combining lists and dictionaries. Through projects like the “Shopping List” and “Grade Repository,” students practiced saving data from memory to files and reading it back for analysis, giving their programs a real sense of memory — the ability to retain information even after the program closes. Now students try to finish the following practice to review what we learned last unit:
csv.DictWriter to save rows with fields name,age,score to class.csv, then read them back with csv.DictReader and print names of students with score ≥ 90.Data example:
data = [
{"name":"Alice","age":12,"score":91},
{"name":"Bob","age":13,"score":85},
{"name":"Cathy","age":12,"score":95},
]
Output example:
Top: Alice, Cathy
Answer example:
import csv
data = [
{"name":"Alice","age":12,"score":91},
{"name":"Bob","age":13,"score":85},
{"name":"Cathy","age":12,"score":95},
]
with open("class.csv","w",newline="",encoding="utf-8") as f:
w = csv.DictWriter(f, fieldnames=["name","age","score"])
w.writeheader()
w.writerows(data)
with open("class.csv","r",newline="",encoding="utf-8") as f:
r = csv.DictReader(f)
top = [row["name"] for row in r if int(row["score"])>=90]
print("Top:", ", ".join(top))
Today, we’ll move from data storage to data visualization, from letting programs remember to letting them create. If the last unit was about teaching the computer how to record, this one will be about teaching it how to draw. Python comes with a fun built-in drawing library called turtle, which acts like a programmable pen. With simple commands, we can make it move forward, turn, lift the pen, or change colors to draw lines and shapes on the screen.
This unit will begin with drawing straight lines, then move to squares and stars, and finally lead students into a creative mini project — My Drawing Board. Through this process, they will combine logic and imagination, discovering how programming can become both an analytical and artistic tool.