paperjam

rps.py

May 25th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.79 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # Rock Paper Scissors
  3. import random
  4. options = ["Rock","Paper","Scissors"]
  5. outCome = ["WIN","Defeat","Draw"]
  6. results = [[outCome[2],outCome[1],outCome[0]],[outCome[0],outCome[2],outCome[1]],[outCome[1],outCome[0],outCome[2]]]
  7. userScore = 0; cpuScore = 0; noScore = 0; round = 0
  8. msg = "{}:1, {}:2, {}:3 or 0 to Quit. Select your weapon : ".format(options[0],options[1],options[2])
  9. print("Hello! Welcome to {}, {}, {} Game!".format(options[0], options[1], options[2]))
  10. while True:
  11.     try:
  12.         userInput = int(input(msg)) - 1
  13.         if userInput == -1 :
  14.             if userScore > cpuScore :
  15.                 bbmsg = outCome[0] + " the"
  16.             elif userScore < cpuScore :
  17.                 bbmsg = "got " + outCome[1] + "ed by the"
  18.             elif userScore == cpuScore :
  19.                 bbmsg = outCome[2] + "ed with the"
  20.             print("After {} rounds you {} CPU with {}:{} points and {} ties".format(round, bbmsg, userScore, cpuScore, noScore))
  21.             exit(0)
  22.         elif userInput in range(0, 3):
  23.             cpuInput = (random.randrange(1,3)) -1
  24.             round += 1
  25.             print("Round : {} is a {}. You selected {}, while the computer rolled {}".format(round, results[userInput][cpuInput], options[userInput], options[cpuInput]))
  26.             if results[userInput][cpuInput] == outCome[0] :
  27.                 userScore += 1
  28.             elif results[userInput][cpuInput] == outCome[1] :
  29.                 cpuScore += 1
  30.             elif results[userInput][cpuInput] == outCome[2] :
  31.                 noScore += 1
  32.             print("Player:{}. CPU:{}. Draws:{}".format(userScore, cpuScore, noScore))
  33.         else:
  34.             print("Choose again between 0 and 3")
  35.     except ValueError:
  36.         print("Not a valid number. Try again between 0 and 3")
Advertisement
Add Comment
Please, Sign In to add comment