69 lines
1.8 KiB
Python
Executable file
69 lines
1.8 KiB
Python
Executable file
#! /usr/bin/env python3
|
|
|
|
import random, sys
|
|
|
|
print('ROCK, PAPER, SCISSORS')
|
|
|
|
#variables to keep track of wins, losses, ties.
|
|
wins =0
|
|
losses = 0
|
|
ties = 0
|
|
|
|
while True: #main game loop.
|
|
print('%s Wins, %s Losses, %s Ties' %(wins, losses, ties))
|
|
while True: #input loop
|
|
print('Enter your move: (r)ock, (p)aper, (s)cissors, or (q)uit')
|
|
playerMove = input()
|
|
if playerMove == 'q':
|
|
sys.exit() #exit program
|
|
elif playerMove == 'r' or playerMove == 'p' or playerMove == 's':
|
|
break #get out of input loop.
|
|
else:
|
|
print('type of of r, p, s, or q.')
|
|
|
|
#display player choice.
|
|
if playerMove == 'r':
|
|
print('ROCK vs ...')
|
|
elif playerMove == 'p':
|
|
print('PAPER vs ...')
|
|
elif playerMove == 's':
|
|
print('SCISSORS vs ...')
|
|
|
|
#determine computer move and display it.
|
|
randomNumber = random.randint(1,3)
|
|
if randomNumber == 1:
|
|
computerMove = 'r'
|
|
print('ROCK')
|
|
if randomNumber == 2:
|
|
computerMove = 'p'
|
|
print('PAPER')
|
|
if randomNumber == 3:
|
|
computerMove = 's'
|
|
print('SCISSORS')
|
|
|
|
#determine and display results.
|
|
if playerMove == computerMove:
|
|
print('Its a Tie!')
|
|
ties += 1
|
|
elif playerMove == 'r':
|
|
if computerMove == 's':
|
|
print('You Win!')
|
|
wins += 1
|
|
else:
|
|
print('You Loose!')
|
|
losses += 1
|
|
elif playerMove == 'p':
|
|
if computerMove == 'r':
|
|
print('You Win!')
|
|
wins +=1
|
|
else:
|
|
print('You Loose!')
|
|
losses += 1
|
|
elif playerMove == 's':
|
|
if computerMove == 'p':
|
|
print('You Win!')
|
|
wins +=1
|
|
else:
|
|
print('You Loose!')
|
|
losses +=1
|