我正在编写一个基于雨量器半径的雨量器降水计算器。当我运行我的脚本时,出现以下错误消息:
Type de raingauge radius [cm]: 5.0
Traceback (most recent call last):
File "pluviometro.py", line 27, in <module>
area_bocal = (pi * (raio_bocal * raio_bocal)) # cm.cm
TypeError: can't multiply sequence by non-int of type 'str'
我正在使用
raio_bocal = input("Type de raingauge radius [cm]:")
用于数据输入。使用 Python2
时,类型转换是自动的。
如何使用 python3
输入一个 float
值?
最佳答案
如 docs 中所述
The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that
所以你需要明确地将其类型转换为float
raio_bocal = float(input("Type de raingauge radius [cm]:"))
关于python - python3 类型转换是否输入了 input() 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29318565/