Differences between revisions 191 and 195 (spanning 4 versions)
Revision 191 as of 2012-05-16 13:26:52
Size: 1067
Editor: daxian001
Comment:
Revision 195 as of 2012-05-16 13:51:45
Size: 1206
Editor: daxian001
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
----                                       '刚入门,你还要留我多长时间?才肯放我晋级行者啊!!!!' ----

'刚入门,你还要留我多长时间?才肯放我晋级行者啊!!!!'
Line 5: Line 8:
'''
#ax^2+bx+c=0 解二次方程的根
import math
def getroot(a,b,c):
    if a==0:
        if b!=0:
            r1=r2=-c/b
        else:
            r1=r2=None
            print('a,b,c!=0')
    else:
        d=b**2-4*a*c
        e1=-b+math.sqrt(abs(d))
        e2=-b-math.sqrt(abs(d))
        if d>0:
            r1=e1/(2*a)
            r2=e2/(2*a)
        elif d==0:
            r1=r2=-b/(2*a)
        else:
            r1=r2=None
            print('无根')
    return(r1,r2)
Line 29: Line 9:
a=['a','b','c']
b=[0,0,0]
for i in range(3):
    a[i]=input("please float integer %s="%a[i])
    if a[i]:
        try:
            j=float(a[i])
        except ValueError as err:
            print(err)
            break
    b[i]=j
print('方程的根为:',getroot(b[0],b[1],b[2]))
'''
'''#ax^2+bx+c=0 解二次方程的根<<BR>>import math<<BR>>def getroot(a,b,c):<<BR>> if a==0:<<BR>> if b!=0:<<BR>> r1=r2=-c/b<<BR>> else:<<BR>> r1=r2=None<<BR>> print('a,b,c!=0')<<BR>> else:<<BR>> d=b**2-4*a*c<<BR>> e1=-b+math.sqrt(abs(d))<<BR>> e2=-b-math.sqrt(abs(d))<<BR>> if d>0:<<BR>> r1=e1/(2*a)<<BR>> r2=e2/(2*a)<<BR>> elif d==0:<<BR>> r1=r2=-b/(2*a)<<BR>> else:<<BR>> r1=r2=None<<BR>> print('无根')<<BR>> return(r1,r2)'''
Line 43: Line 11:
["PythonLearningPlan"]
["MyNewPage"]
'''a=['a','b','c']<<BR>>b=[0,0,0]<<BR>>for i in range(3):<<BR>> a[i]=input("please float integer %s="%a[i])<<BR>> if a[i]:<<BR>> try:<<BR>> b[i]=float(a[i])<<BR>> except ValueError as err:<<BR>> print(err)<<BR>> break<<BR>>if ValueError:<<BR>> pass<<BR>>else:<<BR>> print('方程的根为:',getroot(b[0],b[1],b[2]))<<BR>>'''

["PythonLearningPlan"] ["MyNewPage"]


'刚入门,你还要留我多长时间?才肯放我晋级行者啊!!!!'

'自己编写的一个小小简单python程序'

#ax^2+bx+c=0 解二次方程的根
import math
def getroot(a,b,c):
if a==0:
if b!=0:
r1=r2=-c/b
else:
r1=r2=None
print('a,b,c!=0')
else:
d=b**2-4*a*c
e1=-b+math.sqrt(abs(d))
e2=-b-math.sqrt(abs(d))
if d>0:
r1=e1/(2*a)
r2=e2/(2*a)
elif d==0:
r1=r2=-b/(2*a)
else:
r1=r2=None
print('无根')
return(r1,r2)

a=['a','b','c']
b=[0,0,0]
for i in range(3):
a[i]=input("please float integer %s="%a[i])
if a[i]:
try:
b[i]=float(a[i])
except ValueError as err:
print(err)
break
if ValueError:<<BR>> pass
else:
print('方程的根为:',getroot(b[0],b[1],b[2]))

["PythonLearningPlan"] ["MyNewPage"]

WikiSandBox (last edited 2013-12-17 14:04:40 by lengxuezhixuan)