Python 骰子游戏不会打破循环

Python 骰子游戏不会打破循环,python,Python,即使循环应该继续,循环仍然会使用==或is函数中断,以便玩家再次尝试滚动。我不明白为什么有人能帮助我。那太好了 elif roll1 is roll2: print(score1) continue 或 它们都不起作用,所以没有人知道为什么 while True: print(" ") input("Press enter to roll player 1 ") print("Rolling dice!") roll1=rand

即使循环应该继续,循环仍然会使用==或is函数中断,以便玩家再次尝试滚动。我不明白为什么有人能帮助我。那太好了

elif roll1 is roll2:
        print(score1)
        continue

它们都不起作用,所以没有人知道为什么

 while True:
    print(" ")
    input("Press enter to roll player 1 ")
    print("Rolling dice!")
    roll1=random.randint(1,6)
    roll2=random.randint(1,6)
    print(roll1)
    print(roll2)
    total=(roll1 + roll2)
    print("Your total is:" ,total)
    score1=score1 +total
    even = [2,4,6,8,10,12]
    odd = [3,5,7,9,11]

    if total in even:
        score1=score1 +10
        print(score1)
        break
    elif total in odd:
        score1=score1 -5
        print(score1)
        break
    elif roll1 == roll2:
        print(score1)
        continue
存在完整循环

问题在于:

if total in even:
    score1=score1 +10
    print(score1)
    break
elif total in odd:
    score1=score1 -5
    print(score1)
    break
elif roll1 == roll2:
    print(score1)
    continue
您永远不会到达最后一个elif,因为总计始终为
偶数
奇数
。如果您希望首先重新滚动,则应将elif上移到如下位置:

if roll1 == roll2:
    print(score1)
    continue
elif total in odd:
    score1=score1 -5
    print(score1)
    break
elif total in even:
    score1=score1 +10
    print(score1)
    break

请提供一个循环。你能在循环中包含完整的代码吗?
if roll1 == roll2:
    print(score1)
    continue
elif total in odd:
    score1=score1 -5
    print(score1)
    break
elif total in even:
    score1=score1 +10
    print(score1)
    break