HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_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 →
Live examsInternational live exams are comingTell us which exam you want first. Timed practice papers are open now.See what is coming →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Space Science and Astronomy
  • Earth and Environmental 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
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Python Programming
  2. /Python Essentials

Python Essentials

Python Programming · High School (9–10) · 8 courses, 111 worked problems, 237 practice questions

After the basics, a programmer needs more ways to store data and more ways to solve problems. This area builds them. Tuples and sets hold fixed or unique collections, and dictionaries store values under keys, like meanings under words in a glossary. Modules and libraries let you reuse code that others have written. Text processing works with words and sentences, and errors and exceptions help a program deal with bad input. Searching and sorting, and recursion, are classic ways to solve problems. Essentials projects join these skills in longer programs.

With practice you will be able to

  • Store and look up data with dictionaries, tuples and sets
  • Handle bad input with try and except
  • Write a search, a sort and a recursive function

On the syllabus of

  • CBSE / State Class 12
  • Python Certification
  • AP
  • A-Level
  • IGCSE

Parts of this topic

  • Dictionaries
  • Tuples and Sets
  • Errors and Exceptions
  • Modules and Libraries
  • Searching and Sorting
  • Recursion
  • Text Processing
  • Essentials Projects

Lessons

  • Three Essentials ProjectsCan you crack a Caesar code without knowing the shift?High School (9–10)
  • Working with TextWhy are The, the and THE different words to Python? How does a secret code work?High School (9–10)
  • A Function That Calls ItselfWhy is the simple Fibonacci function so slow? How do you search folders inside folders?High School (9–10)
  • Find It and Put It in OrderHow can ten looks find a word in a 1000-page dictionary? How do ties get a rank?High School (9–10)
  • Import a Toolbox: ModulesHow many 45-seat buses do 130 students need? Is your die really fair?High School (9–10)
  • When Things Go Wrong: try and exceptWhat should a program do when you type a letter for your age? Which line names the error?High School (9–10)

All 8 courses on Python Essentials →

Practice questions

Choose an answer, then check it. Each one shows a full explanation.

A recursive function calls itself twice for each number that is two or more, and adds one each time. def calls(n): if n < 2: return 1 return calls(n - 1) + calls(n - 2) + 1 print(calls(4)) What does the program print?

A function adds results to a list that it is given. Part way through, one of the results fails, and the caller handles the error. def fill(target, values): for v in values: target.append(10 // v) return len(target) data = [] try: n = fill(data, [5, 2, 0, 1]) except ZeroDivisionError: n = -1 print(n, data) What does the program print?

Three small functions are defined. Two of them call themselves, and one uses a loop. def a(n): if n == 0: return 0 return n + a(n - 1) def b(n): total = 0 for k in range(n): total += k return total def d(n): if n <= 1: return n return n * d(n - 1) Which of these expressions are True? Choose every correct option.

One or more options are correct. Tick all the correct ones: a wrong option costs marks, and a part-right answer earns part of the marks.

One function calls another. The inner one reads past the end of a list, and neither function has a try. def inner(items): print("in", end=" ") return items[3] def outer(items): v = inner(items) print("out", end=" ") return v try: print(outer([1, 2, 3])) except IndexError: print("caught") What does the program print?

A function tries to add one to the first item of a tuple. If that fails, it builds a new tuple instead. def bump(t): try: t[0] += 1 except TypeError: t = (t[0] + 1,) + t[1:] return t p = (1, 2) q = bump(p) print(p, q, p is q) What does the program print?

A function adds up points for the letters of a word. Letters that are not in the dictionary get a default value. def score(word, values): total = 0 for ch in word: total += values.get(ch, 1) return total pts = {"a": 2, "z": 10} print(score("pizza", pts), len(pts)) What does the program print?

A function asks a tuple three questions and returns the three answers together. def info(t): return len(t), t.count(2), t.index(2) print(info((2, 4, 2, 6))) What does the program print?

A function reads from a box, which may be a dictionary, a list or a tuple. Its first except names the family LookupError, and its second names Exception. def fetch(box, k): try: return box[k] except LookupError: return "missing" except Exception: return "bad" print(fetch({"x": 1}, "y"), fetch([1, 2], -3), fetch((5, 6), "0")) What does the program print?

A recursive function works on a shorter and shorter slice of a list. def walk(v): if len(v) == 1: return v return walk(v[1:]) + [v[0]] print(walk([1, 2, 3, 4])) What does the program print?

A program removes names from a list. One of the names is not in the list. names = ["Ali", "Bea", "Cal"] for target in ["Bea", "Dev"]: try: names.remove(target) print(target, "out", end="; ") except ValueError: print(target, "not found", end="; ") print(len(names)) What does the program print?

All 237 practice questions on Python Essentials →

Worked problems

Each one has a hint, the key idea and a full worked solution.

  • Write three small functions square(n), double(n) and negate(n), and a dictionary operations that…Medium
  • Choose a project: a program that keeps the scores of a quiz game and shows who is winning…Easy
  • Write a function above_mean(marks) for a dictionary of name and mark…Medium
  • A line has the form name:mark, such as Asha:72…Medium
  • What kind of text?Easy
  • Write a function initials(name) that gives the capital initials of a name, so that "asha kumari…Easy
  • What do show_up(3) and show_down(3) print? Say it before you run it.Easy
  • For sum_to(3), where sum_to(n) is 0 for n == 0 and n + sum_to(n - 1) otherwise, write the calls…Medium
  • For each job, say whether a loop or recursion is the better choice, and why…Easy
  • Write a recursive function all_positive(items) that gives True if every item of the list is more…Medium
  • For each function, say whether a memory (a dictionary of answers) would help, and why…Easy
  • Without running anything, say how many subsets there are for lists of 5, 10 and 20 items…Medium

All 111 worked problems on Python Essentials →

Python labs

  • Contact book tools
  • Guess the shift
  • Marks report tools
  • Run the commands
  • Project: the command menu
  • Plan and test: a unit converter