Randint没有指定,即使它事先工作 - Python

时间:2016-10-28 16:36:59

标签: 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:/

1 个答案:

答案 0 :(得分:0)

确保您拥有:

# this will return the key with the max number of vowels
def favorite_wish
  @submitted_wishes.keys.max_by { |wish| wish.count('aeiou') }
end

# this will return the value to the key with the max number of vowels
def favorite_wish
  max_key = @submitted_wishes.keys.max_by { |wish| wish.count('aeiou') }
  @submitted_wishes[max_key]
end

位于代码顶部,或者:

from random import randint 

如果您使用的是from numpy.random import randint

文件:

https://docs.python.org/2/library/random.html

https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.randint.html