From a1907e4a89407b69ace8eb39a6e76458b721f68e Mon Sep 17 00:00:00 2001 From: "Bradley M. Small" <bradley_small@hotmail.com> Date: Sat, 21 Sep 2019 19:56:58 -0400 Subject: [PATCH] cleaning up with pylint3 and pycodestyle --- beer.py | 66 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/beer.py b/beer.py index 1668695..3bcabde 100755 --- a/beer.py +++ b/beer.py @@ -1,58 +1,72 @@ -#!/usr/bin/python +#!/usr/bin/python +""" +Program to generate the song Ninety-nine Bottles of Beer +""" -def num2name(num) : +def num2name(num): """ function that takes a number and returns the text name this will only work for 0 - 99 - it provides no error handling and assumes that a valid number will be passed in + it provides no error handling and assumes that a valid number will be + passed in """ - tens = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"] - ones = ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"] - teens = ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"] + tens = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", + "eighty", "ninety"] + ones = ["", "one", "two", "three", "four", "five", "six", "seven", + "eight", "nine"] + teens = ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", + "sixteen", "seventeen", "eighteen", "nineteen"] - ten = num//10 - one = num%10 + ten = num // 10 + one = num % 10 # 99-20 - if ten > 1 : + if ten > 1: if one == 0: name = tens[ten] else: name = tens[ten] + "-" + ones[one] # 19-10 - if ten == 1 : + if ten == 1: name = teens[one] # 9-0 - if ten == 0 : + if ten == 0: if one == 0: name = "No" - else : + else: name = ones[one] return name -def count2s(num) : - if num == 1 : + +def count2s(num): + """ + Returns an "s" for any number other than 1 + """ + if num == 1: return "" - else: - return "s" -def main() : + return "s" + + +def main(): """ - Main driver loop. Maintains the base text and substitutes the numbers to make it work. - Checks for count to compensate for bottle vs bottles, in 2 places. - Calculate the plurality and have one output string set + Main driver loop. Maintains the base text and substitutes the numbers + to make it work. Checks for count to compensate for bottle vs bottles, + in 2 places. Calculate the plurality and have one output string set """ - for count in range(99, 0, -1) : - values = (num2name(count).capitalize(), count2s(count), num2name(count).capitalize(), count2s(count), num2name(count-1).capitalize(), count2s(count-1) ) - print "%s bottle%s of beer on the wall.\n" \ - "%s bottle%s of beer. Take one down,\n" \ - "pass it around... %s bottle%s of beer.\n" % values + for count in range(99, 0, -1): + values = (num2name(count).capitalize(), count2s(count), + num2name(count).capitalize(), count2s(count), + num2name(count-1).capitalize(), count2s(count-1)) + print("%s bottle%s of beer on the wall.\n" + "%s bottle%s of beer. Take one down,\n" + "pass it around... %s bottle%s of beer.\n" % values) -if __name__ == "__main__" : +if __name__ == "__main__": main() -- GitLab