当前位置: 首页>>代码示例>>Python>>正文


Python Fraction.split方法代码示例

本文整理汇总了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
开发者ID:opatut,项目名称:uni,代码行数:10,代码来源:simplex.py

示例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]
开发者ID:CannonicalForm,项目名称:problem_generator,代码行数:14,代码来源:arithematic.py

示例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)
开发者ID:qdonnellan,项目名称:qCalculus,代码行数:25,代码来源:universal_functions.py


注:本文中的fractions.Fraction.split方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。