我的终极目标是,把今年在地貌学中学习的所有东西都纳入到斯图尔的档案中(每个不同的教训将是一个不同的档案,例如,外在因素上,在计算器上找到_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