Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 取代「;“如果声明条件”; def move_点(窗口、中心、半径、速度): 大小=(window.get\u width(),window.get\u height()) 对于范围(0,2)中的索引: #在坐标处更新中心 中心[指数]=中心[指数]+速度[指数] #窗外的点边? 如果(中心[索引]=大小[索引]): #转向 速度[指数]=-速度[指数]_Python_Python 3.x_Python 2.7 - Fatal编程技术网

Python 取代「;“如果声明条件”; def move_点(窗口、中心、半径、速度): 大小=(window.get\u width(),window.get\u height()) 对于范围(0,2)中的索引: #在坐标处更新中心 中心[指数]=中心[指数]+速度[指数] #窗外的点边? 如果(中心[索引]=大小[索引]): #转向 速度[指数]=-速度[指数]

Python 取代「;“如果声明条件”; def move_点(窗口、中心、半径、速度): 大小=(window.get\u width(),window.get\u height()) 对于范围(0,2)中的索引: #在坐标处更新中心 中心[指数]=中心[指数]+速度[指数] #窗外的点边? 如果(中心[索引]=大小[索引]): #转向 速度[指数]=-速度[指数],python,python-3.x,python-2.7,Python,Python 3.x,Python 2.7,这是我上面为在窗口内反弹的程序编写的代码。我的问题是,如果(中心[index]=size[index]):直线的中心与窗边接触,而不是其中一条边与窗边接触时反弹,我应该用什么来替换它。(我将在下面附上完整的问题,以便大家更好地了解我正在尝试做什么 [如果您希望点在其中心接触窗口边缘时反弹,而不是在其一条边缘接触窗口边缘时反弹,则应使用什么代码替换“if语句条件”?您只能更改条件。您不能添加或删除任何其他代码。] 我尝试使用代码if(center[index]=size(window(5004

这是我上面为在窗口内反弹的程序编写的代码。我的问题是,如果(中心[index]=size[index]):直线的中心与窗边接触,而不是其中一条边与窗边接触时反弹,我应该用什么来替换它。(我将在下面附上完整的问题,以便大家更好地了解我正在尝试做什么


[如果您希望点在其中心接触窗口边缘时反弹,而不是在其一条边缘接触窗口边缘时反弹,则应使用什么代码替换“if语句条件”?您只能更改条件。您不能添加或删除任何其他代码。]



我尝试使用代码
if(center[index]=size(window(500400)):
if(center[index]=size[window]):
我会得到错误
错误:当中心坐标小于或等于0或大于或等于大小(宽度或高度)时,它会反弹有人能指导我或帮助我吗?谢谢

基本上你想让球在球中心击中窗口边缘时反弹。它当前的编码是在球边缘击中时反弹

检查球位置时,只需去除半径间隙:

def move_dot(window, center, radius, velocity):
    size = (window.get_width(), window.get_height())
    for index in range(0, 2):
        # update center at coordinate
        center[index] = center[index] + velocity[index]
        # dot edge outside window?
        if (center[index] <= radius) or (center[index] + radius >= size[index]):
        # change direction
            velocity[index] = - velocity[index]
if(中心[索引]=大小[索引]):

成功了,我必须删除“如果”和“:”部分才能提交。非常感谢
if (center[index] <= 0) or (center[index] >= size[index]):