本文整理汇总了Python中fractions.Fraction.split方法的典型用法代码示例。如果您正苦于以下问题:Python Fraction.split方法的具体用法?Python Fraction.split怎么用?Python Fraction.split使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fractions.Fraction
的用法示例。
在下文中一共展示了Fraction.split方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: to_frac
# 需要导入模块: from fractions import Fraction [as 别名]
# 或者: from fractions.Fraction import split [as 别名]
def to_frac(v):
v = Fraction(v)
v = v.limit_denominator(1000)
v = str(v)
if "/" in v:
v = v.split("/")
v = "\\frac{%s}{%s}" % (v[0], v[1])
return v
示例2: to_html
# 需要导入模块: from fractions import Fraction [as 别名]
# 或者: from fractions.Fraction import split [as 别名]
def to_html(self):
"""Render the problem in a form that is convertable to
TeX by MathJax. Note that inline MathJax equations are
bracketed by \(...\). Prepends a prompt"""
prompt = "Reduce"
fractions = re.findall('\d+/\d+',self.problem)
h = '\('+self.problem+'\)'
for f in fractions:
a,b = f.split('/')
text = r'\\frac{%s}{%s}'%(a,b)
h = re.sub('\d+/\d+',text,h,count = 1)
return [prompt,h]
示例3: random_arctan_derivative
# 需要导入模块: from fractions import Fraction [as 别名]
# 或者: from fractions.Fraction import split [as 别名]
def random_arctan_derivative():
numerator = random.randint(0, 6)
denominator = random.randint(1, 6)
if numerator == 0:
xvalue = 0
solution = 1
else:
xvalue = Fraction(numerator, denominator)
sol_numerator = denominator ** 2
sol_denominator = numerator ** 2 + denominator ** 2
solution = Fraction(sol_numerator, sol_denominator)
solution = str(solution)
if "/" in solution:
numerator, denominator = solution.split("/")
latex_solution = "\\frac{%s}{%s}" % (numerator, denominator)
else:
latex_solution = solution
if "/" in str(xvalue):
numerator, denominator = str(xvalue).split("/")
xvalue = "\\frac{%s}{%s}" % (numerator, denominator)
return latex_solution, str(xvalue)