Python的奇怪之处

2024-04-25 23:06:47 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我有一些代码:

self.nextY = int(self.y + self.aY * 0,7071 - (9.98 * 0.1 * 0.1)/2)

以下是回溯:

Traceback (most recent call last):
  File "C:\Users\CrazyDude\workspace\flappy-bird-bot\src\main.py", line 16, in <module>
    bird.get_position(image)
  File "C:\Users\CrazyDude\workspace\flappy-bird-bot\src\flappy.py", line 31, in get_position
    self.nextY = int(self.y + self.aY * 0,7071 - (9.98 * 0.1 * 0.1)/2)
TypeError: integer argument expected, got float

如果我把变量改成int,它怎么可能期望int呢?你知道吗


Tags: inpyselfsrcbotlineusersworkspace
1条回答
网友
1楼 · 发布于 2024-04-25 23:06:47

代码将两个参数传递给int函数。(第二个参数被视为base如果有两个参数,它应该是整数。)

>>> int('10', 2.1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: integer argument expected, got float
>>> int('10', 2)
2

也许你是说0.7071而不是0,7071?你知道吗

相关问题 更多 >