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?
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
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.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
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:
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! :-)