Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # Rock Paper Scissors
- import random
- options = ["Rock","Paper","Scissors"]
- outCome = ["WIN","Defeat","Draw"]
- results = [[outCome[2],outCome[1],outCome[0]],[outCome[0],outCome[2],outCome[1]],[outCome[1],outCome[0],outCome[2]]]
- userScore = 0; cpuScore = 0; noScore = 0; round = 0
- msg = "{}:1, {}:2, {}:3 or 0 to Quit. Select your weapon : ".format(options[0],options[1],options[2])
- print("Hello! Welcome to {}, {}, {} Game!".format(options[0], options[1], options[2]))
- while True:
- try:
- userInput = int(input(msg)) - 1
- if userInput == -1 :
- if userScore > cpuScore :
- bbmsg = outCome[0] + " the"
- elif userScore < cpuScore :
- bbmsg = "got " + outCome[1] + "ed by the"
- elif userScore == cpuScore :
- bbmsg = outCome[2] + "ed with the"
- print("After {} rounds you {} CPU with {}:{} points and {} ties".format(round, bbmsg, userScore, cpuScore, noScore))
- exit(0)
- elif userInput in range(0, 3):
- cpuInput = (random.randrange(1,3)) -1
- round += 1
- print("Round : {} is a {}. You selected {}, while the computer rolled {}".format(round, results[userInput][cpuInput], options[userInput], options[cpuInput]))
- if results[userInput][cpuInput] == outCome[0] :
- userScore += 1
- elif results[userInput][cpuInput] == outCome[1] :
- cpuScore += 1
- elif results[userInput][cpuInput] == outCome[2] :
- noScore += 1
- print("Player:{}. CPU:{}. Draws:{}".format(userScore, cpuScore, noScore))
- else:
- print("Choose again between 0 and 3")
- except ValueError:
- print("Not a valid number. Try again between 0 and 3")
Advertisement
Add Comment
Please, Sign In to add comment