Ex40 "TypeError - Song() takes no arguments"

Hello All,
I am looking at Exercise 40, and running into an error. As far as I can see, I have typed it correctly, but as with all of these exercises, perhaps I’ve just missed it several times.

Here’s the error message I get in Powershell:

PS C:\Users\Dave\pythonthw> python ex40.py Traceback (most recent call last):
File “ex40.py”, line 12, in
“So I will stop right there”])
TypeError: Song() takes no arguments
PS C:\Users\Dave\pythonthw>

Code below:

class Song(object):

	def _init_(self, lyrics):
		self.lyrics = lyrics

	def sing_me_a_song(self):
		for line in self.lyrics:

happy_bday = Song(["Happy birthday to you",
                   "I don't want to get sued",
                   "So I will stop right there"])

bulls_on_parade = Song(["They rally around tha family",
						"With pockets full of shells"])



Thanks in advance, and apologies if I am missing something really dumb,


Hello @Hammer_53

You missed an extra underscore (_) around init.
There should be two on each side.
You have only one.

Those errors are hard to spot.


Thanks Ulf,
You’re right, never noticed that one! Thanks very much.



The double underscore and indentation seem to be the biggest things that confuse beginners in Python. It’s just too hard to see _ vs __ as an error, as well as indentation. Keep that in mind when you have some random errors @Hammer_53, and double check that things are lined up on the same columns or have the right number of __ (it’s always two).

1 Like

Thanks, Zed. Yes, it seems an easy one to miss. Indentation often catches me out too!

class Song(object):

def __int__(self,lyrics):
def sing_me_a_song(self):
    for line in self.lyrics:

happy_bday=Song([“Happy birthday to you”,
“I don’t want to get sued”,
“So I’ll stop right there”])

bulls_on_parade=Song([“They rally around the family”,
“With pockets full of shells”])


My code is here, I can’t see any mistakes. Anyone can help?

__int__ should be __init__.

Thank you so much!
I didn’t notice that