Python Program Project

profileeclipse831
HW5P_problem1.ipynb

{ "cells": [ { "cell_type": "markdown", "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "markdown", "checksum": "7b47b6d141b4a60d79c2a115b8a69043", "grade": false, "grade_id": "cell-568582423fb764a7", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "source": [ "# INSTRUCTIONS:\n", "Before you turn this Lab in, make sure everything runs as expected. First, **restart the kernel** (in the menubar, select Kernel$\\rightarrow$Restart) and then **run all cells** (in the menubar, select Cell$\\rightarrow$Run All).\n", "\n", "**TIP**: Open another jupyter notebook to try out your code and experiment with your answers. You can then copy your answer into the Lab notebook for your final submission. This will reduce the chance that your submitted Lab will not be correctly graded.\n", "\n", "Make sure you fill in any place that says `YOUR CODE HERE` or \"YOUR ANSWER HERE\", and follow the instructions carefully.\n", "Also enter your name in the markdown cell below:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "NAME = \"\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "# CS1411-Introduction to Programming with Python\n", "## Homework 5.1" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "**SUBMISSION GUIDELINES**\n", "\n", "1. First design, develop and test your code in a Jupyter notebook or other development environment\n", " - You can expirement and try different things in that notebook\n", "2. Then copy your final code and markdown cells into the Jupyter Notebook file (.ipynb) provided for the assignment and submit to Canvas\n", " - **Your submission file should be named the same as the download file**\n", " - I must be able to open and run your notebook in order to grade it\n", "3. Note that the Jupyter notebook provided for final submission may contain testing code to help you check that your output and expected match. \n", " - Follow the instructions in the notebook for copying your code and running the testing code\n", " - The instructor may run additional tests to check that your code runs correctly\n", "4. If asked, also provide any supporting files or images requested in the assignment\n", "\n", "**GRADING CRITERIA:**\n", "1. Good documentation/comments and program readability using both markdown cells and code comments\n", "2. Algorithm/pseudo-code is explained in a markdown cell and is efficiently written\n", "3. Program runs correctly for test cases with no syntax errors or logical errors\n", "\n", "***The instructor should be able to reproduce your work from your notebook.***" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "3d46f7cb2f3540eeaa5255b5fb22c8b1", "grade": false, "grade_id": "cell-e05854b6a32ee6ea", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "# Run this to check that you have the correct version of Notebook\n", "import IPython\n", "assert IPython.version_info[0] >= 3, \"Your version of IPython is too old, please update it.\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "f14cd89a8c69d76964a68c367a928581", "grade": false, "grade_id": "cell-570ebf38cad6e650", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "\"\"\" Run this setup cell - It is used to keep track of the points per question and set up test environment.\"\"\"\n", "\"\"\" Do not copy/duplicate this cell\"\"\"\n", "num_questions = 5\n", "points = { 1.0: [0,10.0],2.01:[0,5.0],2.02:[0,5.0],2.03:[0,5.0],2.04:[0,5.0],\n", " 3.01:[0, 5.0],3.02:[0,5.0],3.03:[0,5.0],3.04:[0,5.0],3.05:[0,5.0],\n", " 4.01:[0, 5.0],4.02:[0,5.0],4.03:[0,5.0],4.04:[0,5.0],4.05:[0,5.0],4.06:[0,5.0],4.07:[0,5.0],\n", " 5.0 :[0,10.0]\n", " }\n", "print(f\"Number of Questions = {num_questions}\")\n", "print(f\"***** TOTAL POINTS = {sum([value[1] for value in points.values()])}*****\")\n", "\n", "# # For instructor use in setting up test environment\n", "# class input_vars:\n", "# input_list = []\n", "# L_input = input_vars()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "562c66d73a448e8812b7848aaa22a4f8", "grade": true, "grade_id": "Instructor_test_setup", "locked": true, "points": 0, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "\"\"\" This cell has the instructors test setup and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] }, { "attachments": { "image.png": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAw0AAADQCAYAAABFqY2MAAAgAElEQVR4Ae2dX6htV3WHz4P4B/NwE0SpYAwGRELEXLzqi0oChUhNaawPeREbE0RC+xDyYGmgEBJRIi1XhEhE8NIHScGSFCRN+mDSetWEaL2pUTFNk9s0KikmTahaCy2s8ltn/84ZZ2atueeee6919lr7m7Az15p/xhzjG2PNNcfZ++peQ4EABCAAAQhAAAIQgAAEIJAhsJfpowsCEIAABCAAAQhAAAIQgEBD0kAQQAACEIAABCAAAQhAAAJZAiQNWTx0QgACEIAABCAAAQhAAAIkDcQABCAAAQhAAAIQgAAEIJAlQNKQxUMnBCAAAQhAAAIQgAAEIEDSQAxAAAIQgAAEIAABCEAAAlkCJA1ZPHRCAAIQgAAEIAABCEAAAiQNxAAEIAABCEAAAhCAAAQgkCVA0pDFQycEIAABCEAAAhCAAAQgQNJADEAAAhCAAAQgAAEIQAACWQIkDVk8dEIAAhCAAAQgAAEIQAACJA3EAAQgAAEIQAACEIAABCCQJUDSkMVDJwQgAAEIQAACEIAABCBA0kAMQAACEIAABCAAAQhAAAJZAiQNWTx0QgACEIAABCAAAQhAAAIkDcQABCAAAQhAAAIQgAAEIJAlQNKQxUMnBCAAAQhAAAIQgAAEIEDSQAxAAAIQgAAEIAABCEAAAlkCJA1ZPHRCAAIQgAAEIAABCEAAAiQNxAAEIAABCEAAAhCAAAQgkCVA0pDFQycEIAABCEAAAhCAAAQgQNJADEAAAhCAAAQgAAEIQAACWQIkDVk8dEIAAhCAAAQgAAEIQAACJA3EAAQgAAEIQAACEIAABCCQJUDSkMVDJwQgAAEIQAACEIAABCBA0kAMQAACEIAABCAAAQhAAAJZAiQNWTx0QgACEIAABCAAAQhAAAIkDcQABCAAAQhAAAIQgAAEIJAlQNKQxUMnBCAAAQhAAAIQgAAEIEDSQAxAAAIQgAAEIAABCEAA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y3veDgS/yFiQTLl38cee2zuWNe2zy9x+6VEYO3LoUS2xgwtv1QPxi0n4ANKe2h56aWjE0a8f+SRR5ovffaz7XN/oMSI67dr7tB658+fb3lrX3cx/4MD7AZ5KKGS/O9+97termk2KH8W/gt/zNVzOXap3bc3kzScPn0YEOfONc2VV279/Y++/e3myiuvbL73la80506caM5+4xtH7n/66KP7Pqyw51enTr1CXir/1z/7WbX8TfB95IEHjthr/X7w1a82//v+97f+02aijPuUA/rmmw/jWj6/9trR7h/80IeaR3/ndw4Smmbk9bvW+/l739s8/PDD7YvP+sX777/lLaPx6dKv1j/PPPNMI3tkn8v3P/axlv+zzz6737RB/nqRab0XPvABL9esY48SkC5/KH7kn/ZFtkH9W6VHkHf261/ffx47/np3CO6VV7Uvh1dK6m7plf/ww01z5sz+JB0YtF9s2f1zd9zRPr9fu+uuNr7P3njjkftHPvWprdZ/JZ6nTx9886q/LreHOMWtivyj/X2k+1/85CfN3192WfMPfoeMvH6fvf/8iU+0/teB1/ppP/H9jz/5yWPh1advqb9+8NBDrT0v33bbgf62T/v9uvLjfH3zY16//dznDtarjS/pZ3mKl+gP3//yqadGjd9ob2tgTfzedtvR53Gf1Gj/7d23l2iwmaTBB2u9JJQwTKB+8s1vbs6dPt2cfdWrmiv39prvXXDBkfunL7642o4ffvGLr5CXyv+NDmTHyEnrnz9z5sB+JU66//V73nNEr6svuujwK1LrqxeLNp/77tv39wj3p0+caK7d22v++33v23+xjbx+l733fvzjbcKpjetzr31tq584+v5jF1wwGp8u/Wr9oxfjGX2VHvz7tydPtvb98vLLN8pfCbZ4yb9xvXXsMX/FS/SH73/x6U+PHr/r2NMeDG67rbn1llvaZ9G/p1+ytx90174cDgQsucjKv/76/XhRrXjasvsfvvvdbfx98+KL2/g+s7d35P5rr371Vuu/Kk8d6PRt1cHPP5woqFZCN9L9f914Y3P93l7zpde8Zp/vyOu3dnbYe+9b39r6Xwdq6Xd6EQ++v//tb98qfUv99dC73tX8zTXXHPHvH7/+9a19v7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AQgAIEyArX7NklDGV9GQQACEJgkgdqXQ6mxQ8sv1YNxEIAABCBQRqB23yZpKOPLKAhAAAKTJFD7cig1dmj5pXowDgIQgAAEygjU7tskDWV8GQUBCEBgkgRqXw6lxg4tv1QPxkEAAhCAQBmB2n2bpKGML6MgAAEITJJA7cuh1Nih5ZfqwTgIQAACECgjULtvkzSU8WUUBCAAgUkSqH05lBo7tPxSPRgHAQhAAAJlBGr37ZWTBi3EBwbEADFADEwnBspeI3WjiIPpxAG+wlfEADHgGKjZ8VdKGmoWYA4EIAABCEAAAhCAAAQgMG0CJA3T9h/aQwACEIAABCAAAQhAYHACJA2DI2YBCEAAAhCAAAQgAAEITJsAScO0/Yf2EIAABCAAAQhAAAIQGJwAScPgiFkAAhCAAAQgAAEIQAAC0yZA0jBt/6E9BCAAAQhAAAIQgAAEBidA0jA4YhaAAAQgAAEIQAACEIDAtAmQNEzbf2gPAQhAAAIQgAAEIACBwQmQNAyOmAUgAAEIQAACEIAABCAwbQIkDdP2H9pDAAIQgAAEIAABCEBgcAIkDYMjZgEIQAACEIAABCAAAQhMmwBJw7T9h/YQgAAEIAABCEAAAhAYnABJw+CIWQACEIAABCAAAQhAAALTJkDSMG3/oT0EIAABCEAAAhCAAAQGJ0DSMDhiFoAABCAAAQhAAAIQgMC0CZA0TNt/aA8BCEAAAhCAAAQgAIHBCfw/gbOMT7ZsU9gAAAAASUVORK5CYII=" } }, "cell_type": "markdown", "metadata": {}, "source": [ "### Problem 1: Rock, Paper, Scissors Game\n", "\n", "Write a program ```play_game()``` that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows:\n", "\n", "1. Set up global constants, as follows, to make the program more readable:\n", "```\n", "ROCK = 1\n", "PAPER = 2\n", "SCISSORS = 3\n", "\n", "TIE = 0\n", "COMPUTER_WINS = 1\n", "PLAYER_WINS = 2\n", "INVALID = 3\n", "```\n", "\n", "2. When the program begins, a random integer in the range of 1 through 3 is generated. If the number is ROCK, then the computer has chosen rock. If the number is PAPER, then the computer has chosen paper. If the number is SCISSORS, then the computer has chosen scissors. (Don't display the computer's choice yet.) \n", "\n", "3. The user enters his or her choice of 1 (\"rock,\"), 2 (\"paper\"), or 3 (\"scissors\") at the keyboard. Use an input validation loop to check that the input is valid i.e. 1,2, or 3.\n", "\n", "Write and use, in ```play_game()```, a function ```choice_to_string(computer_choice,player_choice)``` that converts the choice as an integer into a string the computer can use. For example if the choice is ROCK then the function should return ```\"rock\"```, PAPER returns ```\"paper\"```, SCISSORS returns ```\"scissors\"``` and anything else returns ```\"something went wrong\"```\n", "\n", "4. The computer's choice is displayed. The player's choice is displayed. \n", "\n", "5. A winner is selected according to the following rules: \n", "\n", "- If one player chooses ROCK and the other player chooses SCISSORS, then ROCK wins. (Rock smashes scissors.) \n", "- If one player chooses SCISSORS and the other player chooses PAPER, then SCISSORS wins. (Scissors cuts paper. ) \n", "- If one player chooses PAPER and the other player chooses ROCK, then PAPER wins. (Paper wraps rock. ) \n", "- If both players make the same choice, then there is a TIE and game must be played again to determine the winner.\n", "\n", "Write and use, in ```play_game()```, a function ```select_winner(computer_choice,player_choice)``` to select the winner of the computer's choice and player's choice according to the game rules. The ```select_winner``` function receives integers representing the computer and player's choices. It returns TIE if there is a tie, COMPUTER_WINS if the computer won, PLAYER_WINS if the player won, or INVALID if the player choice is an invalid choice (i.e. not ROCK, PAPER, or SCISSORS). The function ```play_game()``` returns the result of the game (i.e. PLAYER_WINS, or COMPUTER_WINS).\n", "\n", "Test your functions by matching the expected output for the given inputs exactly. See the notebook for the tests (the instructor may run additional and/or different scenarios to test your code): \n", "\n", "A sample input and print output from the game, for valid user inputs (1,2 or 3) returns PLAYER_WINS and would look as follows (since the game is random you may get different outputs as you play the game):\n", "```\n", "Enter 1 for rock, 2 for paper, 3 for scissors: 1\n", " Computer chose: rock\n", " You chose : rock\n", " TIE: Starting over\n", "Enter 1 for rock, 2 for paper, 3 for scissors: 1\n", " Computer chose: scissors\n", " You chose : rock\n", " PLAYER WINS GAME\n", "```\n", "A sample input and print output from the game,for invalid user input of 4 returns COMPUTER_WINS and would look as follows (since the game is random you may get different outputs as you play the game):\n", "```\n", "Enter 1 for rock, 2 for paper, 3 for scissors: 4\n", "INVALID INPUT\n", "Enter 1 for rock, 2 for paper, 3 for scissors: 1\n", " Computer chose: paper\n", " You chose : rock\n", " COMPUTER WINS GAME\n", "```\n", "\n", "### Hierarchy Chart\n", "![image.png](attachment:image.png)\n", "\n", "**NOTE: SOME THINGS I WILL BE LOOKING FOR:**\n", "\n", "I am expecting to see a summary of your **algorithm steps** in the markdown cell, a **play_game() function** that that has a **while loop to check and continue if there is a tie**, a **while loop to validate the player's input**, calls to the **choice_to_string() and select_winner() functions**, **use of global constants** to improve readability of your code, use of the **randint() function**, **output that matches the expected output**, **play_game() returns a result** that matches the expected return for multiple test cases of the game. And, of course, efficient, well-written, readable code." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Points: 10 - Algorithm" ] }, { "cell_type": "markdown", "metadata": { "jp-MarkdownHeadingCollapsed": true, "tags": [] }, "source": [ "### Q1.0 [Don't Delete!] - Enter your Algorithm steps below\n", "### My Algorithm Steps\n", "\n", "1. ...\n", "2. ...\n", "3. ..." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [], "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "10ed25fa763708aaf71f17bb411b9b48", "grade": true, "grade_id": "Q1_test", "locked": true, "points": 10, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "#\"\"\" This cell has the instructors test and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [] }, "outputs": [], "source": [ "#############################################\n", "# GLOBAL CONSTANTS - DON'T DELETE THIS CELL #\n", "#############################################\n", "ROCK = 1\n", "PAPER = 2\n", "SCISSORS = 3\n", "\n", "TIE = 0\n", "COMPUTER_WINS = 1\n", "PLAYER_WINS = 2\n", "INVALID = 3" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "### Points: 20 - choice_to_string() function\n", "\n", "Q2 Write and test the ```choice_to_string(choice)``` function as indicated in the instructions above.\n", "\n", "(**DO NOT split your solution across cells**. Your complete code should be in the indicated answer cell)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [], "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "d035ea7ce502ea9b045c029db148d69c", "grade": false, "grade_id": "Q2_answer", "locked": false, "schema_version": 3, "solution": true, "task": false }, "tags": [] }, "outputs": [], "source": [ "#Q2 [DO NOT DELETE!]\n", "\n", "# YOUR CODE HERE\n", "raise NotImplementedError()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [] }, "outputs": [], "source": [ "# test for your answer - Try ROCK, PAPER, SCISSORS, and something else, e.g. 4 to check your function\n", "# TEST CODE HERE\n", "assert choice_to_string(ROCK) == 'rock', \"Error: wrong result, expecting 'rock'\"\n", "assert choice_to_string(PAPER) == 'paper', \"Error: wrong result, expecting 'paper'\"\n", "assert choice_to_string(SCISSORS) == 'scissors', \"Error: wrong result, expecting 'scissors'\"\n", "assert choice_to_string(4) == 'something went wrong', \"Error: wrong result, expecting 'something went wrong'\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [] }, "outputs": [], "source": [ "# Instructor Tests\n", "# Check choice_to_string function returns all the correct results" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [], "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "c6511a26d4bb79609e0826bda3f47f50", "grade": true, "grade_id": "Q2_test_1", "locked": true, "points": 5, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "#\"\"\" This cell has the instructors test and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [], "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "afef0efb913a27f1bf7f3c68eb19365b", "grade": true, "grade_id": "Q2_test_2", "locked": true, "points": 5, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "#\"\"\" This cell has the instructors test and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [], "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "abb09edf142accb58468f003fcbc1a79", "grade": true, "grade_id": "Q2_test_3", "locked": true, "points": 5, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "#\"\"\" This cell has the instructors test and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [], "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "b92ba4c0bf413fa94be69d0a54fd8249", "grade": true, "grade_id": "Q2_test_4", "locked": true, "points": 5, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "#\"\"\" This cell has the instructors test and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [], "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "7be95e05704f9bceb9c4432e052ae3d8", "grade": true, "grade_id": "Q2_test_summary", "locked": true, "points": 0, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "#\"\"\" This cell has the instructors test and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "### Points: 25 - select_winner() function\n", "\n", "Q3 Write and test the ```select_winner(computer_choice, player_choice)``` function as indicated in the instructions above.\n", "\n", "(**DO NOT split your solution across cells**. Your complete code should be in the indicated answer cell)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [], "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "e72711f69e811c916abcdebdd6aa2337", "grade": false, "grade_id": "Q3_answer", "locked": false, "schema_version": 3, "solution": true, "task": false }, "tags": [] }, "outputs": [], "source": [ "#Q3 [DO NOT DELETE!]\n", "\n", "##########################################################################################\n", "# The select_winner function receives numbers representing the\n", "# computer and player's choices.\n", "# It returns TIE if there is a tie, COMPUTER_WINS if the computer won, PLAYER_WINS if the \n", "# player won, or INVALID if the player made an invalid choice.\n", "##########################################################################################\n", "\n", "# YOUR CODE HERE\n", "raise NotImplementedError()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [] }, "outputs": [], "source": [ "# test for your answer - Try ROCK, PAPER, SCISSORS, and something else to check your function\n", "# YOUR CODE HERE\n", "assert select_winner(computer_choice=ROCK,player_choice=ROCK) == TIE, \"Error: expected TIE\"\n", "assert select_winner(computer_choice=ROCK,player_choice=SCISSORS) == COMPUTER_WINS, \"Error: expected COMPUTER_WINS\"\n", "assert select_winner(computer_choice=ROCK,player_choice=PAPER) == PLAYER_WINS, \"Error: expected PLAYER_WINS\"\n", "assert select_winner(computer_choice=ROCK,player_choice=4) == INVALID, \"Error: expected INVALID\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [] }, "outputs": [], "source": [ "# Instructor Tests\n", "# Check all select_winner(computer,player) assertion scenarios (more than four above)\n", "# Check using if-else or elif for decision logic" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [], "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "6f1ecdd410c06634adbb4130c87922cc", "grade": true, "grade_id": "Q3_test_1", "locked": true, "points": 5, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "#\"\"\" This cell has the instructors test and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [], "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "4faabb8758612a1d8a555e3a2e3f6b21", "grade": true, "grade_id": "Q3_test_2", "locked": true, "points": 5, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "#\"\"\" This cell has the instructors test and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [], "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "8a824d42f6c01d43c4c9f2fd3206c063", "grade": true, "grade_id": "Q3_test_3", "locked": true, "points": 5, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "#\"\"\" This cell has the instructors test and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [], "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "5d933b637010882f5f6f4d30c6e5fde0", "grade": true, "grade_id": "Q3_test_4", "locked": true, "points": 5, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "#\"\"\" This cell has the instructors test and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [], "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "25102d99de22849905ea883c651eaeb5", "grade": true, "grade_id": "Q3_test_5", "locked": true, "points": 5, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "#\"\"\" This cell has the instructors test and is hidden\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [], "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "cb45d18cb55a4a9531337273d624b1dc", "grade": true, "grade_id": "Q3_test_summary", "locked": true, "points": 0, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "#\"\"\" This cell has the instructors test and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "### Points: 35 - play_game() function\n", "\n", "Q4. Write and test the ```play_game()``` function as indicated in the instructions above.\n", "\n", "(**DO NOT split your solution across cells**. Your complete code should be in the indicated answer cell)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "9f05837f37401cb8dfd4806210c98b40", "grade": false, "grade_id": "Q4_answer", "locked": false, "schema_version": 3, "solution": true, "task": false }, "tags": [] }, "outputs": [], "source": [ "#Q4 [DO NOT DELETE!]\n", "\n", "#######################################################################################################################\n", "# The play_game() function continues to play while there is a TIE. It generates a random integer from 1 to 3 and makes\n", "# this the computer_choice. It then prompts the user to enter a choice of ROCK, PAPER, or SCISSORS. The users input\n", "# is validated using an input validation loop before continuing. \n", "# It then displays the computer's choice and the player's choice and uses the choice_to_string() function to \n", "# convert the choice number to the selection string (\"rock\",\"paper\",\"scissors\", or \"something went wrong\").\n", "#\n", "# The select_winner() function is then used to determine whether there is a TIE, COMPUTER_WINS, or PLAYER_WINS. As \n", "# long as result equals a TIE the game continues (use a while loop). \n", "#\n", "# Once there is a winner display the winner. The function returns an integer that has the result of the game which \n", "# will be one of COMPUTER_WINS, PLAYER_WINS, or INVALID.\n", "#######################################################################################################################\n", "def play_game():\n", " import random\n", "\n", "# YOUR CODE HERE\n", "raise NotImplementedError()\n", " \n", " return result" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# test for your answer - Try ROCK, PAPER, SCISSORS (Valid input) to check your function\n", "#L.input_list = [2,1,1,1,1,1]\n", "# YOUR CODE HERE\n", "import random\n", "random.seed(None)\n", "result = play_game()\n", "print(f'Result = {result}')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [] }, "outputs": [], "source": [ "# Instructor Tests\n", "# Check input string looks correct\n", "# check using while loop\n", "# check using random.randint()\n", "# Check calling choice_to_string()\n", "# Check calling select_winner()\n", "# Check output matches exactly for given user inputs (set seed to 1) and returned result matches scenario\n", "# Check output matches exactly for invalid user input (set seed to 1) and returned result matches scenario\n", "# Check style, readability, efficiency" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "53918aaaf2db8b3b8e21a5a26ee81f98", "grade": true, "grade_id": "Q4_test_1", "locked": true, "points": 5, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "#\"\"\" This cell has the instructors test and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "24b840b3f707a80dec5686fcbb38e8ce", "grade": true, "grade_id": "Q4_test_2", "locked": true, "points": 5, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "#\"\"\" This cell has the instructors test and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "01d7a98604767ba85b395ce87cfdf4c9", "grade": true, "grade_id": "Q4_test_3", "locked": true, "points": 5, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "#\"\"\" This cell has the instructors test and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "5654951d5756379cd44e925c7c7e259d", "grade": true, "grade_id": "Q4_test_4", "locked": true, "points": 5, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "#\"\"\" This cell has the instructors test and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "5f899577c453de5b8ac9f7bf599ddb40", "grade": true, "grade_id": "Q4_test_5", "locked": true, "points": 5, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "#\"\"\" This cell has the instructors test and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "13a0267c94625470cc941cc05a0bd0c7", "grade": true, "grade_id": "Q4_test_6", "locked": true, "points": 5, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "#\"\"\" This cell has the instructors test and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "f880c1e6755c76bcf5d5c7de7d71a460", "grade": true, "grade_id": "Q4_test_7", "locked": true, "points": 5, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "#\"\"\" This cell has the instructors test and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [], "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "64cd8b016b08be90c3a4c14ed0aa5947", "grade": true, "grade_id": "Q4_test_summary", "locked": true, "points": 0, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "#\"\"\" This cell has the instructors test and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] }, { "cell_type": "markdown", "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "markdown", "checksum": "26c6bf589229cfff53ce7f1df6ae7ef5", "grade": false, "grade_id": "Q3_style_check", "locked": true, "points": 10, "schema_version": 3, "solution": false, "task": true }, "tags": [] }, "source": [ "### Points: 10 - Style\n", "Q5. Manually graded. Is code well written, readable?" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [ 0 ], "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "e7f372ee0ffb63bbdc7fc03c94be8ade", "grade": true, "grade_id": "Q3_style_test", "locked": true, "points": 0, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "\"\"\" This cell has the instructors test and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "861b7f37d8e18e9c2c972896561a93b1", "grade": true, "grade_id": "Summary_points", "locked": true, "points": 0, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "\"\"\" This cell has the instructors test and is hidden - DO NOT copy/duplicate this cell\"\"\"" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.11.4" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "oldHeight": 122.85, "position": { "height": "174.85px", "left": "888.08px", "right": "20px", "top": "116px", "width": "225.72px" }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "varInspector_section_display": "block", "window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }