标红的while——统领全局,位于所有循环语句最左侧
import random, sys print('Rock ,paper,scissors') # keep track of the number of wins,losses and ties wins = 0 losses = 0 ties = 0 while True: print('%s Wins,%s Losses,%s Ties' % (wins, losses, ties)) while True: print('enter your move :(r)ock (p)aper (s)cissors or (q)uit') playMove = input() if playMove == 'q': sys.exit() elif playMove == 'r' or playMove == 'p' or playMove == 's': break print('type one of r,p,s,q.') # Display what the player chose: if playMove == 'r': print('ROCK versus...') elif playMove == 'p': print('PAPER versus...') elif playMove == 'S': print('SCISSORS versus...') # Display what the computer chose: randomNumber = random.randint(1, 3) if randomNumber == 1: computerMove = 'r' print('Rock') elif randomNumber == 2: computerMove = 'p' print('Paper') elif randomNumber == 3: computerMove = 's' print('Scissors') # Display and record the win/loss/tie: if computerMove == playMove: print('It is a tie!') ties = ties + 1 elif playMove == 'r' and computerMove == 's': print('you win') wins = wins + 1 elif playMove == 's' and computerMove == 'p': print('you win') wins = wins + 1 elif playMove == 'p' and computerMove == 'r': print('you win') wins = wins + 1 elif playMove == 'p' and computerMove == 's': print('you lose') losses = losses + 1 elif playMove == 'r' and computerMove == 'p': print('you lose') losses = losses + 1 elif playMove == 's' and computerMove == 'r': print('you lose') losses = losses + 1