Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random, sys
- def computer_choice():
- computer_choice = random.choice("rps")
- return computer_choice
- def user_choice():
- user_ch = raw_input(" Your Choice ? ")
- if user_ch != "r" and user_ch != "p" and user_ch != "s":
- print " Wrong input, Please try again.\n"
- user_ch = user_choice()
- return user_ch
- def compare_choices(user_choice, computer_choice):
- if user_choice == "r" and computer_choice == "p":
- return "computer"
- elif user_choice == "r" and computer_choice == "s":
- return "user"
- elif user_choice == "r" and computer_choice == "r":
- return "n" # n means nul
- elif user_choice == "p" and computer_choice == "r":
- return "user"
- elif user_choice == "p" and computer_choice == "s":
- return "computer"
- elif user_choice == "p" and computer_choice == "p":
- return "n"
- elif user_choice == "s" and computer_choice == "r":
- return "computer"
- elif user_choice == "s" and computer_choice == "p":
- return "user"
- elif user_choice == "s" and computer_choice == "s":
- return "n"
- def play_again():
- print "Game Over"
- choice = raw_input(" Would you like to play again? (Y/N) ")
- if choice == "y" or choice == "Y":
- play()
- elif choice == "n" or choice == "N":
- sys.exit()
- else:
- print " Wrong input, Please try again.\n"
- play_again()
- def play():
- global user_score, computer_score
- i = 1
- while i <= 3:
- user_c = user_choice()
- computer_c = computer_choice()
- result = compare_choices(user_c, computer_c)
- if result == "user":
- user_score += 1
- print " Your choice was " + user_c + ", the computer's choice was "+ computer_c
- print " You WON ! \n"
- elif result == "computer":
- computer_score += 1
- print " Your choice was " + user_c + ", the computer's choice was "+ computer_c
- print " The computer won. \n"
- else:
- print " Your choice was " + str(user_c) + ", the computer's choice was "+ str(computer_c)
- play_again()
- i += 1
- print "Your score was: "+str(user_score)+", The Computer's score was: "+str(computer_score)
- if user_score > computer_score:
- print "You are the WINNER, CONGRATULATIONS! \n\n"
- else:
- print "The Computer is the WINNER. \n\n"
- play_again()
- user_score = computer_score = 0
- print """
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- + WECLOME TO ROCK, PAPER, SISSORS GAME. +
- + +
- + To test you luck, please choose "r" for Rock, "s" Sissors and "p" for paper.+
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- """
- play()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement