id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

peter@norvig.com non_word_games > rock_paper_scissors
prev  |  next  |  chance

In the game of rock-paper-scissors, players A and B simultaneously reveal a choice of rock or paper or scissors; rock beats scissors, paper beats rock, and scissors beats paper. It is a tie if both players play the same thing. Write a function rock_paper_scissors(a, b), where a and b are the player's moves, which must be 'rock' or 'paper' or 'scissors', that returns +1 if player A wins, -1 if player A loses, and 0 if it is a tie.


rock_paper_scissors('rock', 'rock') → 0
rock_paper_scissors('rock', 'paper') → -1
rock_paper_scissors('rock', 'scissors') → 1

...Save, Compile, Run (ctrl-enter)

def rock_paper_scissors(a, b):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Difficulty: 202 Post-solution available

Copyright Nick Parlante 2017 - privacy