Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

cajubelt Group Title

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?

  • 10 months ago
  • 10 months ago

  • This Question is Open
  1. rsmith6559 Group Title
    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.

    • 10 months ago
  2. latinC Group Title
    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.

    • 9 months ago
  3. johnshipp Group Title
    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! :-)

    • 8 months ago
    • Attachments:

See more questions >>>

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...

23

  • 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.