Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

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?

Functions
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Join Brainly to access

this expert answer

SEE EXPERT ANSWER

To see the expert answer you'll need to create a free account at Brainly

It sounds like rock isn't assigned a value before some code is trying to use rock's value.
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.
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! :-)

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

Not the answer you are looking for?

Search for more explanations.

Ask your own question