Python如果/ elif与random.randint一起出现问题

api*_*hel 1 python python-3.x

这是一个更大的问题的一部分,但我有这个if/elif函数的一些问题.

def fish():
    import random   

    score = 0

    i = random.randint(0,39)

    if i == [0,19]:
        print("You caught nothing!")
    elif i == [20,39]:
        print("You caught a Minnow! +10 points.")
        score += 10
    print(i)
    print(score)
fish()
Run Code Online (Sandbox Code Playgroud)

当我运行这个时,我得到的是randint数字,得分为0.我不确定我在这里做错了什么.

Ign*_*ams 6

是的,嗯......这不是它的工作方式.您将整数与列表进行比较.

    if 0 <= i < 20:
        print("You caught nothing!")
    elif 20 <= i < 40:
        print("You caught a Minnow! +10 points.")
        score += 10
Run Code Online (Sandbox Code Playgroud)