{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 1. [Rock-paper-scissors](https://en.wikipedia.org/wiki/Rock%E2%80%93paper%E2%80%93scissors) \n", "Implement `rock_paper_scissors` function which takes the player's rock-paper-scissors choice as an input (as integer), randomly selects the choice of the computer and reveals it (prints) and finally announces (prints) the result. The function should return `PLAYER_WINS`, `COMPUTER_WINS` or `TIE`." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "editable": false }, "outputs": [], "source": [ "# Constants, you should use these in your implementation\n", "ROCK = 1\n", "PAPER = 2\n", "SCISSORS = 3\n", "\n", "PLAYER_WINS = 'Player wins!! Woop woop!'\n", "COMPUTER_WINS = 'Robocop wins :-('\n", "TIE = \"It's a tie!\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Your implementation here\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Once you have finished the implementation of `rock_paper_scissors` function, you can check if it works as expected by playing the game:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def play_rps():\n", " print('Welcome to play rock-paper-scissors')\n", " print('The options are:\\nrock: 1\\npaper: 2\\nscissors: 3')\n", "\n", " result = TIE\n", " while result == TIE:\n", " player_choice = input('Give your choice\\n')\n", " \n", " if not player_choice in ['1', '2', '3']:\n", " print('Invalid choice')\n", " continue\n", " \n", " result = rock_paper_scissors(int(player_choice))\n", " \n", "if __name__ == '__main__':\n", " play_rps()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you copy the code from above cells into a single .py file, you have a rock-paper-scissor command line game!" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.4" } }, "nbformat": 4, "nbformat_minor": 2 }