python class methods

Doing an exercise playing with Class for the first time.   Well my first time in python in 5 years,  but I think I remembered how it worked....  Here's an extension of an exercise where I created a method to count the lines, count the words... and print an Ascii,  cause I've found I really like making them.


class Song(object):
def __init__(self, lyrics):
self.lyrics = lyrics
#def __init__(self, ascii_list):
#self.ascii_list = ascii_list

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

def print_ascii(self):
for line in self.lyrics:
print(line)

def count_lyrics(self):
count = 0
for line in self.lyrics:
count += 1
print(count)

def count_words(self, some_list):
song_list = some_list.lyrics
count = 0
new_list = []
for line in song_list:
line = song_list[count]
#words = song_list.split(' ')
words = line.split(' ')
new_list.extend(words)
print(new_list)
for word in new_list:
count += 1
print(count)

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 tha family",
"With pockets full of shells"])

smiley = Song([".........>>>>>>.........",
"......>> >>......",
".....> O O >.....",
"......> *....* >......",
".........>>>>>>........."])

smiley.print_ascii()
#smiley.sing_me_a_song()
happy_bday.sing_me_a_song()
happy_bday.count_lyrics()
bulls_on_parade.sing_me_a_song()
bulls_on_parade.count_words(bulls_on_parade)

Comments

Popular posts from this blog

JavaScript Ascii animation with while loops and console.log

playing with trigonometry sin in pygame

playing with color in powershell python