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 Going Further

Python Going Further

Python Programming · High School (11–12) · 6 courses, 59 worked problems, 195 practice questions

Programs grow larger, and a programmer needs ways to keep them organised. This area covers the tools that working programmers use every day. Classes and objects bundle data with the functions that act on it. Inheritance and special methods let new classes build on old ones and work with +, len() and print(). Files and data formats such as CSV and JSON let a program save and read real data. Comprehensions and generators give short, memory-friendly loops. Testing and debugging catch mistakes, and data structures such as stacks, queues and trees organise data.

With practice you will be able to

  • Write a class with attributes and methods, and make objects
  • Read and write CSV and JSON files from a Python program
  • Test a function with assert and fix a bug from its traceback

On the syllabus of

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

Parts of this topic

  • Classes and Objects
  • Inheritance and Special Methods
  • Files and Data Formats
  • Comprehensions, Iterators and Generators
  • Data Structures
  • Testing and Debugging

Lessons

  • Testing and DebuggingWhere do most bugs hide? How do you find a bug without guessing?High School (11–12)
  • Data StructuresHow does undo remember your steps? How does a route finder find the fewest stops?High School (11–12)
  • Comprehensions, Iterators and GeneratorsWhat does a for loop really do? Can a generator give numbers for ever?High School (11–12)
  • Files and Data FormatsCan opening a file wipe it out? How does a program remember between runs?High School (11–12)
  • Inheritance and Special MethodsIs a car a kind of engine, or does it have one? How does print show your own object?

Practice questions

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

A program writes three lines to a file, then adds up the lines that are numbers. A line that is not a number counts as 100. with open("n.txt", "w") as f: f.write("3\nx\n5\n") total = 0 with open("n.txt") as f: for row in f: try: total += int(row) except ValueError: total += 100 print(total, f.closed) What does the program print?

A list comprehension uses a conditional expression, and filter is called with None. vals = [x if x % 3 else 0 for x in range(1, 7)] print(vals, list(filter(None, vals))) What does the program print?

Three classes form a chain. Each one sets its own rate, and Premium extends the cost method with super(). class Base: rate = 2 def cost(self, n): return n * self.rate class Premium(Base): rate = 3 def cost(self, n): return super().cost(n) + 1 class Gold(Premium): rate = 5 print(Base().cost(2), Premium().cost(2), Gold().cost(2)) What does the program print?

Worked problems

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

  • A function is_even(n) should say whether a whole number is even…Easy
  • A function ticket_price(age) gives 0 for ages under 5, 50 for ages 5 to 12, 100 for ages 13 to 59…Easy
  • A student writes these names for test methods in a class that tests a Stack class…Easy
  • A test run prints this. How many tests passed? …Medium
  • A function longest_word(text) gives the longest word of a text, and when two words are equally…Easy
  • Fix second_largest so that it gives the second largest different value, and None when there is none…

Python labs

  • Fill the table
  • Catch the bugs
  • Test a function with a table
  • Find a failing input
  • Fix the running total
  • Fix the second largest
High School (11–12)
  • Classes and ObjectsIs a number in Python an object too? How can a bank account refuse a bad withdrawal?High School (11–12)
  • A film object should report its kind through a method title. But the constructor stores the film's name in capitals under that same name. class Film: def __init__(self, name): self.title = name.upper() def title(self): return "film" movie = Film("up") print(movie.title()) What happens when the program runs?

    A class Point takes one required parameter and one with a default value. Each option below is run on its own, after the class. class Point: def __init__(self, x, y=0): self.x = x self.y = y Which lines run with no error? 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.

    A thermometer reading should turn into text through its own special method. The method gives back the stored number as it is. class Reading: def __init__(self, degrees): self.degrees = degrees def __str__(self): return self.degrees r = Reading(7) print("Now: " + str(r)) What happens when the program runs?

    A class defines __add__ but not __iadd__. A second name points to the first object before += is used. class Vec: def __init__(self, x, y): self.x, self.y = x, y def __add__(self, o): return Vec(self.x + o.x, self.y + o.y) def __str__(self): return f"({self.x}, {self.y})" a = Vec(1, 2) b = a a += Vec(3, 4) print(a, b, a is b) What does the program print?

    A class uses an empty list as the default value of a parameter of __init__. class Team: def __init__(self, members=[]): self.members = members def join(self, name): self.members.append(name) x, y, z = Team(), Team(), Team(["Kai"]) x.join("Ana") z.join("Ben") print(y.members, z.members, x.members is y.members) What does the program print?

    The class Plane has two base classes, Wing and Tail. Both set the class variable mark, and only Tail has the method label. class Wing: mark = "w" class Tail: mark = "t" def label(self): return self.mark class Plane(Wing, Tail): pass print(Plane().label(), Plane.mark) What does the program print?

    Two cars are built around the same engine object. class Engine: def __init__(self): self.rpm = 0 class Car: def __init__(self, engine): self.engine = engine e = Engine() a, b = Car(e), Car(e) a.engine.rpm = 900 b.engine = Engine() print(a.engine.rpm, b.engine.rpm, e.rpm, a.engine is e) What does the program print?

    All 195 practice questions on Python Going Further →

    Medium
  • Write three properties that must be true for any list x and the function reversed_list(x) that…Medium
  • A pipeline has three stages. For the input "Hello, World", it should give ["hello", "world"], but…Medium
  • This function should give the average of a list, but gives a wrong answer for [2, 4, 6] (it gives…Easy
  • Think of a bug that you met while working through this book, or write one on purpose…Easy
  • Use a stack to write a function reverse_words(sentence) that reverses the order of the words of a…Easy
  • Customers arrive and are served one at a time, each needing some minutes: Asha 4, Ravi 2, Meera 6…Medium
  • All 59 worked problems on Python Going Further →