From 987fc04c2778bbaff51912c3eb530ae97cec13c2 Mon Sep 17 00:00:00 2001 From: cclauss Date: Sun, 14 Jul 2019 11:27:47 +0200 Subject: [PATCH 1/3] Travis CI: Add pytest --doctest-modules maths --- .travis.yml | 1 + maths/abs_min.py | 9 ++++++--- maths/binary_exponentiation.py | 17 +++++++++-------- maths/lucas series.py | 13 ------------- maths/lucas_series.py | 14 ++++++++++++++ maths/sieve_of_eratosthenes.py | 6 ++---- 6 files changed, 32 insertions(+), 28 deletions(-) delete mode 100644 maths/lucas series.py create mode 100644 maths/lucas_series.py diff --git a/.travis.yml b/.travis.yml index 9afc0c93a037..6a7137c85d60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,7 @@ script: dynamic_programming hashes linear_algebra_python + maths matrix networking_flow other diff --git a/maths/abs_min.py b/maths/abs_min.py index d546196aa1b5..abb0c9051b7d 100644 --- a/maths/abs_min.py +++ b/maths/abs_min.py @@ -1,10 +1,11 @@ -from abs import abs_val +from .abs import abs_val + def absMin(x): """ - # >>>absMin([0,5,1,11]) + >>> absMin([0,5,1,11]) 0 - # >>absMin([3,-10,-2]) + >>> absMin([3,-10,-2]) -2 """ j = x[0] @@ -13,9 +14,11 @@ def absMin(x): j = i return j + def main(): a = [-3,-1,2,-11] print(absMin(a)) # = -1 + if __name__ == '__main__': main() \ No newline at end of file diff --git a/maths/binary_exponentiation.py b/maths/binary_exponentiation.py index cf789afc6f22..a8d736adfea0 100644 --- a/maths/binary_exponentiation.py +++ b/maths/binary_exponentiation.py @@ -17,11 +17,12 @@ def binary_exponentiation(a, n): return b * b -try: - BASE = int(input('Enter Base : ')) - POWER = int(input("Enter Power : ")) -except ValueError: - print("Invalid literal for integer") - -RESULT = binary_exponentiation(BASE, POWER) -print("{}^({}) : {}".format(BASE, POWER, RESULT)) +if __name__ == "__main__": + try: + BASE = int(input("Enter Base : ").strip()) + POWER = int(input("Enter Power : ").strip()) + except ValueError: + print("Invalid literal for integer") + + RESULT = binary_exponentiation(BASE, POWER) + print("{}^({}) : {}".format(BASE, POWER, RESULT)) diff --git a/maths/lucas series.py b/maths/lucas series.py deleted file mode 100644 index 91ea1ba72a56..000000000000 --- a/maths/lucas series.py +++ /dev/null @@ -1,13 +0,0 @@ -# Lucas Sequence Using Recursion - -def recur_luc(n): - if n == 1: - return n - if n == 0: - return 2 - return (recur_luc(n-1) + recur_luc(n-2)) - -limit = int(input("How many terms to include in Lucas series:")) -print("Lucas series:") -for i in range(limit): - print(recur_luc(i)) diff --git a/maths/lucas_series.py b/maths/lucas_series.py new file mode 100644 index 000000000000..04312f2fb78b --- /dev/null +++ b/maths/lucas_series.py @@ -0,0 +1,14 @@ +# Lucas Sequence Using Recursion + +def recur_luc(n): + if n == 1: + return n + if n == 0: + return 2 + return (recur_luc(n-1) + recur_luc(n-2)) + +if __name__ == "__main__": + limit = int(input("How many terms to include in Lucas series:").strip()) + print("Lucas series:") + for i in range(limit): + print(recur_luc(i)) diff --git a/maths/sieve_of_eratosthenes.py b/maths/sieve_of_eratosthenes.py index 11c123693694..cedd04f92aa0 100644 --- a/maths/sieve_of_eratosthenes.py +++ b/maths/sieve_of_eratosthenes.py @@ -2,9 +2,6 @@ import math -N = int(input("Enter n: ")) - - def sieve(n): """Sieve of Eratosthones.""" l = [True] * (n + 1) @@ -26,4 +23,5 @@ def sieve(n): return prime -print(sieve(N)) +if __name__ == "__main__": + print(sieve(int(input("Enter n: ").strip()))) From 6ebf7be90b73f45b60b74222ea6b53793835778d Mon Sep 17 00:00:00 2001 From: John Law Date: Sun, 21 Jul 2019 00:47:29 +0800 Subject: [PATCH 2/3] Update lucas_series.py --- maths/lucas_series.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/maths/lucas_series.py b/maths/lucas_series.py index 9d9954aafd50..22ad893a6567 100644 --- a/maths/lucas_series.py +++ b/maths/lucas_series.py @@ -3,11 +3,11 @@ def recur_luc(n): """ - >>> recur_luc(1) - 1 - >>> recur_luc(0) - 2 - """ + >>> recur_luc(1) + 1 + >>> recur_luc(0) + 2 + """ if n == 1: return n if n == 0: From 7996f34d6d2f2b67d782b04234d417ce2c170762 Mon Sep 17 00:00:00 2001 From: John Law Date: Sun, 21 Jul 2019 00:47:51 +0800 Subject: [PATCH 3/3] Update lucas_series.py --- maths/lucas_series.py | 1 - 1 file changed, 1 deletion(-) diff --git a/maths/lucas_series.py b/maths/lucas_series.py index 22ad893a6567..9ae437dc9f54 100644 --- a/maths/lucas_series.py +++ b/maths/lucas_series.py @@ -1,6 +1,5 @@ # Lucas Sequence Using Recursion - def recur_luc(n): """ >>> recur_luc(1)