Library › Coding AI › Teachers

Keep each student's best quiz attempt with pandas

Practice: Giving the right context. About 5 minutes.

About this exercise

Write a pandas script that reads quiz_export.csv and writes best_scores.csv with exactly two columns, email and best_pct, one row per student. Scores come in as text like 12/15, and retakes were out of 20, so turn each score into a percent (points divided by possible, times 100) before comparing. Match students by email lowercased, keep each one's highest percent rounded to 1 decimal, and don't write the index. One code block, at most 12 lines, then under 25 words outside the code.

Common mistakes when you ask AI for this

  • Not explaining the scores. The AI compares raw points, so a 15/20 beats a 14/15. Try: Add: "Turn 12/15 into a percent before comparing."
  • Not mentioning capital letters. The AI treats AJones@ and ajones@ as two students. Try: Add: "Match by email lowercased, keep the highest percent."
  • Leaving the output open. The AI keeps extra columns or writes the index, so the gradebook paste breaks. Try: Add: "Exactly email and best_pct, 1 decimal, index=False."
  • Getting a menu of options. The AI likes to offer two or three versions of the script, so you're left to pick and test them yourself. Try: Add: "Give one script only, in one code block, no alternatives."
  • Getting a tutorial. By default the AI explains every part of the code at length, which you then have to scroll past. Try: Add: "After the code, one line under 12 words. Nothing else."

What a strong prompt includes

  • Explains the score format
  • Handles capital letters
  • Says which attempt to keep
  • Sets the output
  • Asks for one answer only

Practice this now ↑

Related exercises