【发布时间】:2019-01-29 14:04:17
【问题描述】:
我正在尝试编写一个请求号码的程序 闪电和雷声之间的秒数,并报告与风暴的距离 四舍五入到小数点后两位。
n = input('Enter the number of seconds between lightning and storm')
1.25
print('Distance from storm',n/5)
但是,当我调用打印函数时,我收到以下错误:
Traceback (most recent call last):
File "<ipython-input-106-86c5a1884a8d>", line 1, in <module>
print('Distance from storm',n/5)
TypeError: unsupported operand type(s) for /: 'str' and 'int'
我该如何解决这个问题?
【问题讨论】:
-
print('Distance from storm',int(n)/5) -
您也可以像其他类似问题一样检查是否输入:stackoverflow.com/questions/5424716/…
标签: python function input spyder