From 53accf037d8575436ff2b02c7517d70a5e4efc8f Mon Sep 17 00:00:00 2001 From: sunguangning Date: Wed, 15 Jan 2020 15:29:37 +0800 Subject: [PATCH 1/3] fizzbuzz first commit --- fizzbuzz.py | 33 +++++++++++++++++++++++++++++++++ fizzbuzz_test.py | 5 +++++ 2 files changed, 38 insertions(+) create mode 100644 fizzbuzz.py create mode 100644 fizzbuzz_test.py diff --git a/fizzbuzz.py b/fizzbuzz.py new file mode 100644 index 0000000..cd34766 --- /dev/null +++ b/fizzbuzz.py @@ -0,0 +1,33 @@ +#!/usr/bin/python +import sys +import getopt + +def main(): + try: + opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) + print_fizzbuzz(int(args[0])) + except: + sys.exit(0) + + +def print_fizzbuzz(input_num): + for i in range(1, input_num+1): + if fizzbuzz(i) != "pass": + print("%s %s" % (i, fizzbuzz(i))) + + +def fizzbuzz(input_num): + if input_num % 3 == 0 and input_num % 5 != 0: + return ("fizz") + elif input_num % 3 != 0 and input_num % 5 == 0: + return ("buzz") + elif input_num % 3 == 0 and input_num % 5 == 0: + return ("fizz buzz") + else: + return "pass" + + + +if __name__ == "__main__": + main() + diff --git a/fizzbuzz_test.py b/fizzbuzz_test.py new file mode 100644 index 0000000..69efa1e --- /dev/null +++ b/fizzbuzz_test.py @@ -0,0 +1,5 @@ +from fizzbuzz import fizzbuzz + + +def test_fizzbuzz(): + assert fizzbuzz(3) == 'fizz' From 55a33cbdb54c9a3c18ace01f2623bc21646fea50 Mon Sep 17 00:00:00 2001 From: sunguangning Date: Wed, 15 Jan 2020 15:32:54 +0800 Subject: [PATCH 2/3] remove helloworld --- helloworld.py | 2 -- helloworld_test.py | 5 ----- 2 files changed, 7 deletions(-) delete mode 100644 helloworld.py delete mode 100644 helloworld_test.py diff --git a/helloworld.py b/helloworld.py deleted file mode 100644 index 449b948..0000000 --- a/helloworld.py +++ /dev/null @@ -1,2 +0,0 @@ -def get_greetings(): - return 'Hello World!' diff --git a/helloworld_test.py b/helloworld_test.py deleted file mode 100644 index 4c27dfe..0000000 --- a/helloworld_test.py +++ /dev/null @@ -1,5 +0,0 @@ -from helloworld import get_greetings - - -def test_get_helloworld(): - assert get_greetings() == 'Hello World!' From 63ebcc7c3edce4c8b8a362b8b07d68b7c91311cd Mon Sep 17 00:00:00 2001 From: sunguangning Date: Thu, 23 Jan 2020 10:02:12 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fizzbuzz.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fizzbuzz.py b/fizzbuzz.py index cd34766..a8cb67f 100644 --- a/fizzbuzz.py +++ b/fizzbuzz.py @@ -2,11 +2,12 @@ import sys import getopt + def main(): try: opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) print_fizzbuzz(int(args[0])) - except: + except EOFError: sys.exit(0) @@ -25,9 +26,7 @@ def fizzbuzz(input_num): return ("fizz buzz") else: return "pass" - if __name__ == "__main__": main() -