I am working on exercise 2.1 on homework 2.0. We are being asked to write a function that takes parameters instead of asking for user input for our Rock, Paper, Scissors program. I created the following function but I can't capture the return value and was wondering if you could help function: def p1(x): if x == 'rock' or x == 'scissors' or x == 'paper': return x else: print "still trying" and I call it this way p1('rock') I want to take the results of return x and put that into a variable called player_a and I can't make it work. I feel so dense thi

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.

Get our expert's

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions.

A community for students.

I am working on exercise 2.1 on homework 2.0. We are being asked to write a function that takes parameters instead of asking for user input for our Rock, Paper, Scissors program. I created the following function but I can't capture the return value and was wondering if you could help function: def p1(x): if x == 'rock' or x == 'scissors' or x == 'paper': return x else: print "still trying" and I call it this way p1('rock') I want to take the results of return x and put that into a variable called player_a and I can't make it work. I feel so dense thi

MIT 6.189 A Gentle Introduction to Programming Using Python (OCW)
See more answers at brainly.com
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.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions

Try player_a = p1('rock') But that would just print 'rock'?
yes, I did that and discovered that it does just as you said .. it prints rock regardless of how I call the function.
Well it would print 'paper' if you said: player_a = p1('paper') print player_a Your game of Rock Paper Scissors will need 2 arguments though. Player 1's and Player 2' choice. These 2 need to be compared and the winner decided. def rps(player_1, player_2): #do logic against choices here #return the winner winner = rps('rock', 'paper) print winner Something to that effect. Hope this helps somewhat.

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

it must return a value either way: def f(x): if x == 'rock' or x == 'stone': return x else: return 'not'
Thanks Andrew and Snark. I am going to rethink my approach based on Andrew's comments. I think the problem I am struggling with is the fact that rock, paper or scissors are strings and when I call the function, I call it as rps('rock') or rps('paper'), etc.
you can use random: function: return random(rock,scissor,paper) you can call it this way: function(rand) if that make sense. I hope that was helpful

Not the answer you are looking for?

Search for more explanations.

Ask your own question