acclivity

Lizard Spock Extension (of Rock Paper Scissors)

Jan 11th, 2021 (edited)
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. # Rock Paper Scissors with Lizard Spock Extension (but with Wizard in place of Spock)
  2. # By Mike Kerry - Jan 2021  - Email: acclivity2@gmail.com
  3. import random
  4. mydict = {"R": "Rock", "P": "Paper", "S": "Scissors", "L": "Lizard", "W": "Wizard", "Q": "Quit"}
  5. winners = ["RS", "PR", "SP", "LW", "WS", "RL", "SL", "LP", "PW", "WR"]  # winning pairs. Rock beats Scissors etc.
  6. scores = [0,0]                # List for keeping scores
  7. while True:
  8.     comp = random.choice(winners)[0]   # Computer makes a random choice
  9.     while True:
  10.         user = input("=" * 20 + "\nMake your choice, Rock, Paper, Scissors, Lizard or Wizard (initial will do)\ntype Q to quit: ")
  11.         user = user[0].upper()
  12.         if user in mydict:          # Validate user input first letter for R P S L W or Q only
  13.             break
  14.         print("Invalid. Try again")
  15.     if user == "Q":                 # Q = Quit
  16.         break
  17.     print("You chose:", mydict[user], "\nThe computer chose", mydict[comp])
  18.     if comp == user:                # Did the user choose same as computer?
  19.         print("It was a tie!")
  20.     else:
  21.         if comp + user in winners:  # Check for computer winning
  22.             print("You lose!")
  23.             scores[1] += 1          # count 1 computer win
  24.         else:                       # Otherwise user won
  25.             print("You won!")
  26.             scores[0] += 1          # count 1 user win
  27. print("Final scores: (You, computer)", *scores)
  28.  
Add Comment
Please, Sign In to add comment