Discuss / Python / 哈哈哈 写了一上午 写脚本不难 难的是我忘记了一元二次方程怎么解,对不起教我数学的体育老师啊。

哈哈哈 写了一上午 写脚本不难 难的是我忘记了一元二次方程怎么解,对不起教我数学的体育老师啊。

Topic source

diska本尊

#1 Created at ... [Delete] [Delete and Lock User]
import math
a = float(input('a'))
b = float(input('b'))
c = float(input('c'))
if  not  isinstance (a, (int, float)):
    raise TypeError('bad operand type')
if  not  isinstance (b, (int, float)):
    raise TypeError('bad operand type')
if  not  isinstance (c, (int, float)):
    raise TypeError('bad operand type')
if a == 0:
    print('a=0:',-(c/b))
else:
    if  (b*b)-(4*a*c) > 0:
        print('one:',(-b + math.sqrt((b*b)-(4*a*c)))/(2*a))
        print('tow:',(-b - math.sqrt((b*b)-(4*a*c)))/(2*a))
        print('math.sqrt=',math.sqrt((b*b)-(4*a*c)))
    else:
        print('no jie')

_Ljj110719

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

哥们你都用了float(input('a')) 那a肯定是个float了。。 后面咋还用if not isinstance (a, (int, float)):

diska本尊

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

@_Ljj110719 说的对,新手,没考虑到那么多。

Python小姐

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

表示同啊!!想了半天没想出应该怎么算,看了答案发现自己是忘记数学公式上了。


  • 1

Reply