Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.


+4 votes

I don't want to do a bunch of if/elif statements for the outcome of the Rock Paper Scissors game.
Could I do something that says:

if choiceComp or choiceHuman == rock and paper:
     print('Paper covers rock')

Instead of 2-4 if statements for either the computer having rock or paper and the human having either rock or paper?

asked in CSC201 Spring 2021 by (1 point)

I don't know why but it seems like it would be bad coding if you do something like that


Can you be more specific?

3 Answers

+4 votes

This is code refactoring. It is possible to do an 'or' or an 'and' for the if function to reduce the chunk. However, if you want to do the accumulator loop, to find the number of times the human or the computer won, it will be challenging unless you create another if function for specifically that.

Hope that helps,

answered by (1 point)
+4 votes

Yes, there is a way to solve this!

Regarding your choice, I could do:

if ((choiceHuman == 'rock' and choiceComp == 'paper') or (choiceComp == 'rock' and choiceHuman == 'paper')):
        print('Paper covers rock')

The code above worked and printed what you want, however, it is pretty difficult for you to do the accumulator loop and figure out the score of each round.
I think there would be a way to accumulate the score within this code above, but I hvnt found it.

Hope this helps!

answered by (1 point)
+2 votes

\\comment deleted//

answered by (1 point)
edited by