Skip to content
6 min read

How to Teach Programming with Python in Middle School (Grades 6–9): Lesson Ideas, Activities & Worksheets

A practical guide to teaching Python in Grades 6–9: a first-lesson sequence, example code, differentiation, common bugs and misconceptions, and assessment ideas.

Why teach Python in Grades 6–9?

Quick answer: Teach Python to middle schoolers by starting with tiny, immediately runnable programs — print(), variables and input() — then adding conditionals and loops through short, high-interest tasks. Python's readable syntax lets Grades 6–9 students write real, working code in their very first lesson, which builds confidence fast.

Python is an ideal first text-based language: minimal punctuation, English-like keywords, and instant feedback. After students have built computational-thinking foundations, Python lets them turn plans into programs that actually run. Our Programming with Python unit for Grades 6–9 provides sequenced worksheets, projects and slides so you can teach confidently even if you are new to coding.

What should the first few lessons cover?

A dependable sequence:

  1. Output: print("Hello, world!") — change the message, run again.
  2. Variables and input: capture and reuse data.
  3. Conditionals: make the program decide.
  4. Loops: repeat without copy-paste.

A complete first-week program students can build and personalize:

name = input("What is your name? ")
age = int(input("How old are you? "))
if age >= 13:
    print(name + ", you are a teenager!")
else:
    print(name + ", you will be a teenager soon.")
for i in range(3):
    print("Welcome to Python!")

Every line here maps to a computational-thinking idea students may have met unplugged first. If they haven't, our Algorithms and Computational Thinking unit for Grades 6–9 is a strong prerequisite that teaches sequencing, decisions and loops away from the keyboard.

Which beginner projects keep students motivated?

  • Mad Libs: collect words with input() and drop them into a story — pure string practice with a funny payoff.
  • Number guessing game: combines random, a loop and conditionals; a natural bridge from the unplugged binary-search game.
  • Quiz app: track a score across several questions — great for reinforcing variables and if.
  • Rock, paper, scissors: introduces comparing user and computer choices.

Because these programs handle text and numbers, they are a good moment to discuss how computers store data — our Data and Encoding: Binary & Digital Images unit explains what is happening beneath the variables.

How do I differentiate across Grades 6–9?

Use the same project with tiered goals:

  • Grade 6: modify a working program (change messages, values, loop counts). Success = it runs without errors.
  • Grade 7–8: write programs from a spec that combine input, a conditional and a loop.
  • Grade 9: add functions, validate input, and handle edge cases such as non-numeric answers.

Provide starter code and a “parson's puzzle” (correct lines in scrambled order) for students who need scaffolding, and open-ended challenge extensions for those ready to stretch.

Common bugs, misconceptions and assessment

Expect these recurring issues: forgetting the colon after if/for; inconsistent indentation; mixing up = (assignment) and == (comparison); and treating input() as a number when it returns text (hence int()). Normalize errors — read the traceback together and treat debugging as the real skill.

For assessment, combine a short code-reading quiz (predict the output) with a build task graded on a rubric for correctness, use of the required structures, and readability (sensible names, comments). A quick exit ticket asking students to find and fix one bug is fast and revealing.

What starter code should students begin from?

Two short programs cover the first week of hands-on work. Mad Libs uses nothing but input() and string joining, so every student ends the lesson with something that runs:

noun = input("Enter a noun: ")
verb = input("Enter a verb: ")
print("The " + noun + " likes to " + verb + " all day!")

The number-guessing game is the natural next step. It adds a loop, a conditional and randomness in about a dozen lines, and it is the sequel to the unplugged binary-search game — students who guessed by halving can now code that strategy:

import random
secret = random.randint(1, 20)
guess = 0
while guess != secret:
    guess = int(input("Guess (1-20): "))
    if guess < secret:
        print("Too low")
    elif guess > secret:
        print("Too high")
print("You got it!")

Hand either program out complete to Grade 6 and let students change the range, the wording and the number of turns. Grade 7 and 8 can type it from a description of what it should do instead. Five minutes of “bug of the day” at the start of a lesson — a short broken program on the board that the class fixes before opening their own work — makes error messages ordinary rather than a sign that something has gone wrong.

Plan one 45-minute lesson for each of these two starter programs, including time to run them and personalize the wording. The larger builds — the quiz app and rock, paper, scissors — need two lessons each once testing and fixing are counted, so a four-project arc fills roughly six lessons.

What can students do when they finish early?

