Created
September 22, 2014 01:47
-
-
Save kd-harris/165305df32504df07c31 to your computer and use it in GitHub Desktop.
A rock, paper, scissors-type game in Python.
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
import random | |
valid_choices = ['rock','paper','scissors','lizard','spock'] | |
def main(): | |
print ("Let's play a game - rock, paper, scissors, Spock, or lizard! Enter Y to play or N to quit.") | |
choice = input("Y/N?: ").upper() | |
if choice == 'Y': | |
game() | |
elif choice == "N": | |
exit() | |
else: | |
exit() | |
def game(): | |
your_choice = input("Choose rock, paper, scissors, Spock, or lizard!: ").lower() | |
if your_choice in valid_choices: | |
choice_dict = {1:'rock', 2:'paper', 3:'scissors',4:'spock', 5:'lizard'} | |
computer_num = random.randrange(1,6) | |
computer_choice = choice_dict[computer_num] | |
print ("Computer chose", computer_choice) | |
if your_choice == computer_choice: | |
print ("Tie!") | |
game() | |
if your_choice == 'rock' and computer_choice == 'paper': | |
print ("You lose - paper covers the rock!") | |
main() | |
if your_choice == 'rock' and computer_choice == 'scissors': | |
print("You win - rock smashes the scissors!") | |
main() | |
if your_choice == 'rock' and computer_choice == 'spock': | |
print("You lose - Spock vaporizes the rock!") | |
main() | |
if your_choice == 'rock' and computer_choice == 'lizard': | |
print("You win - rock smashes the lizard!") | |
main() | |
if your_choice == 'paper' and computer_choice == 'rock': | |
print("You win - paper covers the rock!") | |
main() | |
if your_choice == 'paper' and computer_choice == 'scissors': | |
print("You lose - scissors cut the paper!") | |
main() | |
if your_choice == 'paper' and computer_choice == 'spock': | |
print("You win - paper disproves Spock!") | |
main() | |
if your_choice == 'paper' and computer_choice == 'lizard': | |
print("You lose - lizard eats the paper!") | |
main() | |
if your_choice == 'scissors' and computer_choice == 'rock': | |
print("You lose - rock smashes the scissors!") | |
main() | |
if your_choice == 'scissors' and computer_choice == 'paper': | |
print("You win - scissors cut the paper!") | |
main() | |
if your_choice == 'scissors' and computer_choice == 'spock': | |
print("You lose - Spock smashes the scissors!") | |
main() | |
if your_choice == 'scissors' and computer_choice == 'lizard': | |
print("You win - scissors decapitate the lizard!") | |
main() | |
if your_choice == 'spock' and computer_choice == 'rock': | |
print("You win - Spock vaporizes the rock!") | |
main() | |
if your_choice == 'spock' and computer_choice == 'paper': | |
print("You lose - paper disproves Spock!") | |
main() | |
if your_choice == 'spock' and computer_choice == 'scissors': | |
print("You win - Spock smashes the scissors!") | |
main() | |
if your_choice == 'spock' and computer_choice == 'lizard': | |
print("You lose - the lizard poisons Spock!") | |
main() | |
if your_choice == 'lizard' and computer_choice == 'rock': | |
print("You lose - rock crushes the lizard!") | |
main() | |
if your_choice == 'lizard' and computer_choice == 'paper': | |
print("You win - lizard eats the paper!") | |
main() | |
if your_choice == 'lizard' and computer_choice == 'scissors': | |
print("You lose - scissors decapitate the lizard!") | |
main() | |
if your_choice == 'lizard' and computer_choice == 'spock': | |
print("You win - lizard poisons Spock!") | |
main() | |
else: | |
print ("Sorry, that is not a valid choice!") | |
main() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment