为什么我不能在这里使用 "int "?
Why i cannot use "int " here?
我的interperter版本是python3.5,输入浮点数时出现错误。
这是我的代码:
a = input()
weight = int(a)
print(weight)
错误是:
34.44
Traceback (most recent call last):
File "C:/Text/Project_SDC/Astar_Algorithm/test.py", line 2, in <module>
weight = int(a)
ValueError: invalid literal for int() with base 10: '34.44'
所以如果我还想使用int类型,这个错误有什么解决办法吗??
你应该先将字符串 '34.44'
转换为浮点数,然后使用 int
这将使它只有 34
int(float(a))
或者你可以使用回合:round(float(a))
我的interperter版本是python3.5,输入浮点数时出现错误。 这是我的代码:
a = input()
weight = int(a)
print(weight)
错误是:
34.44
Traceback (most recent call last):
File "C:/Text/Project_SDC/Astar_Algorithm/test.py", line 2, in <module>
weight = int(a)
ValueError: invalid literal for int() with base 10: '34.44'
所以如果我还想使用int类型,这个错误有什么解决办法吗??
你应该先将字符串 '34.44'
转换为浮点数,然后使用 int
这将使它只有 34
int(float(a))
或者你可以使用回合:round(float(a))