English 中文(简体)
不进口的三氯甲烷[封闭式]
原标题:Factoring a trinomial without imports any imports [closed]
Closed. This question needs details or clarity. It is not currently accepting answers.

我的终极目标是,把今年在地貌学中学习的所有东西都纳入到斯图尔的档案中(每个不同的教训将是一个不同的档案,例如,外在因素上,在计算器上找到_an_angle.py,在计算器上找到_length.py(一行),因为我认为这是一个挑战,它将帮助我学会以轻而高效的方式书写代码。 此外,我可以使用任何非专用图书馆,因为计算器显然与Pypi有连接,安装图书馆。

不管怎么说,我正试图做一个因素—— Python。 我想使用 缩略语:(-b) ± sqrt(b)^2 - 4 (a)* (c))/(2*(a),我决定使用这一条,而不是其他任何因素,因为它将获得<条码>c中添加到<条码>的因数/代码>,但是如果是,那么它就会获得为<条码>x<>/条码>发挥作用的因素。 此外,我将能够把它变成激进的形式,然后简化激进分子,这样它就最简单(对激进分子来说是简单的)形式(只有这样一整数字,才会激进)。

我使用的守则如下:

def sqrt_sim(und_root):
    und_root = abs(int(und_root))
    rt_fc = []
    coef = 1
    if und_root < 0:
        return None
    elif und_root == 0:
        return 0
    else:
        for i in range(2, int(und_root**(0.5))+1):
            while und_root % (i**2) == 0:
                rt_fc.append(i)
                und_root /= i**2

        for ele in rt_fc:
            coef *= ele

        if coef == 1:
            sim_rad = "sqrt(" + str(und_root) + ")"

        else:
            sim_rad = str(coef) +  *sqrt(  + str(und_root) + ")"

        return sim_rad


def factor(a, b, c):
    if a == 0:
        print("This is not a quadratic equation")
    else:
        discriminant = b**2 - 4*a*c
        if discriminant < 0:
            sol1 = complex(-b/(2*a), ((-discriminant)**0.5)/(2*a))
            sol2 = complex(-b/(2*a), -((-discriminant)**0.5)/(2*a))
            print(f"This equation has two complex solutions: {sol1} and {sol2}")
        else:
            sol1 = -(-b + (discriminant)**0.5)/(2*a)
            sol2 = -(-b - (discriminant)**0.5)/(2*a)
            if discriminant == 0:
                print(f"This equation has one solution: {round(-b/(2*a), 2)}")
            else:
                print(f"This equation has two solutions: {round(sol1, 2)} and {round(sol2, 2)}")

            if isinstance(sol1, float): # Check if sol1 is a float
                sim_sol1 = sqrt_sim(sol1**2) # Call sqrt_sim with sol1 as argument

                if "*sqrt(1.0)" in sim_sol1:
                    sim_sol1 = sim_sol1.replace("*sqrt(1.0)", "")

                if "sqrt(1)" in sim_sol1:
                    sim_sol1 = sim_sol1.replace("sqrt(1)", "1")

                if sol1 < 0:
                    print(f"Simplified radical sol1: -{sim_sol1}")
                else:
                    print(f"Simplified radical sol1: {sim_sol1}")


            if isinstance(sol2, float): # Check if sol2 is a float
                sim_sol2 = sqrt_sim(sol2**2) # Call sqrt_sim with sol2 as argument

                if "*sqrt(1.0)" in sim_sol2:
                    sim_sol2 = sim_sol2.replace("*sqrt(1.0)", "")

                if "sqrt(1)" in sim_sol2:
                    sim_sol2 = sim_sol2.replace("sqrt(1)", "1")

                if sol2 < 0:
                    print(f"Simplified radical sol2: -{sim_sol2}")
                else:
                    print(f"Simplified radical sol2: {sim_sol2}")

因此,当我投入时:

factor(5, 25, 30)

我收到了:

This equation has two solutions: 2.0 and 3.0
Simplified radical sol1: 2
Simplified radical sol2: 3

因此,当我投入时:

factor(5, -1, -30)

我收到了:

This equation has two solutions: -2.5515301344262524 and 2.3515301344262527
Simplified radical sol1: -sqrt(6)
Simplified radical sol2: sqrt(5)

最后,我要指出,这不是一个问题,我同其他人一样,想用这一法典做一些事情,因为它没有进口任何东西。 另外,如果有人想使用我出于任何理由而制定的守则,他们将在Gite Hub网站上查阅。

Thank you;

Tyler.Creator

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签