为什么我的程序只在Python中没有错误地停止?

时间:2020-01-16 10:11:37

标签: python

编译器停止 enter image description here

import time
import random

def game():
    score1=0
    score2=0
    name1=input("Player 1, please enter your name: ")
    time.sleep(0.5)
    name2=input("Player 2, please enter your name: ")
    time.sleep(0.5)
    print(name1, "rolls two dice")
    dice1=random.randint(0,6)
    dice2=random.randint(0,6)
    time.sleep(0.5)
    if dice1 == dice2:
        print(name1, "rolled a double! They may roll a third dice, whatever number they roll will be the number of points they earn.")
        dice3=random.randint(0,6)
        score1=score1+dice3
        print(name1, "rolled", dice3)
    else:
        total=dice1+dice2
        if (total % 2) == 0:
            score1=score1+10
        else:
            score1=score1-5

#Start
goes=0
while goes >10:
    goes=0+1
    game()

当我运行我的代码时,它会一直工作到掷出两个骰子为止(即当它停止时),编译器将返回到其打开状态。我也不知道自己在做什么错,将不胜感激。

1 个答案:

答案 0 :(得分:1)

您必须在此处修复两件事。

  1. while goes > 10 这应该是while goes < 10goes最初是0,并且您的条件检查结果大于10,该值将永远不起作用,并且在while循环中不会进入。

  2. goes=0+1应该是goes = goes + 1goes += 1。每次进入while循环时,您的代码都会将goes设置为1