当前位置: 代码迷 >> 综合 >> Python一次输入多个值
  详细解决方案

Python一次输入多个值

热度:24   发布时间:2024-02-02 03:01:23.0

以计算一元二次方程为例

采用以下两种方法:

①

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*ax2=(-1*b-math.sqrt(b*b-4*a*c))/2*areturn 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)

 

  相关解决方案