Help
Contact
For teachers and institutes
Search courses, problems, tests…
A
A
>_
StemPy Lab
Courses ▾
Problems ▾
Practice ▾
Mock Tests
Classes
Groups
Community ▾
A
A
Problems
/
Python Going Further
/
Classes and Objects
Classes and Objects
Python Programming
+ Upload a Problem
More in Python Going Further
Classes and Objects
Inheritance and Special Methods
Files and Data Formats
Comprehensions, Iterators and Generators
Data Structures
Testing and Debugging
All Levels
High School (9–10)
High School (11–12)
Undergraduate
General
All
Easy
Medium
Sort
Mixed
Newest first
Oldest first
A to Z
16 problems
Type:
Any
Conceptual
Python-Coded
1.
For each pair, say whether you would use inheritance (is a) or composition (has a), and why.
High School (11–12), High School (9–10), Undergraduate, General · Inheritance and Special Methods, Classes and Objects
StemPy Lab
Easy
2.
A class Note has an attribute rupees. Write __lt__ and __str__ so that sorted puts a list of notes…
High School (11–12), High School (9–10), Undergraduate, General · Inheritance and Special Methods, Classes and Objects
StemPy Lab
Medium
3.
For each line of code, name the special method that Python calls.
High School (11–12), High School (9–10), Undergraduate, General · Inheritance and Special Methods, Classes and Objects
StemPy Lab
Easy
4.
The loop below works for any animal. Add a class Bird that says Tweet, and a class Parrot built on…
High School (11–12), High School (9–10), Undergraduate, General · Inheritance and Special Methods, Classes and Objects
StemPy Lab
Medium
5.
Who says what?
High School (11–12), High School (9–10), Undergraduate, General · Inheritance and Special Methods, Classes and Objects
StemPy Lab
Easy
6.
A Dog object has no name. Find the reason and fix the class.
High School (11–12), High School (9–10), Undergraduate, General · Inheritance and Special Methods, Classes and Objects
StemPy Lab
Medium
7.
Given these classes, say what each line shows.
High School (11–12), High School (9–10), Undergraduate, General · Inheritance and Special Methods, Classes and Objects
StemPy Lab
Easy
8.
A class Dog has the attributes name and age.
High School (11–12), High School (9–10), Undergraduate, General · Classes and Objects
StemPy Lab
Medium
9.
A class Basket has def __init__(self, items=[]) and self.items = items.
High School (11–12), High School (9–10), Undergraduate, General · Classes and Objects
StemPy Lab
Medium
10.
Class or object attribute?
High School (11–12), High School (9–10), Undergraduate, General · Classes and Objects
StemPy Lab
Medium
11.
Using the BankAccount class of the lesson, add a method transfer(other, amount) that moves money…
High School (11–12), High School (9–10), Undergraduate, General · Classes and Objects
StemPy Lab
Medium
12.
What does self hold?
High School (11–12), High School (9–10), Undergraduate, General · Classes and Objects
StemPy Lab
Medium
13.
Write a class Point with the attributes x and y, and a method distance_to(other) that gives the…
High School (11–12), High School (9–10), Undergraduate, General · Classes and Objects
StemPy Lab
Medium
14.
This class has two mistakes. Find them, say what error Python gives, and fix them.
High School (11–12), High School (9–10), Undergraduate, General · Classes and Objects
StemPy Lab
Easy
15.
A student is a name and a list of marks.
High School (11–12), High School (9–10), Undergraduate, General · Classes and Objects
StemPy Lab
Easy
16.
For each name in the lines below, say whether it is a class, an object, an attribute or a method.
High School (11–12), High School (9–10), Undergraduate, General · Classes and Objects
StemPy Lab
Easy