calthoff / self_taught

This repository contains the exercises for "The Self-Taught Programmer: The Definitive Guide to Programming Professionally."
http://theselftaughtprogrammer.io
272 stars 226 forks source link

Chapter 12 Rectangle class #37

Open Jaro266613 opened 3 years ago

Jaro266613 commented 3 years ago

class Rectangle(): def _init(self, w, l): self.width = w self.len = l

def area(self):
    return self.width * self.len

def change_size(self, w, l):
    self.width = w
    self.len = l

rectangle = Rectangle(10, 20) print(rectangle.area()) rectangle.change_size(20, 40) print(rectangle.area())


TypeError Traceback (most recent call last)

in ----> 1 rectangle = Rectangle(10, 20) 2 print(rectangle.area()) 3 rectangle.change_size(20, 40) 4 print(rectangle.area()) TypeError: Rectangle() takes no arguments
Pranshu1902 commented 2 years ago

you missed the "" in the initialization of Rectangle class. It should be "init" but it is written as "init"