Discuss / Python / 作业

作业

Topic source

默_kk

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

import math def check(*x): for i in x: if not isinstance(i,(int,float)): raise TypeError('bad operand type')

def quadratic(a,b,c): check(a,b,c) xx = b*2-4ac if a == 0: return -c/b elif xx < 0: return 'No Solution' else: x1 = (-b+math.sqrt(xx))/(2a) x2 = (-b-math.sqrt(xx))/(2*a) return x1,x2

要加好多运算符号。。。

a牵挂a

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

提问: import math def calc(a,b,c): deta = bb - 4ac if(a < 0): return 'input error' elif(deta < 0): return 'input error' else: x1 = (-b+math.sqrt(deta))/2a x2 = (-b-math.sqrt(deta))/2*a return x1,x2

from def_function import calc tu = calc(1,-5,6) print(tu)

函数和使用都在这个def_function文件,但是加入一个import后,结果输出两次 (3.0, 2.0) (3.0, 2.0)


  • 1

Reply