Due: Thursday, March 13 at 11:59 pm
Submission: On Courseworks
Please read the instructions carefully. An incorrectly formatted submission may not be counted.
There is one question in this assignment.
This assignment starts from skeleton code called rps_sim.py
.
Please include comments in your code detailing your thought process where appropriate.
Put rps_sim.py
in a folder called uni-hw5
(so for me this would be tkp2108-hw5
).
Then compress this folder into a .zip
file.
For most operating systems, you should be able to right click and have a “compress” option in the context menu.
This should create a file called tkp2108-hw5.zip
(with your uni).
Submit this on courseworks.
Let’s adapt our in-class odds/evens code into an analysis of the game Rock/Paper/Scissors.
You’re given some skeleton code. Expand and adapt the in-class odds/evens code for rock/paper/scissors. Your output should be similar to mine.
Playing Rocks/Paper/Scissors!
Would you like to play a single game (a) or run a simulation (b): a
Pick a choice: ('🪨', '📄', '✂️') (0, 1, 2): 0
User choice:🪨 Computer Choice:✂️
You win!
Would you like to play again? (y/n) y
Would you like to play a single game (a) or run a simulation (b): b
How many simulations? 10000
Played 10000 games.
Player 1 won 3315 times
Player 2 won 3411 times
Players tied 3274 times
Win percentage: 33.15%
Lose percentage: 34.11%
Tie percentage: 32.74%
Would you like to play again? (y/n) n
Your code should:
rps_sim.py
from random import choice
ROCK = "🪨"
PAPER = "📄"
SCISSORS = "✂️"
CHOICES = (ROCK, PAPER, SCISSORS)
def runSimulation():
# TODO
pass
def gameWinner(player_one_choice, player_two_choice):
# TODO
# This is a helper function if you want to use it
pass
def runSingleGame():
# TODO
pass
def main():
print("Playing Rock/Paper/Scissors!")
play_again = "y"
while play_again == "y":
user_choice = input("Would you like to play a single game (a) or run a simulation (b): ")
if user_choice == "a":
runSingleGame()
else:
runSimulation()
play_again = input("Would you like to play again? (y/n) ")
if __name__ == "__main__":
main()