ROCK PAPER SCISSORS INFINITE
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
Other Videos By One Person Studio
2023-02-15 | SIMPLY SQUARE |
2023-02-14 | PIKACHU #shorts #art #drawing |
2023-02-13 | SHIZUKA #shorts #art #drawing |
2023-02-13 | GON #shorts #art #drawing |
2023-02-13 | ARIANA GRANDE #shorts #art #drawing |
2023-02-12 | NICOLE WATTERSON #shorts #art #drawing |
2023-02-12 | PYTHON TURTLE: GOOGLE CHROME LOGO |
2023-02-11 | TRAINING ON THE CULLING OF STRATHOLME |
2023-02-11 | TWEETY BIRD #shorts #art #drawing |
2023-02-11 | HULK #shorts #art #drawing |
2023-02-11 | ROCK PAPER SCISSORS INFINITE |
2023-02-10 | THE ELECTRICIAN APPRENTICE |
2023-02-10 | AMONG US XVII #shorts #art #drawing |
2023-02-10 | 1000000000D WORLD |
2023-02-09 | A TERRIBLE DREAM, NOTHING MORE |
2023-02-08 | SHIKAMARU NARA #shorts #art #drawing |
2023-02-07 | PYTHON TURTLE: CAPTAIN AMERICA SHIELD |
2023-02-07 | SKETCHBOOK TOUR PART LXXXIV #shorts #art #drawing |
2023-02-06 | LET'S PLAY DARTS! |
2023-02-06 | MR P ICON FROM BRAWL STARS #shorts #art #drawing |
2023-02-06 | YAHTZEE UPPER SECTION |