#!/usr/bin/pythonAnd it gives the results:
import random
print ("Paper, Rock, Scissors, Lizard, Spock")
print ("====================================")
print ("Please choose P(aper), R(ock), S(cissors), L(izard) or (Spoc)K")
player_choice = input()
player_choice = player_choice.upper()
choice_list = ["P", "R", "S", "L", "K"]
computer_choice = random.choice(choice_list)
print ("Player choice is ", player_choice)
print ("Computer choice is ", computer_choice)
if player_choice == "P":
if computer_choice == "P":
print ("Two Papers - Draw!")
elif computer_choice == "R":
print ("Paper covers Rock - Player Wins!")
elif computer_choice == "S":
print ("Scissors cuts Paper - Computer Wins!")
elif computer_choice == "L":
print ("Lizard eats Paper - Computer Wins!")
elif computer_choice == "K":
print ("Paper disproves Spock - Player Wins!")
elif player_choice == "R":
if computer_choice == "P":
print ("Paper covers Rock - Computer Wins!")
elif computer_choice == "R":
print ("Two rocks - Draw!")
elif computer_choice == "S":
print ("Rock blunts Scissors - Player Wins!")
elif computer_choice == "L":
print ("Rock crushes Lizard - Player Wins!")
elif computer_choice == "K":
print ("Spock vapourises Rock - Computer Wins!")
elif player_choice == "S":
if computer_choice == "P":
print ("Sissors cut Paper - Player Wins!")
elif computer_choice == "R":
print ("Rock blunts Scissors - Computer Wins!")
elif computer_choice == "S":
print ("Two Scissors - Draw!")
elif computer_choice == "L":
print ("Scissors decapitates Lizard - Player Wins!")
elif computer_choice == "K":
print ("Spock smashes Scissors - Computer Wins!")
elif player_choice == "L":
if computer_choice == "P":
print ("Lizard eats Paper - Player Wins!")
elif computer_choice == "R":
print ("Rock crushes Lizard - Computer Wins!")
elif computer_choice == "S":
print ("Scissors decapitates Lizard - Computer Wins!")
elif computer_choice == "L":
print ("Two Lizards - Draw!")
elif computer_choice == "K":
print ("Lizard poisons Spock - Player Wins!")
elif player_choice == "K":
if computer_choice == "P":
print ("Paper disproves Spock - Computer wins!")
elif computer_choice == "R":
print ("Spock vapourises Rock - Player Wins!")
elif computer_choice == "S":
print ("Spock smashes Scissors - Player Wins!")
elif computer_choice == "L":
print ("Lizard poisons Spock - Computer Wins!")
elif computer_choice == "K":
print ("Two Spocks - That is illogical! (but still counts as a draw)")
else:
print ("Problem with Player Choice")
RESTART: C:/Users/John/Dropbox/Misc Programming/Python/python3/test06_rockPaperScissors.py
Paper, Rock, Scissors, Lizard, Spock
====================================
Please choose P(aper), R(ock), S(cissors), L(izard) or (Spoc)K
r
Player choice is R
Computer choice is S
Rock blunts Scissors - Player Wins!
>>>
RESTART: C:/Users/John/Dropbox/Misc Programming/Python/python3/test06_rockPaperScissors.py
Paper, Rock, Scissors, Lizard, Spock
====================================
Please choose P(aper), R(ock), S(cissors), L(izard) or (Spoc)K
l
Player choice is L
Computer choice is P
Lizard eats Paper - Player Wins!
>>>
This is not sophisticated - it simply has an if/elif option for each possible combination.
It does introduce the random module - I will discuss importing modules in a later post.
I may come back to this with a more efficient version that does not rely on such long-winded coding. Just as a challenge to any budding Python coders, how would you improve this?
No comments:
Post a Comment