# Logan Hoerth / LHoerth@mail.greenriver.edu # Modulus Rock, Paper, Scissors game - 7/15/2015 # This game uses the mod operator (%) to implement a simple solution # to the problem of finding the winner. # (To show Phillip Andrist I'm not crazy (hopefully). # import randint to generate computer's choice from random import randint # Index weapon names... 0: rock, 1: paper, 2: scissors. weapons = ['rock','paper','scissors'] # generate computer's choice. comp = randint(0,2) # Get player's choice (bug in this version: if user picks 0, it's the same as scissors.) print("Please choose thy weapon . . .") print("(1) Rock") print("(2) Paper") print("(3) Scissors") player = input(">") # Display computer's choice print "\nYour opponent chose %s." % weapons[comp] if (player)%3 == comp : print("You have been slain... :-( ") elif (comp+1)%3+1 == player : # (I think this should work...) print("You have slain your opponent! Huzzah!") elif comp+1 == player : print("It's a draw! You must restart the game and rematch! ") else : print("You probably had a slip of the finger. Please re-run the game.") print("Till next time, Goodbye!")
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question