Attach scores.csv (banner → Add files). Each block is a complete cell. You will parse rows, compute a band, write a report, and optionally plot.
Goal
Produce gradebook.csv with name, score, and band. Print the class average.
1. Read the CSV
import os
print("uploads:", os.listdir("/uploads"))
print(open("scores.csv").read())2. Parse into dicts
rows = []
with open("scores.csv") as f:
header = f.readline()
for line in f:
line = line.strip()
if not line:
continue
name, raw = line.split(",")
rows.append({"name": name, "score": int(raw)})
print(rows)
print("average:", round(sum(r["score"] for r in rows) / len(rows), 1))3. Band each student
def band(score):
if score >= 90:
return "A"
if score >= 80:
return "B"
if score >= 70:
return "C"
return "D"
rows = []
with open("scores.csv") as f:
next(f)
for line in f:
line = line.strip()
if not line:
continue
name, raw = line.split(",")
score = int(raw)
rows.append({"name": name, "score": score, "band": band(score)})
for row in sorted(rows, key=lambda r: r["score"], reverse=True):
print(f"{row['name']:8} {row['score']:3} {row['band']}")4. Write the report
def band(score):
if score >= 90:
return "A"
if score >= 80:
return "B"
if score >= 70:
return "C"
return "D"
rows = []
with open("scores.csv") as f:
next(f)
for line in f:
line = line.strip()
if not line:
continue
name, raw = line.split(",")
score = int(raw)
rows.append({"name": name, "score": score, "band": band(score)})
with open("gradebook.csv", "w") as f:
f.write("name,score,band\n")
for row in rows:
f.write(f"{row['name']},{row['score']},{row['band']}\n")
print(open("gradebook.csv").read())Download gradebook.csv from the chip.
5. Optional plot
import matplotlib.pyplot as plt
def band(score):
if score >= 90:
return "A"
if score >= 80:
return "B"
if score >= 70:
return "C"
return "D"
rows = []
with open("scores.csv") as f:
next(f)
for line in f:
line = line.strip()
if not line:
continue
name, raw = line.split(",")
rows.append({"name": name, "score": int(raw), "band": band(int(raw))})
names = [r["name"] for r in rows]
scores = [r["score"] for r in rows]
plt.figure()
plt.bar(names, scores)
plt.axhline(90, linestyle="--")
plt.title("Scores")
plt.show()Next
You now have Python itself. For tables, groupby, and CSV pipelines, continue with Learn pandas.
You should see
If scores.csv is missing, attach it and run again. FileNotFoundError means the notebook cannot see the file in /uploads.