成功满足条件后,如何停止循环迭代?

因此,我正在处理手工板球脚本,我想在用户选择的数字与CPU选择的数字相等时停止“ for”循环的迭代,如果不相等,则应继续迭代直到未达到最终范围的值

for i in range(1,7):
    print("Ball %d"%i)
    user_choice =int(input("Enter a number between 1 to 6 --> "))
    cpu_choice=random.randint(1,6)

    if user_choice < 7:
        print("CPU picked --> ",cpu_choice)
        run=cpu_choice+run

    if user_choice == cpu_choice:
        print("User is OUT!!")
        run -= cpu_choice
        print("Runs = %d \t Over = %d.%d\n"%(run,i//6,i%6))
        break
        print("Runs = %d \t Over = %d.%d\n"%(run,i//6,i%6))

    else:
        print("\nWRONG CHOICE!! %d ball is cancelled.\n"%i)
        break
评论