Discuss / Python / 作业

作业

Topic source

taiwen1314

#1 Created at ... [Delete] [Delete and Lock User]
在此插入代码

-- coding: utf-8 --

import math

def quadratic(a,b,c): for n in (a,b,c): if not isinstance(n,(float,int)) : raise TypeError('use float or int variable') delta = bb - 4ac if a == 0: x1=-c/b x2=-c/b print ("quadratic(a,b,c)#=>(%s,%s)" %(x1,x2))
elif delta < 0: print ("无解") else: x1=(-b+math.sqrt(delta))/(2
a) x2=(-b-math.sqrt(delta))/(2*a) print ("quadratic(a,b,c)#=>(%s,%s)" %(x1,x2)) return

taiwen1314

#2 Created at ... [Delete] [Delete and Lock User]
在此插入代码
# -*- coding: utf-8 -*-

import math


def quadratic(a,b,c):
    for n in (a,b,c):
        if not isinstance(n,(float,int)) :
            raise TypeError('use float or int variable')
    delta = b*b - 4*a*c
    if a == 0:
        x1=-c/b
        x2=-c/b
        print ("quadratic(a,b,c)#=>(%s,%s)" %(x1,x2))    
    elif delta < 0:
        print ("无解")
    else:
        x1=(-b+math.sqrt(delta))/(2*a)
        x2=(-b-math.sqrt(delta))/(2*a)
        print ("quadratic(a,b,c)#=>(%s,%s)" %(x1,x2))
        return

  • 1

Reply