forked from curtisgr/99bottles-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise.py
40 lines (33 loc) · 1.38 KB
/
exercise.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class Bottles(object):
def song(self) -> str:
return self.verses(99, 0)
def verses(self, start_verse: int, stop_verse: int) -> str:
start_verse, stop_verse = sorted([start_verse, stop_verse], reverse=True)
verses = range(start_verse, stop_verse - 1, -1)
return '\n\n'.join([self.verse(verse) for verse in verses])
def verse(self, verse_num: int) -> str:
return self.phrase1(verse_num) + '\n' + \
self.phrase2(verse_num-1)
def phrase1(self, bottle_num: int) -> str:
s = {1: ''}.get(bottle_num, 's')
phrase1: dict = {
0: 'No more bottles of beer on the wall, no more bottles of beer.'
}
return phrase1.get(
bottle_num,
f'{bottle_num} bottle{s} of beer on the wall, {bottle_num} bottle{s} of beer.'
)
def phrase2(self, bottle_num: int) -> str:
s = {1: ''}.get(bottle_num, 's')
phrase2: dict = {
0: 'Take it down and pass it around, no more bottles of beer on the wall.',
-1: 'Go to the store and buy some more, 99 bottles of beer on the wall.'
}
return phrase2.get(
bottle_num,
f'Take one down and pass it around, {bottle_num} bottle{s} of beer on the wall.'
)
if __name__ == '__main__':
bottles = Bottles()
print(bottles.verses(99, 98))
print(bottles.song())