Vous êtes sur la page 1sur 4

#################################################################

#Program:
#Programmer: Stacey Pierce
#Date:

10/20/14

#Abstract: This program processes a game of rock, paper, scissors based on random input from the
computer. The players's choice is manually entereed. The computers choice is display and the winner is
determined. Total number of tied games, games won by the computer and games won by the player are
displayed at end of game.

import random
def main():
#crate a variable to control the loop
play_again = 'y'
#create a counter for tied games
number_tied_games = 0
#create a counter for games computer won
number_of_comp_games = 0
#create a counter for games player won
number_of_player_games = 0
#display beginning message
print ("Let's play the game of Rock, Paper, Scissors.")
#process Each game of rock, paper, scissors
while play_again == 'y' or play_again == 'Y':
#use a function to get computer's choice
computer_choice = process_computer_choice()
#use a function to get player's choice
player_choice = process_player()
#display computer's choice
if computer_choice == 1:
print ('The computer chooses rock.')

elif computer_choice == 2:
print('The computers chooses paper.')
else:
print('The computers chooses scissors.')
#use a function to determine the winner
result = determine_winner(player_choice, computer_choice)

#accumulate the appropriate winner of game total


if result =='computer':
number_of_comp_games += 1
elif result == 'player':
number_of_player_games += 1
else:
number_of_tied_games += 1

#playing more games?


print
play_again = raw_input ('Do you want to play again? (enter y for yes):')
#display the total number of games tied
print('There were ', number_of_games, 'tie games played.')
#display the total number of games the computer won
print('The computer won ', number_of_comp_games, 'game(s).')
#display the total number of games the player won
print('You won ', number_of_player_games, 'game(s).')

#process computer's choice


def process_computer_choice():
#randomly select the computer's choice from 1 to 3
choice1 = random.ranint,(1,3)

return choice1
#process player's choice
def process_player_choice():
#input the player's choice
print ('What is your choice? Enter 1 for rock, 2 for paper or 3 for scissors:')
choice2=input()
#determine the winner of the game
def determine_winner (player_choice, computer_choice):
if computer_choice == 1:
if player_choice == 2:
print('Paper wraps rock. You win!!')
elif player_choice == 3:
print('Rock smashes scissors. The computer wins!')
winner = 'computer'
else:
print ('The game is tied. Try again.')
winner='tied'
if computer_choice == 2:
if player_choice == 1:
print('Paper wraps rock. The computer wins!')
winner = 'computer'
elif player_choice ==3:
print('Scissors cuts paper. You win!!')
winner = 'player'
else:
print ('the game is tied. Try again.')
winner='tied'
if computer_choice ==3:
if player_choice == 1:

print('Rock smashes scissors. You win!!')


winner = 'player'
elif player_choice ==2:
print('Scissors cuts paper. The computer wins!!')
winner = 'computer'
else:
print ('The game is tied. Try again.')
winner = 'tied'
return winner
#Call the main function
main()

Vous aimerez peut-être aussi