我正在做一个飞镖记分员,但它总是一个接一个地转。我只是想知道为什么会这样。 代码:
import time
import sys
from sys import argv
script, name1, name2 = argv
def dartscore():
print "Play from 501 or 301?"
threeorfive = int(raw_input())
if (threeorfive == 501):
def playerone():
startnum1 = threeorfive
while (startnum1 > 0):
print "Ready ", name1,"?"
print "Please enter your score."
minusnum1 = int(raw_input())
startnum1 = startnum1 - minusnum1
playertwo()
if (startnum1 == 0):
print "Well done! You win!"
elif (startnum1 < 0):
print "Sorry but you have entered a wrong score"
playertwo()
def playertwo():
startnum2 = threeorfive
print "Ready ", name2,"?"
print "Please enter your score."
minusnum2 = int(raw_input())
startnum2 = startnum2 - minusnum2
if (startnum2 == 0):
print "Well done! You win!"
print "Unlucky ", name1,". Well played though."
sys.exit()
if (startnum2 < 0):
print "Sorry but you have entered an incorrect score. Please try again"
startnum2 += minusnum2
playerone()
playerone()
dartscore()
现在这两个函数playerone()
和playertwo()
是不同的,因为我正在尝试用playerone()
函数来解决我的问题。在
你有一个
while(startnum1 > 0):
。似乎startnum1
总是大于0。退出循环的唯一方法是播放器2在0上有一个startnum2
。在你的问题是:
在整个游戏中,你开始你的每个功能
^{pr2}$这意味着游戏“重置”后,两个玩家轮流。在
一个可能的解决方案是添加全局变量:
^{3}$然后在每次迭代中更新累积值:
并将while循环更改为:
相关问题 更多 >
编程相关推荐