-
-
Save codecademydev/e82093013e59cf7cac36d47e096edd06 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains 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
"""This program will simulate a game of rock paper scissors""" | |
from random import randint | |
from time import sleep | |
options = ["R", "P", "S"] | |
loss = "You lost!" | |
win = "Congratulations, you win!" | |
def decide_winner(user_choice, computer_choice): | |
print "You selected %s" % user_choice | |
print "Computer selecting..." | |
sleep(1) | |
print "The computer selected %s" % computer_choice | |
user_choice_index = options.index(user_choice) | |
computer_choice_index = options.index(computer_choice) | |
if user_choice_index == computer_choice_index: | |
print"It's a tie!" | |
elif user_choice_index == 0 and computer_choice_index == 2: | |
print win | |
elif user_choice_index == 1 and computer_choice_index == 0: | |
print win | |
elif user_choice_index == 2 and computer_choice_index == 1: | |
print win | |
elif user_choice_index > 2: | |
print"Invalid selection" | |
return | |
else: | |
print loss | |
def play_RPS(): | |
print"Rock, Paper, or Scissors" | |
user_choice = raw_input("Select R for rock, P for paper, or S for scissors") | |
sleep(1) | |
user_choice = user_choice.upper | |
computer_choice = options[randint(0,len(options)-1)] | |
decide_winner(user_choice,computer_choice) | |
play_RPS() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment