我的Python方程求解器可以';不求分数

我的Python方程求解器可以';不求分数,python,loops,integer,equation,Python,Loops,Integer,Equation,好的,我做了一个小的方程求解器来解x。它适用于整数值,但每当我尝试求解分数时,它就会进入一个无止境的循环。这是我的密码: print "Make the variable in your equation stand for x" print startingLimit=int(raw_input("What is the lowest estimate that your variable could possibly be?")) print wholeNumber=raw_input("D

好的,我做了一个小的方程求解器来解x。它适用于整数值,但每当我尝试求解分数时,它就会进入一个无止境的循环。这是我的密码:

print "Make the variable in your equation stand for x"
print
startingLimit=int(raw_input("What is the lowest estimate that your variable could possibly be?"))
print
wholeNumber=raw_input("Do you know if your variable will be a whole number or a fraction? Answer: yes/no")
if (wholeNumber== "yes"):
    print
    fraction= raw_input("Is it a decimal/fraction? Answer:yes/no")
    if (fraction=="yes"):
        print
        print "This program will only calculate up to the 2nd place to the right of the decimal"
        xfinder=float(0.01)
    else:
        xfinder=int(1)
else:
    xfinder=float(0.01)


leftEquation=raw_input("Enter your left side of the equation:")
print
rightEquation=raw_input("Enter the right side of the equation:")
print
amountSolutions=100

print

#solving

a=0
indivisualCount=0
count=0
x=float(startingLimit)
while (count!=amountSolutions):
    ifstuffleft=eval(leftEquation)
    ifstuffright=eval(rightEquation)
    if (ifstuffleft!=ifstuffright):
        x=float(x+xfinder)
        print x
    else:
        a=(a+1)
        count=count+1
        print "Solution",a,"=",x
        print
        x=float(x+xfinder)
if(ifstufflight!=ifstuffright):
应该变成

如果abs(ifstuffleft-ifstuffright)<公差:

其中,
公差
是您愿意接受的错误

如果(ifstufflight!=ifstuffright):
应该变成

如果abs(ifstuffleft-ifstuffright)<公差:


其中,
容差
是您愿意接受的错误

这突出说明OP需要了解浮点值是如何存储在计算机上的。@Jonathon Reinhart,不要生气,但这看起来不像是对OP的构造性响应。至少给他一个到python手册部分的链接:。对于用户1624992来说,问题在于如何在计算机内部处理浮点,这种表示使相等性测试成为一种几乎永远不会返回真值的危险操作,这就是为什么你的程序陷入了无休止的循环。这突出表明OP需要了解浮点值是如何存储在计算机上的。@Jonathon Reinhart,不要生气,但这看起来不像是对OP的构造性响应。至少给他一个到python手册部分的链接:。对于用户1624992来说,问题在于如何在计算机内部处理浮点,这种表示使相等性测试成为一种几乎永远不会返回真值的危险操作,这就是为什么您的程序陷于无休止的循环中