Created
July 9, 2018 22:50
-
-
Save 3rdAnimal/eb0adaa1c198ebc68484620219b3426b to your computer and use it in GitHub Desktop.
practicepython.org: Rock Paper Scissors
This file contains hidden or 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
en_us_winning = [ | |
"Rock OBLITERATES scissors!", | |
"Paper SMOTHERS rock!", | |
"Scissors EVISCERATES paper!" | |
] | |
en_us = [ | |
"Rock, Paper, or Scissors?", | |
"Player", | |
"Enter choice", | |
"Invalid choice.", | |
"Tie game.", | |
"Player 1 is the winner.", | |
"Player 2 wins.", | |
"Quiting", | |
] | |
choices = { | |
'q' : -1, | |
'r' : 0, | |
'p' : 1, | |
's' : 2 | |
} | |
def calcWinner(p1,p2): | |
return (p1 - p2) % 3 | |
def entryRequest(num): | |
choice = input( "\n\n{0} {1}\n{2}\n{3}: ".format( en_us[1], num, en_us[0], en_us[2] ) ) [0].lower() | |
valid = False | |
while not valid: | |
if not choice in choices : | |
choice = input( "\n\n{4}\n{0} {1}\n{2}\n{3}: ".format( en_us[1], num, en_us[0], en_us[2], en_us[3] ) ) [0].lower() | |
valid = False | |
valid = True | |
return choices[choice] | |
while True : | |
p1 = entryRequest(1) | |
if p1 == -1: | |
print( "{0}...".format( en_us[7] ) ) | |
break | |
print ("\n" * 100) | |
p2 = entryRequest(2) | |
if p2 == -1: break | |
result = calcWinner(p1,p2) | |
if result == 0 : print ( "\n{0}\n".format( en_us[4] ) ) | |
if result == 1 : | |
print ( "\n{0}".format( en_us_winning[p1] ) ) | |
print ( "{0}".format( en_us[5] ) ) | |
if result == 2 : | |
print ( "\n{0}".format( en_us_winning[p2] ) ) | |
print ( "{0}".format( en_us[6] ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment