Randint没有指定,即使事先计算 - Python的
问题描述:
我在与编码的部分,这是该位Randint没有指定,即使事先计算 - Python的
def move_bubbles():
for i in range(len(bub_id)):
c.move(bub_id[i], -bub_speed[i], 0)
from time import sleep, time
BUB_CHANCE = 10
#MAIN GAME LOOP
while True:
if randint(1, BUB_CHANCE) == 1:
create_bubble()
move_bubbles()
window.update()
sleep(0.01)
def get_coords(id_num):
pos = c.coords(id_num)
x = (pos[0] + pos[2])/2
y = (pos[1] + pos[3])/2
return x, y
,它说如果randint(1, BUB_CHANCE) == 1:
,显然randint
没有定义的麻烦,即使我以前在相同的代码中使用过它。
有人可以告诉我为什么这是一个错误?我只使用python几天:/
答
请确保您有:
from random import randint
在你的代码的顶部,或:
from numpy.random import randint
如果您正在使用numpy
。
文档:
https://docs.python.org/2/library/random.html
https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.randint.html
你进口吗? –