【发布时间】:2018-06-11 12:12:14
【问题描述】:
在第二个 while 循环中,我被卡住了,永远无法摆脱。如何解决?
def playGame(wordList):
new_hand = {}
choice = input('Enter n to deal a new hand, or e to end game: ')
while choice != 'e':
if choice == 'n':
player_or_pc = input('Enter u to have yourself play, c to have the computer play: ')
while player_or_pc != 'u' or player_or_pc != 'c':
print('Invalid command.')
player_or_pc = input('Enter u to have yourself play, c to have the computer play: ')
if player_or_pc == 'u':
print('player played the game')
elif player_or_pc == 'c':
print('PC played the game')
choice = input('Enter n to deal a new hand, r to replay the last hand, or e to end game: ')
else:
print('Invalid command.')
choice = input('Enter n to deal a new hand, r to replay the last hand, or e to end game: ')
【问题讨论】:
-
player_or_pc != 'u' or player_or_pc != 'c'- 此条件将始终为真。听起来你想要and而不是or。
标签: python while-loop logical-operators