Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Rock, Paper, or Scissors project. The user can insert a choice, and, in return the compute will display a random choice.
- """
- from random import randint
- from time import sleep
- options = ["R", "P", "S"]
- LOSS_MESSAGE = "You lost!"
- WIN_MESSAGE = "Yay....You won!"
- def decide_winner(user_choice, computer_choice):
- print "You selected: %s" % user_choice # check
- sleep (1)
- print "computer selected: %s" % computer_choice # check
- sleep (1)
- user_choice_index = options.index(user_choice)
- computer_choice_index = options.index(computer_choice)
- if user_choice_index == computer_choice_index:
- print "It is a tie!"
- elif user_choice_index == 0 and computer_choice_index==2:
- print WIN_MESSAGE
- elif user_choice_index == 1 and computer_choice_index==0:
- print WIN_MESSAGE
- elif user_choice_index == 2 and computer_choice_index==1:
- print WIN_MESSAGE
- elif user_choice_index > 2:
- print "Invalid choice"
- return #check
- else:
- print LOSS_MESSAGE
- def play_RPS():
- print "Rock, Paper, or Scissors?"
- user_choice = raw_input ("select R for Rock, P for Paper, or S for Scissors: ")
- spleep (1)
- user_choice = user_choice.upper()
- computer_choice = options[randint(0,len(options)-1)]
- decide_winner(user_choice, computer_choice)
- play_RPS()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement