diff --git a/.travis.yml b/.travis.yml index a3ff22fb0..bea512264 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,10 +18,6 @@ script: --ignore=machine_learning/perceptron.py --ignore=machine_learning/random_forest_classification/random_forest_classification.py --ignore=machine_learning/random_forest_regression/random_forest_regression.py - --ignore=maths/abs_min.py - --ignore=maths/binary_exponentiation.py - --ignore=maths/lucas_series.py - --ignore=maths/sieve_of_eratosthenes.py after_success: - python scripts/build_directory_md.py - cat DIRECTORY.md diff --git a/maths/abs_min.py b/maths/abs_min.py index d546196aa..abb0c9051 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 cf789afc6..a8d736adf 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") +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)) + RESULT = binary_exponentiation(BASE, POWER) + print("{}^({}) : {}".format(BASE, POWER, RESULT)) diff --git a/maths/lucas_series.py b/maths/lucas_series.py index 91ea1ba72..9ae437dc9 100644 --- a/maths/lucas_series.py +++ b/maths/lucas_series.py @@ -1,13 +1,21 @@ # 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)) + """ + >>> recur_luc(1) + 1 + >>> recur_luc(0) + 2 + """ + 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:")) + 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 11c123693..cedd04f92 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())))