From 9d68d585b280b31b083abb2d53f4bae6467f43e5 Mon Sep 17 00:00:00 2001 From: lukew3 Date: Sat, 9 Oct 2021 13:57:07 -0400 Subject: [PATCH] lint fixes --- .../basic_math/greatest_common_divisor.py | 24 ++++++++++++------- .../computer_science/nth_fibonacci_number.py | 4 ++-- .../funcs/misc/decimal_to_roman_numerals.py | 22 ++++++++--------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/mathgenerator/funcs/basic_math/greatest_common_divisor.py b/mathgenerator/funcs/basic_math/greatest_common_divisor.py index 1c72694..728bd1f 100644 --- a/mathgenerator/funcs/basic_math/greatest_common_divisor.py +++ b/mathgenerator/funcs/basic_math/greatest_common_divisor.py @@ -1,25 +1,33 @@ from .__init__ import * + def greatestCommonDivisorOfTwoNumbers(number1, number2): number1 = abs(number1) number2 = abs(number2) - while number2>0: number1, number2 = number2, number1%number2 + while number2 > 0: + number1, number2 = number2, number1 % number2 return number1 -def generator_function(numbersCount=2, maximalNumberLimit=10**9, format='string'): - numbersCount = max(numbersCount, 2) - numbers = [ random.randint(0, maximalNumberLimit) for number in range(numbersCount) ] - greatestCommonDivisor = greatestCommonDivisorOfTwoNumbers(numbers[0], numbers[1]) +def gen_func(numbersCount=2, maximalNumberLimit=10**9, format='string'): + numbersCount = max(numbersCount, 2) + numbers = [random.randint(0, maximalNumberLimit) + for number in range(numbersCount)] + + greatestCommonDivisor = greatestCommonDivisorOfTwoNumbers( + numbers[0], numbers[1]) for index in range(1, numbersCount): - greatestCommonDivisor = greatestCommonDivisorOfTwoNumbers(numbers[index], greatestCommonDivisor) + greatestCommonDivisor = greatestCommonDivisorOfTwoNumbers( + numbers[index], greatestCommonDivisor) if format == "string": return "GCD(" + ",".join(map(str, numbers)) + ") = " + str(greatestCommonDivisor) elif format == "latex": return ("\\(GCD(" + ",".join(map(str, numbers)) + f") = {greatestCommonDivisor}\\)") - else: return greatestCommonDivisor + else: + return greatestCommonDivisor -greatest_common_divisor = Generator("Greatest Common Divisor of N Numbers", 999, generator_function, ["maximalNumberLimit=1000000000"]) \ No newline at end of file +greatest_common_divisor = Generator("Greatest Common Divisor of N Numbers", 115, gen_func, [ + "numbersCount=2", "maximalNumberLimit=10**9"]) diff --git a/mathgenerator/funcs/computer_science/nth_fibonacci_number.py b/mathgenerator/funcs/computer_science/nth_fibonacci_number.py index 5d06300..22c5188 100644 --- a/mathgenerator/funcs/computer_science/nth_fibonacci_number.py +++ b/mathgenerator/funcs/computer_science/nth_fibonacci_number.py @@ -4,10 +4,10 @@ import math def gen_func(maxN=100, format='string'): - golden_ratio = (1 + math.sqrt(5)) / 2 + gratio = (1 + math.sqrt(5)) / 2 n = random.randint(1, maxN) problem = f"What is the {n}th Fibonacci number?" - ans = int((math.pow(golden_ratio, n) - math.pow(-golden_ratio, -n)) / (math.sqrt(5))) + ans = int((math.pow(gratio, n) - math.pow(-gratio, -n)) / (math.sqrt(5))) if format == 'string': return problem, str(ans) diff --git a/mathgenerator/funcs/misc/decimal_to_roman_numerals.py b/mathgenerator/funcs/misc/decimal_to_roman_numerals.py index 53d8cc6..2d7232d 100644 --- a/mathgenerator/funcs/misc/decimal_to_roman_numerals.py +++ b/mathgenerator/funcs/misc/decimal_to_roman_numerals.py @@ -14,23 +14,23 @@ def gen_func(maxDecimal=4000, format='string'): 500: "D", 1000: "M" } - divisor = 1 - while x >= divisor: - divisor *= 10 - divisor /= 10 + div = 1 + while x >= div: + div *= 10 + div /= 10 solution = "" while x: - last_value = int(x / divisor) + last_value = int(x / div) if last_value <= 3: - solution += (roman_dict[divisor] * last_value) + solution += (roman_dict[div] * last_value) elif last_value == 4: - solution += (roman_dict[divisor] + roman_dict[divisor * 5]) + solution += (roman_dict[div] + roman_dict[div * 5]) elif 5 <= last_value <= 8: - solution += (roman_dict[divisor * 5] + (roman_dict[divisor] * (last_value - 5))) + solution += (roman_dict[div * 5] + (roman_dict[div] * (last_value - 5))) elif last_value == 9: - solution += (roman_dict[divisor] + roman_dict[divisor * 10]) - x = math.floor(x % divisor) - divisor /= 10 + solution += (roman_dict[div] + roman_dict[div * 10]) + x = math.floor(x % div) + div /= 10 if format == 'string': problem = "The number " + str(x) + " in Roman Numerals is: "