Discuss / Python / 有点超纲吧

有点超纲吧

Topic source

飞页快刀

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

import math

def quadratic():

    while True:

        try:

            a = float(input('请输入a: '))

            na = float(a)

            break

        except:

            print("需要数字")

    while True:

        try:

            b = float(input('请输入b: '))

            nb = float(b)

            break

        except:

            print("需要数字")

    while True:

        try:

            c = float(input('请输入c: '))

            nc = float(c)

            break

        except:

            print("需要数字")

    if a == 0:

        return ("a不可以为0")

    if b**2 - a*c*4 < 0:

        return ("根号内不能为负数")

    q1 = ((-b + math.sqrt(b**2 - a*c*4)) / (a*2) )

    q2 = ((-b - math.sqrt(b**2 - a*c*4)) / (a*2) )

    return q1, q2

print(quadratic())

张Gerous

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

Traceback (most recent call last):

  File "/Users/tieban/Documents/Python/一元二次方程.py", line 31, in <module>

    print(quadratic())

  File "/Users/tieban/Documents/Python/一元二次方程.py", line 28, in quadratic

    q1 = ((-b + math.sqet(b**2-a*c*4))/(a*2))

AttributeError: module 'math' has no attribute 'sqet'

这是怎么回事呢?请问

飞页快刀

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

是不是复制的时候缩进出问题了


  • 1

Reply