A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing


  • 3 years ago

I'm on exercise 2.1 of homework 2 for 6.189, intro to python. I don't know how to turn the rock paper scissors game into a function. I keep getting this error: "name 'rock' is not defined." Can someone give me a hint or an example of a possible solution?

  • This Question is Open
  1. rsmith6559
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    It sounds like rock isn't assigned a value before some code is trying to use rock's value.

  2. latinC
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    the only thing you should have to change is the input into a function, like def game(x,y) and print to return, and then your program should run smooth.

  3. anonymous
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    There are two parts to the Rock, Paper, Scissors code in the unit 1 assignment, part one is about getting user input, part two is about deciding the winner. If you place the 2nd part into a function, you could then call is using something like: def rps(player_1_input, player_2_input): To test your function, you can add test cases like this: print rps('rock','scissors') print rps('paper','paper') print rps('rock','paper') To make it into the "game" again, you would first ask for input from user #1 (rock, paper, or scissors) and the input from user #2 (rock, paper, or scissors)... assigning the input to variables player_1_input and plyaer_2_input respectively in this case. ... then, finally, you would call your function ... print rps(player_1_function, player_2_funciton) ... Don't forget, your function should RETURN the value of "Player 1 wins", "Player 2 wins", or "Tie". Hope this helps! :-)

  4. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...


  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.