Keep two extensions on hand so the fast finishers stay in Python rather than drifting:

  • Password strength checker: use string length and character checks to rate a password as weak, fair or strong.
  • Times-table generator: nested loops that print a full multiplication grid, which for most students is the first time they see a loop inside a loop.

Both double as the personal twist every project should require: a new question, a different message, one extra feature. Ask students to add a feature of their own choosing and then explain aloud the line that makes it work. That explanation shows understanding faster than a finished file does, and it makes copied code obvious.

Both also work as an end-of-unit choice task: students pick one, build it, and hand in a two-sentence note saying which structure — loop, conditional or string operation — does the real work in their program.

FAQ

Is Python a good first programming language for middle school?

Yes. Python's readable, English-like syntax and instant feedback let Grades 6–9 students write working programs in their first lesson, which builds confidence and reduces frustration compared with more punctuation-heavy languages.

What tools do I need to teach Python?

A free browser-based editor is enough to start — no installation required. Students only need a computer and internet access, so the technical barrier for teachers is low.

Do students need to learn algorithms before Python?

It helps. Students who have practiced sequencing, decisions and loops unplugged pick up Python faster because they are only learning syntax, not the underlying logic, at the same time.

Start teaching Python today

Skip the prep work: the Programming with Python unit for Grades 6–9 gives you sequenced lessons, worksheets, projects and slides ready to run — download it and code with your class this week.

Want a ready-to-teach curriculum?Complete, ready-to-use teaching curricula for Middle & High School — structured units, assessments, and more.

All Middle School Curricula →

Teaching High School classes?Complete, ready-to-use teaching curricula for Middle & High School — structured units, assessments, and more.

All High School Curricula →
✏
About the author
The TeachLessons Team
Curriculum Designers & Educators

The TeachLessons team is made up of experienced classroom teachers and curriculum specialists from the US, UK, and Australia. We build complete, ready-to-use teaching resources because we know what it takes to walk into a classroom prepared. Every resource is grounded in real teaching practice, standards-aligned, and designed to make lessons better from day one.

Curriculum DesignK–12 EducationStandards AlignmentClassroom PracticeLearning Design
Common Questions

FAQ about TeachLessons resources

TeachLessons provides K–12 resources. Complete Curriculum packages currently focus on Middle School and High School, while the blog also supports Elementary teachers.

Each package includes lesson plans, worksheets, assessments, rubrics, and teacher notes as print-ready PDFs.

Yes. Resources align with relevant US standards such as Common Core, NGSS, and the NCSS C3 Framework.

Yes. Complete Curriculum packages currently focus on Middle and High School, while our blog supports Elementary teachers with lesson ideas, classroom strategies, cross-curricular activities, free downloads, and Teach-Life-Balance support.

  • Blog articles with practical lesson ideas
  • Free resources via the newsletter
  • Teach-Life-Balance for teachers at every level

The Teach-Life-Balance course is a time-saving programme for Elementary, Middle, and High School teachers. It helps with lesson planning, marking, admin, routines, boundaries, and workload management.

It includes a teacher planner, guides, templates, and practical strategies. Available at teachlessons.us/products/teach-life-balance.

After purchase you receive an instant email with your download link. Files are also stored in your customer account under Orders. Materials are print-ready PDFs for class, projection, or digital use.

Resources are licensed for personal classroom use. You may use them in your own classes. Sharing digital files or uploading them online is not permitted under a single-user licence. School licences are available on request.

Yes. Although primarily aligned to US standards, the lesson structures and subject content work well for UK and Australian classrooms with minor adaptation. The store supports GBP and AUD currency.

Keep reading

You might also like

Discussion

Comments

No comments yet — be the first to share your thoughts!

Leave a comment

Comments are reviewed before being published.

Also join the newsletter?
Get weekly lesson ideas and a free resource pack.

Please fill in all required fields and confirm your consent.

* Required. Email will not be published. Privacy Policy.

✅

Thanks for your comment!

Your comment is being reviewed and will appear here shortly.

Free resource inside

Lesson ideas straight to your inbox.

Join thousands of teachers. Sign up and get a free starter resource pack plus weekly lesson ideas — no fluff, just things that work in real classrooms.

No spam, ever
Unsubscribe any time
GDPR & COPPA compliant

Please fill in all required fields and confirm your consent.

💌

Almost there, !

Check your inbox and click the confirmation link to receive your free pack.

1
Check your inboxA confirmation email from teachlessons.us is on its way.
2
Click the linkConfirm your email to activate your subscription.
3
Receive your free packYour starter resource pack arrives right after confirmation.
No email yet?Check your spam or junk folder and mark us as “Not Spam”. Sender: teachlessons.us