Python 3.x 简单的python代码不会将字符串转换为浮点

Python 3.x 简单的python代码不会将字符串转换为浮点,python-3.x,scripting-language,Python 3.x,Scripting Language,我试图编写代码来显示一个球从计算中会升到多高 然而,无论我如何键入它,它总是在高度变量上说它“无法将字符串转换为float” time = input("How long did the ball go up? in seconds\n") time = float(time) velocity = input("What was the initial velocity?\n") velocity = float(velocity) height = ("What was the init

我试图编写代码来显示一个球从计算中会升到多高 然而,无论我如何键入它,它总是在高度变量上说它“
无法将字符串转换为float

time = input("How long did the ball go up? in seconds\n")
time = float(time)

velocity = input("What was the initial velocity?\n")
velocity = float(velocity)

height = ("What was the initial height?\n")
height = float(height)

answer = (time ** 2 * -16) + (velocity * time) + height

print(answer)
ValueError:无法将字符串转换为浮点:“初始高度是多少?\n”


为什么代码不想转换?

这是因为时间是一个
字符串。您不能更改数据类型,但可以强制转换它。你应该做的是:

time = input("How long did the ball go up? in seconds\n")

velocity = input("What was the initial velocity?\n")

height = input("What was the initial height?\n")

answer = (float(time) ** 2 * -16) + (float(velocity) * float(time)) + float(height)

print(answer)

你错过了
input
阅读
height
。打字:你想要
height=input(“初始高度是多少?\n”)
该死的,我没有看到,谢谢你现在帮我写代码