import Draw Draw.setCanvasSize(1200, 900) Draw.setBackground(Draw.LIGHT_GRAY) Draw.setFontSize(60) Draw.string("MAKE YOUR MOVE!", 260, 50) #make rock, paper, and scissor options def makeBoard(): Draw.setColor(Draw.LIGHT_GRAY) Draw.rect(15, 160, 435, 350) Draw.picture("rock.gif", 20, 170) Draw.rect(450, 160, 370, 350) Draw.picture("paper.gif", 500, 160) Draw.rect(820, 100, 375, 460) Draw.picture("scissors.gif", 800, 90) makeBoard() #determine which option player has chosen def playerChoose(): x = Draw.mouseX() y = Draw.mouseY() if x > 15 and x < 450 and y > 160 and y < 560: return "ROCK" elif x > 450 and x < 820 and y > 160 and y < 510: return "PAPER" elif x > 820 and x < 1195 and y > 100 and y < 560: return "SCISSORS" #determine computer's choice import random #x = random.randint(0, 2) def computerChoose(): if x == 0: return "ROCK" elif x == 1: return "PAPER" else: return "SCISSORS" #determine who wins def winner(): me = playerChoose() computer = computerChoose() if me == computer: return "tie" elif me == "ROCK" and computer == "PAPER" or \ me == "PAPER" and computer == "SCISSORS" or \ me == "SCISSORS" and computer == "ROCK": return "lose" elif me == "PAPER" and computer == "ROCK" or \ me == "SCISSORS" and computer == "PAPER" or \ me == "ROCK" and computer == "SCISSORS": return "win" def choices(): Draw.setColor(Draw.BLACK) Draw.setFontSize(60) Draw.setFontFamily('Courier') Draw.setFontBold(False) Draw.string("Play again!", 240, 50) Draw.string("YOU CHOSE:", 100, 500) Draw.string("COMPUTER CHOSE:", 100, 600) #display what has been chosen def fillChoices(): Draw.setColor(Draw.RED) Draw.setFontBold(True) Draw.string(playerChoose(), 510, 500) Draw.string(computerChoose(), 700, 600) #display outcome def outcome(): outcome = winner() Draw.setFontFamily('Courier') Draw.setFontBold(True) Draw.setColor(Draw.RED) if outcome == "tie": Draw.string("It's a tie!", 340, 700) elif outcome == "lose": Draw.string("You lose. Try again!", 280, 700) elif outcome == "win": Draw.string("Congrats! You win!", 320, 700) game = False while not game: if Draw.mousePressed(): Draw.clear() makeBoard() x = random.randint(0, 2) choices() fillChoices() outcome()
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