From 630032fcddc117f9f02ab9a4b302dbf69207577c Mon Sep 17 00:00:00 2001 From: Metropass Date: Mon, 19 Oct 2020 15:49:11 -0400 Subject: [PATCH 1/7] Added DecimalToOctal, and DecimalToRomanNumerals --- README.md | 2 ++ mathgenerator/funcs/__init__.py | 1 + mathgenerator/mathgen.py | 2 ++ 3 files changed, 5 insertions(+) diff --git a/README.md b/README.md index f2d81dc..5b9bcff 100644 --- a/README.md +++ b/README.md @@ -104,3 +104,5 @@ problem, solution = mathgen.genById(0) | 65 | Geometric Progression | For the given GP [4, 16, 64, 256, 1024, 4096] ,Find the value of a,common ratio,8th term value, sum upto 7th term | The value of a is 4, common ratio is 4 , 8th term is 65536 , sum upto 7th term is 21844.0 | geometricprogression | | 66 | Geometric Mean of N Numbers | Geometric mean of 3 numbers 81 , 35 and 99 = | (81*35*99)^(1/3) = 65.47307713912309 | geometricMean | | 67 | Harmonic Mean of N Numbers | Harmonic mean of 2 numbers 99 and 25 = | 2/((1/99) + (1/25)) = 39.91935483870967 | harmonicMean | +| 82 | Decimal to Octal Conversion | What's the octal representation of 98? | 0o142 | decimalToOctalFunc | +| 83 | Decimal to Roman Numerals | What's the Roman Numeral representation of 3805? | MMMDCCCV | decimalToRomanNumeralsFunc diff --git a/mathgenerator/funcs/__init__.py b/mathgenerator/funcs/__init__.py index 83702eb..25e3968 100644 --- a/mathgenerator/funcs/__init__.py +++ b/mathgenerator/funcs/__init__.py @@ -84,3 +84,4 @@ from .compoundInterestFunc import * from .deciToHexaFunc import * from .percentageFunc import * from .celsiustofahrenheit import * +from .decimaltoOctalFunc import * diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index f679b0c..8a26906 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -268,3 +268,5 @@ decimalToHexadeci = Generator("Decimal to Hexadecimal", 79, "Binary of a=", percentage = Generator("Percentage of a number", 80, "What is a% of b?", "percentage", percentageFunc) celsiustofahrenheit = Generator("Celsius To Fahrenheit", 81, "(C +(9/5))+32=", "F", celsiustofahrenheitFunc) +decimalToOctal = Generator("Converts decimal to octal", 82, "What's the octal representation of 98?", "0o142", decimalToOctalFunc) +decimalToRomanNumerals = Generator("Converts decimal to Roman Numerals", 83, "Convert 20 into Roman Numerals", "XX", decimalToRomanNumeralsFunc) From 4be7251a45abf531c6fe02747618681bea05a719 Mon Sep 17 00:00:00 2001 From: Metropass Date: Mon, 19 Oct 2020 15:54:37 -0400 Subject: [PATCH 2/7] Fixed spelling on __init__.py --- mathgenerator/funcs/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mathgenerator/funcs/__init__.py b/mathgenerator/funcs/__init__.py index 25e3968..8600076 100644 --- a/mathgenerator/funcs/__init__.py +++ b/mathgenerator/funcs/__init__.py @@ -84,4 +84,5 @@ from .compoundInterestFunc import * from .deciToHexaFunc import * from .percentageFunc import * from .celsiustofahrenheit import * -from .decimaltoOctalFunc import * +from .decimalToOctalFunc import * +from .decimalToRomanNumeralsFunc import * From 429ea62518f611bbe0c60c1bd479b4c0d9b08602 Mon Sep 17 00:00:00 2001 From: Metropass Date: Mon, 19 Oct 2020 16:00:46 -0400 Subject: [PATCH 3/7] Added untracked files into repo --- mathgenerator/funcs/decimalToOctalFunc.py | 9 +++++++ .../funcs/decimalToRomanNumeralsFunc.py | 26 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 mathgenerator/funcs/decimalToOctalFunc.py create mode 100644 mathgenerator/funcs/decimalToRomanNumeralsFunc.py diff --git a/mathgenerator/funcs/decimalToOctalFunc.py b/mathgenerator/funcs/decimalToOctalFunc.py new file mode 100644 index 0000000..3981cc4 --- /dev/null +++ b/mathgenerator/funcs/decimalToOctalFunc.py @@ -0,0 +1,9 @@ +from .__init__ import * + + +#converts decimal into octal +def decimalToOctalFunc(maxDecimal = 4096): + x = random.randint(0, maxDecimal) + problem = "The decimal number " + str(x) + " in Octal is: " + solution = oct(x) + return problem, solution diff --git a/mathgenerator/funcs/decimalToRomanNumeralsFunc.py b/mathgenerator/funcs/decimalToRomanNumeralsFunc.py new file mode 100644 index 0000000..57d3898 --- /dev/null +++ b/mathgenerator/funcs/decimalToRomanNumeralsFunc.py @@ -0,0 +1,26 @@ +from .__init__ import * + + +#converts decimal to roman numerals +def decimalToRomanNumeralsFunc(maxDecimal = 4000): + x = random.randint(0, maxDecimal) + problem = "The number " + str(x) + " in Roman Numerals is: " + roman_dict = {1:"I", 5:"V", 10: "X", 50:"L", 100:"C", 500:"D", 1000: "M"} + divisor = 1 + while x >= divisor: + divisor *= 10 + divisor /= 10 + solution = "" + while x: + last_value = int(x/divisor) + if last_value <= 3: + solution += (roman_dict[divisor] * last_value) + elif last_value == 4: + solution += (roman_dict[divisor] * roman_dict[divisor*5]) + elif 5 <= last_value <= 8: + solution += (roman_dict[divisor * 5] + (roman_dict[divisor] * (last_value - 5))) + elif last_value == 9: + solution += (roman_dict[divisor] + roman_dict[divisor * 10]) + x = math.floor(x % divisor) + divisor /= 10 + return problem, solution From d19d1de443f3e5db178e867d7061b144a6c16f85 Mon Sep 17 00:00:00 2001 From: Metropass Date: Mon, 19 Oct 2020 16:04:53 -0400 Subject: [PATCH 4/7] Fixed Lint Formatting --- mathgenerator/funcs/decimalToOctalFunc.py | 4 ++-- mathgenerator/funcs/decimalToRomanNumeralsFunc.py | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mathgenerator/funcs/decimalToOctalFunc.py b/mathgenerator/funcs/decimalToOctalFunc.py index 3981cc4..e24b796 100644 --- a/mathgenerator/funcs/decimalToOctalFunc.py +++ b/mathgenerator/funcs/decimalToOctalFunc.py @@ -1,8 +1,8 @@ from .__init__ import * -#converts decimal into octal -def decimalToOctalFunc(maxDecimal = 4096): + +def decimalToOctalFunc(maxDecimal=4096): x = random.randint(0, maxDecimal) problem = "The decimal number " + str(x) + " in Octal is: " solution = oct(x) diff --git a/mathgenerator/funcs/decimalToRomanNumeralsFunc.py b/mathgenerator/funcs/decimalToRomanNumeralsFunc.py index 57d3898..3d2904e 100644 --- a/mathgenerator/funcs/decimalToRomanNumeralsFunc.py +++ b/mathgenerator/funcs/decimalToRomanNumeralsFunc.py @@ -1,22 +1,22 @@ from .__init__ import * -#converts decimal to roman numerals -def decimalToRomanNumeralsFunc(maxDecimal = 4000): + +def decimalToRomanNumeralsFunc(maxDecimal=4000): x = random.randint(0, maxDecimal) problem = "The number " + str(x) + " in Roman Numerals is: " - roman_dict = {1:"I", 5:"V", 10: "X", 50:"L", 100:"C", 500:"D", 1000: "M"} + roman_dict = {1: "I", 5: "V", 10: "X", 50: "L", 100: "C", 500: "D", 1000: "M"} divisor = 1 while x >= divisor: divisor *= 10 divisor /= 10 solution = "" while x: - last_value = int(x/divisor) + last_value = int(x / divisor) if last_value <= 3: solution += (roman_dict[divisor] * last_value) elif last_value == 4: - solution += (roman_dict[divisor] * roman_dict[divisor*5]) + solution += (roman_dict[divisor] * roman_dict[divisor * 5]) elif 5 <= last_value <= 8: solution += (roman_dict[divisor * 5] + (roman_dict[divisor] * (last_value - 5))) elif last_value == 9: From d0734fc7e9b74fc5da1b9cc734a0fe81179454b9 Mon Sep 17 00:00:00 2001 From: Metropass Date: Mon, 19 Oct 2020 16:06:44 -0400 Subject: [PATCH 5/7] Fixed Extra Lines for Lint --- mathgenerator/funcs/decimalToOctalFunc.py | 1 - mathgenerator/funcs/decimalToRomanNumeralsFunc.py | 1 - 2 files changed, 2 deletions(-) diff --git a/mathgenerator/funcs/decimalToOctalFunc.py b/mathgenerator/funcs/decimalToOctalFunc.py index e24b796..64bbae4 100644 --- a/mathgenerator/funcs/decimalToOctalFunc.py +++ b/mathgenerator/funcs/decimalToOctalFunc.py @@ -1,7 +1,6 @@ from .__init__ import * - def decimalToOctalFunc(maxDecimal=4096): x = random.randint(0, maxDecimal) problem = "The decimal number " + str(x) + " in Octal is: " diff --git a/mathgenerator/funcs/decimalToRomanNumeralsFunc.py b/mathgenerator/funcs/decimalToRomanNumeralsFunc.py index 3d2904e..c7183c3 100644 --- a/mathgenerator/funcs/decimalToRomanNumeralsFunc.py +++ b/mathgenerator/funcs/decimalToRomanNumeralsFunc.py @@ -1,7 +1,6 @@ from .__init__ import * - def decimalToRomanNumeralsFunc(maxDecimal=4000): x = random.randint(0, maxDecimal) problem = "The number " + str(x) + " in Roman Numerals is: " From 8a4036469269b6e7a4162bfdbd3f7a8e9604746f Mon Sep 17 00:00:00 2001 From: Luke Weiler Date: Mon, 19 Oct 2020 21:19:32 -0400 Subject: [PATCH 6/7] Update decimalToOctalFunc.py --- mathgenerator/funcs/decimalToOctalFunc.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mathgenerator/funcs/decimalToOctalFunc.py b/mathgenerator/funcs/decimalToOctalFunc.py index 64bbae4..1f2cf6f 100644 --- a/mathgenerator/funcs/decimalToOctalFunc.py +++ b/mathgenerator/funcs/decimalToOctalFunc.py @@ -6,3 +6,6 @@ def decimalToOctalFunc(maxDecimal=4096): problem = "The decimal number " + str(x) + " in Octal is: " solution = oct(x) return problem, solution + + +decimalToOctal = Generator("Converts decimal to octal", 82, "What's the octal representation of 98?", "0o142", decimalToOctalFunc) From e18a35559d8966a0907ebe922d20d0d36dd1ab2e Mon Sep 17 00:00:00 2001 From: Luke Weiler Date: Mon, 19 Oct 2020 21:19:51 -0400 Subject: [PATCH 7/7] Update decimalToRomanNumeralsFunc.py --- mathgenerator/funcs/decimalToRomanNumeralsFunc.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mathgenerator/funcs/decimalToRomanNumeralsFunc.py b/mathgenerator/funcs/decimalToRomanNumeralsFunc.py index c7183c3..407a4f2 100644 --- a/mathgenerator/funcs/decimalToRomanNumeralsFunc.py +++ b/mathgenerator/funcs/decimalToRomanNumeralsFunc.py @@ -23,3 +23,6 @@ def decimalToRomanNumeralsFunc(maxDecimal=4000): x = math.floor(x % divisor) divisor /= 10 return problem, solution + + +decimalToRomanNumerals = Generator("Converts decimal to Roman Numerals", 83, "Convert 20 into Roman Numerals", "XX", decimalToRomanNumeralsFunc)