我有一个问题(显然)循环没有按预期工作。假设其他一切都按预期工作,我的第二个while循环(根据分级机)调用raw\u输入的次数超出了需要。你知道吗
代码玩文字游戏。你可以玩一手牌,重放一手牌,或退出。第二个循环决定你是玩手还是玩电脑。你知道吗
所有被调用的函数都正常工作,但是循环调用原始输入的次数太多了。你知道吗
抱歉,如果有很多其他问题,我是相对新的编码。你知道吗
userInput = ''
playInput = ''
hasPlayed = False
# while still playing, e exits
while userInput != 'e':
userInput = raw_input("Enter n to deal a new hand, r to replay the last hand, or e to end game: ").lower()
if userInput not in 'nre':
print("Invalid command.")
elif userInput == 'r' and hasPlayed == False:
print("You have not played a hand yet. Please play a new hand first!")
print
else:
while True:
#
print
playInput = raw_input("Enter u to have yourself play, c to have the computer play: ").lower()
if playInput == 'u':
print
hand = dealHand(HAND_SIZE)
playHand(hand, wordList, HAND_SIZE)
hasPlayed = True
elif playInput == 'c':
print
hand = dealHand(HAND_SIZE)
compPlayHand(hand, wordList, HAND_SIZE)
hasPlayed = True
else:
print("Invalid command.")
print
你的循环运行得非常好;它永远在循环,就像你告诉它的那样:
现在缺少的是一种退出循环的方法。不同条件下的任一试验:
或者使用
break
关键字显式中断循环:相关问题 更多 >
编程相关推荐