Discuss / Python / 求助,无法运算

求助,无法运算

Topic source

GhZicE-奇

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

运行结果如下: Please input a0 Please input b0 Please input c0

Process finished with exit code 0

代码如下:

# -*- coding: utf-8 -*-

import math

a = float(input('Please input a'))
b = float(input('Please input b'))
c = float(input('Please input c'))

def quadratic(a, b, c):
    print (quadratic(a, b, c))
    if (a==0):
        print (quadratic())
        return 'value of a cannot be 0'
    else :
        derta = b**2 - 4*a*c
        if (derta >= 0):
            x1 = (-b + math.sqrt(derta))/(2*a)
            x2 = (-b - math.sqrt(derta))/(2*a)
            return x1, x2
        else :
            return 'Wrong Number!'
    print (quadratic(a, b, c))

GhZicE-奇

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

已解决。print 位置的问题。

# -*- coding: utf-8 -*-

import math

a = float(input('Please input a'))
b = float(input('Please input b'))
c = float(input('Please input c'))

def quadratic(a, b, c):
    if (a==0):
        return 'value of a cannot be 0'
    else :
        derta = b**2 - 4*a*c
        if (derta >= 0):
            x1 = (-b + math.sqrt(derta))/(2*a)
            x2 = (-b - math.sqrt(derta))/(2*a)
            return x1, x2
        else :
            return 'Wrong Number!'

print (quadratic(a, b, c))

  • 1

Reply