Discuss / Python / 终于搞好了

终于搞好了

Topic source

Ostrichfang

#1 Created at ... [Delete] [Delete and Lock User]
# -*- coding: utf-8 -*-import mathdef quadratic(a,b,c):    global x1    global x2    if a==0:         x=(-c)/b         print('非二元一次方程x=',x)    elif a<0:        print('错误')    elif b**2-4*a*c<0:        print('无解')    else:        x1=(-b+math.sqrt(b**2-4*a*c))/(2*a)        x2=(-b-math.sqrt(b**2-4*a*c))/(2*a)        print('x1=', x1, 'x2=', x2)a=float(input('a:'))b=float(input('b:'))c=float(input('c:'))quadratic(a,b,c)

Ostrichfang

#2 Created at ... [Delete] [Delete and Lock User]
# -*- coding: utf-8 -*-import math
def quadratic(a,b,c):
    global x1
    global x2
    if a==0:
         x=(-c)/b
         print('非二元一次方程x=',x)
    elif a<0:
        print('错误')
    elif b**2-4*a*c<0:
        print('无解')
    else:
        x1=(-b+math.sqrt(b**2-4*a*c))/(2*a)
        x2=(-b-math.sqrt(b**2-4*a*c))/(2*a)
        print('x1=', x1, 'x2=', x2)
a=float(input('a:'))
b=float(input('b:'))
c=float(input('c:'))
quadratic(a,b,c)

  • 1

Reply