HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClassesGroups

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Blog

Account

  • Dashboard
  • My Content
  • Profile
  • Log in
© 2026 senLearn. All rights reserved.HelpAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Python Labs
  2. /Terms and middle terms
MathematicsMediumHigh School (11–12)Algebra › Binomial Theorem

Terms and middle terms

You will write three small functions for binomial expansions: the general term, the value of a whole expansion, and the middle term numbers. The checker tests them on many cases.

The idea. The (r+1)(r + 1)(r+1)th term of (a+b)n(a + b)^n(a+b)n is nCr an−rbr{}^nC_r\,a^{n-r}b^rnCr​an−rbr. Adding all the terms from r=0r = 0r=0 to r=nr = nr=n gives (a+b)n(a + b)^n(a+b)n. The middle term numbers are n2+1\dfrac{n}{2} + 12n​+1 for even nnn, and n+12\dfrac{n + 1}{2}2n+1​ and n+32\dfrac{n + 3}{2}2n+3​ for odd nnn.

Your tasks.

  1. Finish general_term(n, r, a, b). Return the value of the (r+1)(r + 1)(r+1)th term.
  2. Finish expansion_value(n, a, b). Add the general terms for r from 0 to n.
  3. Finish middle_terms(n). Return a list with the middle term number or numbers, in order.

Run it first, just as it is. The checker at the end prints FAIL for each task. Then do the tasks one at a time, and run the program again after each one. A Hint appears under every check that still fails.

When every line says PASS, print middle_terms(20) and middle_terms(21). Do they agree with the lesson?

StemPy LabContributed by StemPy Lab
python
Loading Python runtime…

A worked solution

Have you tried it?

Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.

Log in to save
← All Labs
More onAlgebra › Binomial Theorem

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. Middle terms and the term free of xPascal's Triangle and the Binomial Expansion

More labs on this topic

  1. Remainders and short sumsMedium
  2. Rows and their sums in codeEasy
  3. Pascal's triangle two waysEasy
All labs on this topic →

Want to go further?

With Standard, you also open 11 more problems, 2 Python labs and 1 extra course. Everything you have used here stays free, always.

Part of our upcoming paid plans.