global bullet
global ball
global ball_x
pred1 = [bullet, ball]
pred2 = random.choice(pred1)
process = image(pred2, ball_x, 10)
time.sleep(0.5)
ball_x = [100,200,300]
我需要知道如何对“过程”进行编程,使其在“ 0.5”秒后重复自身,然后再次睡眠“ 0.5”秒,以此类推,直到永远重复此过程。
如果要以0.5秒的延迟将process
置于无限循环中,则可以执行以下操作:
while True:
process = image(pred2, ball_x, 10)
time.sleep(0.5)
首先添加import time
或from time import sleep
。然后在while True:
循环中执行time.sleep(0.5)