我是一般编程新手,我似乎无法让编辑器窗口让我添加多个输入命令
每当我尝试添加它们时,它只会显示上一个输入命令的结果,并且不允许我添加更多内容来完成我的代码
distance = 450
speed = eval (input("Enter Average Speed:"))
#after pressing enter here, the IDLE shows the result of this line but when I type in the result it forgets the variable speed and I have no option left
time = distance/speed
print ("Distance is:", distance)
print ("Time is:" , time , "hr")```
我认为您正在寻找的函数是 float() 而不是 eval()。 Eval 本质上接受一个字符串并运行其内容,就好像它是它自己的 python 代码一样。如果您只想将输入转换为数字,那么 float 会产生奇迹。