I am trying to become a better coder, which includes getting rid of my \'hard-coding\' habits to keep my programs dynamic and easy to maintain.
Right now I am writing a
List is a good idea. In your case validoptions = ["rock", "paper", "scissors"]
you can see, everything beats the only one before it (the "paper"
beats the "rock"
, the "rock"
beats the "scissors"
and the "scissors"
beats the "paper"
. So if you sort it that way, it is solvable with the use of the indexes only. If you want to increase the choices, you can, but tke care, only the odd numbers will provide fair game.
In general if you make a list of options
, with a length of length
, then:
if u1 == u2:
#it is a draw
elif u2input in validoptions[u1 - int((length-1)/2):u1]:
#player1 has won
else:
#player2 has won