Discuss / Python / 交作业 又发了一遍,发现删除不了评论,也无法回复, ̄□ ̄||

交作业 又发了一遍,发现删除不了评论,也无法回复, ̄□ ̄||

Topic source

落落2800

#1 Created at ... [Delete] [Delete and Lock User]

# -*- coding: utf-8 -*-
import math

def quadratic(a, b, c):
    x1=0
    x2=0
    if not isinstance(a,(int,float)) or not isinstance(a,(int,float)) or not isinstance(a,(int,float)):
        raise TypeError('bad operand type')
    if a == 0:
        print('分母a不能为0!')
    elif ((b*b-4*a*c)<0):
        print('负数无法开平方!,方程无解')
    else:
        x1=(-b+math.sqrt(b*b-4*a*c))/2*a
        x2=(-b-math.sqrt(b*b-4*a*c))/2*a
        print('方程解1为:',x1)
        print('方程解2为:',x2)
quadratic(1,1,1)


  • 1

Reply