6.100L | Fall 2022 | Undergraduate

Introduction to CS and Programming using Python

Lecture 18: More Python Class Methods

Topics: Object Oriented Programming: dunder methods, examples

Lecture Notes

Lecture 18: More Python Class Methods

Lecture 18 Code

Readings

Ch 10.1

Finger Exercise Lecture 18

Write the class according to the specifications below:

class Circle():
    def __init__(self, radius):
        """ Initializes self with radius """
        # your code here

    def get_radius(self):
        """ Returns the radius of self """
        # your code here

    def __add__(self, c):
        """ c is a Circle object 
        Returns a new Circle object whose radius is 
        the sum of self and c's radius """
        # your code here

    def __str__(self):
        """ A Circle's string representation is the radius """
        # your code here

6.100L Finger Exercises Lecture 18 Solutions

Course Info

Instructor
As Taught In
Fall 2022
Learning Resource Types
Lecture Videos
Lecture Notes
Problem Sets
Programming Assignments with Examples
Readings
Recitation Notes