0 python floating-point python-3.x
我一直试图运行这个函数,但程序一直说我需要在下面的第6行输入一个浮点数.当我尝试输入float()函数时,它仍然说我需要一个浮点数.我想我做错了.我如何正确进入浮球?(我正在运行Python 3.3.)
import math
a=input('a=?')
b=input('b=?')
c=input('c=?')
d=input('d=?')
critical_point_p=((-2*b)+math.sqrt((4*(math.pow(b, 2)))-(12*a*c)))/(2*a)
critical_point_n=((-2*b)-math.sqrt((4*(math.pow(b, 2)))-(12*a*c)))/(2*a)
Run Code Online (Sandbox Code Playgroud)
当您使用input()函数时,它会从用户那里获取STRING.所以从本质上讲,你是在函数中插入一个字符串.字符串可能是'hello','5'或'5.23',它们都会导致错误,因为它是字符读取.您需要将输入转换为float.
a = float(input('a=?'))
Run Code Online (Sandbox Code Playgroud)
那条线就可以了.当然,对其他输入字段也一样.
归档时间: |
|
查看次数: |
57 次 |
最近记录: |