PLAYING THE GAME
At one time or another, most children and adults have enjoyed playing “Rock, Paper, Scissors”. The game involves players simultaneously making hand gestures to form either, rock (fist), paper (flat hand), or scissors (peace sign with the hand placed laterally). Depending upon the gestures made, the popular and simple hand game has two possible outcomes: a draw, or a win for one player and a loss for the other.
History dates the game back to the Chinese Ming-dynasty around 206 BC to 220 AD. It then traveled to Japan where popularity grew. In Japan the game is known as “sansukumi-ken” or “mushi-ken”, and it uses hand gestures to represent a frog, a slug, and a snake.
As stated before, in today’s adaptation of the game, the hand gestures represent rock, paper, or scissors. To win – rock beats scissors, scissors beats paper, and paper beats rock.
This coding project allows the user to play the game against the computer. One can enjoy the game at the bottom of this page.
For the diehard Rock Paper Scissors gamers, the World Rock Paper Scissors Association shares strategies, rules, and tournaments all over the world. Check them out HERE.
So, on the twenty-seventh of August every year, we celebrate the Rock Paper Scissors game all over the world and the day is known as World Rock Paper Scissors Day!
GOING RANDOM
This project represents Day 4 of the #100 Days of Coding Challenge.
Python coding of the “Rock, Paper, Scissors Game” allows for the use of randomization. The random module must be first imported. When the code indicates, the computer picks a random number within a given range.
In this computerized game, the computer chooses a random integer from 0 to 2, but the random module can also allow for multiplying it by a number, choosing it from a sequence, choosing it from a list, shuffling the elements in the list, or generating a randomly selected element from range (start, stop, step).
USING LISTS
Python coding can contain lists. Lists are used to store multiple items in a single variable. List items are ordered, changeable, and allow duplicate values. In addition, list items are indexed. The first item has index [0], the second item has index [1], etc. Other coding languages may refer to this as an array.
The list is one of the most versatile datatypes available in Python. It can be written as a list of comma-separated values (items) between square brackets, and the entries in the list do not need to be of the same type.
This project places the three ASCII Art images into a list. The code prints the corresponding art dependent upon the user’s and computer’s random choices.
COVERING ERRORS
One of the most important aspects of coding programs involves the ability to debug and error check.
Coding errors that crash the program are obvious as the program runs. Logical errors are more difficult to catch.
As “if“, “elif” and “else” statements are carried out, careful consideration and testing need to be conducted to ensure the correct results are calculated. Often these statements need to be nested within one another, complicating the logic even more. Make sure to test your code with various inputs to catch any logical errors!
If for some reason one cannot resolve the Python programming errors, Thonny, a free Python Integrated Development Environment (IDE), is a great debugging tool. It allows one to go line by line to show how the computer executes the written code.
ROCK, PAPER, SCISSORS – DAY 4
ROCK, PAPER, SCISSORS – DAY 4
Enjoy playing the “Rock, Paper, Scissors” game against the Computer. I found this coding challenge a little more difficult than previous coding challenges, but still doable. The most complicated coding logic comprised correctly nesting the “if” statements to execute in the correct order.
This project includes a user error message if the user types a number outside of the requested range of (0,1, or 2). However, the program does crash if the user types a letter or other character.
** Something to fix in future coding projects.
Start click the green button below. To restart the game click the green arrow once again. Good luck!