ROCK PAPER SCISSORS INFINITE

Subscribers:
4,890
Published on ● Video Link: https://www.youtube.com/watch?v=bdHxcv0Xti4



Duration: 5:53
56 views
0


Make a function that selects the winner based on the options that players 1 and 2 select from a list of options.

EXPLANATION CODE:
1) Winner is a Python function that accepts the three parameters choices, p1, and p2 as input. A collection of strings indicating various options makes up the choices argument. The strings in the p1 and p2 arguments reflect the decisions made by two players.
2) The function first determines whether the length of the options array is less than three, in which case it returns 'Draw!'.
3) Next, it divides l-3 by 2 and adds 1, where l is the length of the option list, to determine the number of winning choices for each player. Each player will have an equal amount of winning options thanks to this.
4) Then, using the index technique, it locates the indices of p1 and p2 in the choices list.
5) Using a list comprehension, it then creates two lists of the winning choices for each player by taking the elements that come before their chosen index, up to the number of winning choices calculated earlier.
6) The program then gives the appropriate result string, such as "Player 1 won!," "Player 2 won!," or "Draw!", depending on whether a player's option was among the other player's winning choices.
#codewars #code #wars #python #pythonprogramming #education #tutorial #computerscience #games #puzzles #fundamentals







Tags:
codewars
code
wars
python
python programming
tutorial
step by step
education
computer science
games
puzzles
fundamentals