为什么我的程序只是在Python中停止而没有错误?
编译器刚刚停止为什么我的程序只是在Python中停止而没有错误?,python,Python,编译器刚刚停止 当我运行我的代码时,它一直工作,直到它掷两个骰子为止,也就是说,当它刚刚停止时,编译器返回到它的打开状态。我也不确定我做错了什么,非常感谢您的帮助。这里有两件事您必须解决 whilegoes>10 这应该是而不是
当我运行我的代码时,它一直工作,直到它掷两个骰子为止,也就是说,当它刚刚停止时,编译器返回到它的打开状态。我也不确定我做错了什么,非常感谢您的帮助。这里有两件事您必须解决
whilegoes>10
这应该是而不是<10
goes
最初是0
,您的条件检查goes是否大于10,这将永远不起作用,并且在循环时不会进入goes=0+1
这应该是goes=goes+1
或goes+=1
。每次进入while循环时,代码都会将goes
设置为1
goes永远不会等于10,不完全确定你试图解决的问题是什么,尽管你有问题在这里
goes=0+1
你保持重新启动尚未完成,对不起,我应该澄清一下。每次迭代都会要求玩家提供名称。也许将获取名称作为一个单独的函数,并且只调用一次?然后用goes+=1掷任意数量的骰子
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()