mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 14:35:23 +01:00
Merge pull request #276 from Metropass/master
Added DecimalToOctal, and DecimalToRomanNumerals
This commit is contained in:
@@ -31,7 +31,6 @@ problem, solution = mathgen.genById(0)
|
||||
| Id | Skill | Example problem | Example Solution | Function Name |
|
||||
|------|-----------------------------------|--------------------|-----------------------|--------------------------|
|
||||
[//]: # list start
|
||||
| 81 | Celsius To Fahrenheit | Convert 15 degrees Celsius to degrees Fahrenheit = | 59.0 | # addition |
|
||||
| 0 | Addition | 16+3= | 19 | subtraction |
|
||||
| 1 | Subtraction | 96-17= | 79 | multiplication |
|
||||
| 2 | Multiplication | 48*1= | 48 | multiplicationFunc) |
|
||||
|
||||
@@ -86,3 +86,5 @@ from .percentageFunc import *
|
||||
from .celsiustofahrenheit import *
|
||||
from .arithmeticProgressionTermFunc import *
|
||||
from .arithmeticProgressionSumFunc import *
|
||||
from .decimalToOctalFunc import *
|
||||
from .decimalToRomanNumeralsFunc import *
|
||||
|
||||
11
mathgenerator/funcs/decimalToOctalFunc.py
Normal file
11
mathgenerator/funcs/decimalToOctalFunc.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from .__init__ import *
|
||||
|
||||
|
||||
def decimalToOctalFunc(maxDecimal=4096):
|
||||
x = random.randint(0, maxDecimal)
|
||||
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)
|
||||
28
mathgenerator/funcs/decimalToRomanNumeralsFunc.py
Normal file
28
mathgenerator/funcs/decimalToRomanNumeralsFunc.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from .__init__ import *
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
decimalToRomanNumerals = Generator("Converts decimal to Roman Numerals", 83, "Convert 20 into Roman Numerals", "XX", decimalToRomanNumeralsFunc)
|
||||
Reference in New Issue
Block a user