以计算一元二次方程为例
采用以下两种方法:
①
a,b,c=map(int,input('input the value of a,b,c:').split())
变量直接为int类型
②
a,b,c=input('input the value of a,b,c:').split()
变量返回后是str,需要进行类型转换
import math
def quadratic(a,b,c):
x1=(-1*b+math.sqrt(b*b-4*a*c))/2*a
x2=(-1*b-math.sqrt(b*b-4*a*c))/2*a
return x1,x2
#用.split()进行分割
a,b,c=map(int,input('input the value of a,b,c:').split())
#a,b,c=input('input the value of a,b,c:').split()
# a=int(a)
# b=int(b)
# c=int(c)
x1,x2=quadratic(a,b,c)
print('X1=',x1,' X2=',x2)