This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Display what the player chose: | |
| if playerMove == 'r': | |
| print('ROCK versus...') | |
| elif playerMove == 'p': | |
| print('PAPER versus...') | |
| elif playerMove == 's': | |
| print('SCISSORS versus...') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| while True: # The main game loop | |
| print('%s Wins, %s Losses, %s Ties' % (wins, losses, ties)) | |
| while True: # The player input loop. | |
| print('Enter your move: (r)ock (p)aper (s)cissors or (q)uit') | |
| playerMove = input() | |
| if playerMove == 'q': | |
| sys.exit() #Quit the program. | |
| if playerMove == 'r' or playerMove == 'p' or playerMove == 's': | |
| break # Break out of the player input loop. | |
| print('Type one of r, p, s, or q.') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # These variables keep track of the number of wins, losses and ties. | |
| wins = 0 | |
| losses = 0 | |
| ties = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random, sys | |
| print('ROCK, PAPER, SCISSORS') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Display and record the win/loss/tie: | |
| if playerMove == computerMove: | |
| print('It is a tie!') | |
| ties = ties + 1 | |
| elif playerMove == 'r' and computerMove == 's': | |
| print('You win!') | |
| wins = wins + 1 | |
| elif playerMove == 'p' and computerMove == 'r': | |
| print('You win!') | |
| wins = wins + 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Display what the player chose: | |
| if playerMove == 'r': | |
| print('ROCK versus...') | |
| elif playerMove == 'p': | |
| print('PAPER versus...') | |
| elif playerMove == 's': | |
| print('SCISSORS versus...') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| while True: # The main game loop | |
| print('%s Wins, %s Losses, %s Ties' % (wins, losses, ties)) | |
| while True: # The player input loop. | |
| print('Enter your move: (r)ock (p)aper (s)cissors or (q)uit') | |
| playerMove = input() | |
| if playerMove == 'q': | |
| sys.exit() #Quit the program. | |
| if playerMove == 'r' or playerMove == 'p' or playerMove == 's': | |
| break # Break out of the player input loop. | |
| print('Type one of r, p, s, or q.') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| wins = 0 | |
| losses = 0 | |
| ties = 0 |