Discuss / Python / b^2和b**2在python中是不同的

b^2和b**2在python中是不同的

Topic source

#! /usr/bin/env python3

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

import math

def quadratic(a, b, c):

    for v in(a,b,c):

        if not isinstance(v,int):

            raise TypeError('Bad operand type')

    dt = b*b-4*a*c

    if dt >= 0:

        x1 = (-b + math.sqrt(dt))/(2 * a)

        x2 = (-b - math.sqrt(dt))/(2 * a)

        print('该方程的根为',x1,x2)

        return x1,x2

    else:

        print('该方程无实数根')


  • 1

Reply