From 356038c6fbb25ac20e13759958f4c10a1b5664a7 Mon Sep 17 00:00:00 2001 From: SUNIDHI PANDEY <65342463+sunidhi2001@users.noreply.github.com> Date: Sat, 30 Oct 2021 20:43:39 +0530 Subject: [PATCH] Password Capstone Project --- Password Project.ipynb | 143 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 Password Project.ipynb diff --git a/Password Project.ipynb b/Password Project.ipynb new file mode 100644 index 0000000..a16dc11 --- /dev/null +++ b/Password Project.ipynb @@ -0,0 +1,143 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Password Project Code" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The Colours are: (r)ed, (b)lue, (o)ange, (y)ellow, (p)ink, (g)reen, (w)hite.\n", + "Enter your choice for Place 1: b\n", + "Enter your choice for Place 2: b\n", + "Enter your choice for Place 3: b\n", + "Enter your choice for Place 4: b\n", + "Correct Colour in the correct place: 0\n", + "Correct Colour but in the wrong place: 0\n", + "\n", + "The Colours are: (r)ed, (b)lue, (o)ange, (y)ellow, (p)ink, (g)reen, (w)hite.\n" + ] + } + ], + "source": [ + "import random\n", + "def select_col():\n", + " colours = [\"r\",\"b\",\"o\",\"y\",\"p\",\"g\",\"w\"]\n", + " c1 = random.choice(colours)\n", + " c2 = random.choice(colours)\n", + " c3 = random.choice(colours)\n", + " c4 = random.choice(colours)\n", + " data = (c1,c2,c3,c4)\n", + " return data\n", + "def tryit(c1,c2,c3,c4):\n", + " print(\"The Colours are: (r)ed, (b)lue, (o)ange, (y)ellow, (p)ink, (g)reen, (w)hite.\")\n", + " try_again = True\n", + " while try_again == True:\n", + " u1 = input(\"Enter your choice for Place 1: \")\n", + " u1 = u1.lower()\n", + " if u1 != \"r\" and u1 != \"b\" and u1 != \"o\" and u1 != \"y\" and u1 != \"p\" and u1 != \"g\" and u1 != \"w\":\n", + " print(\"Incorrect Selection\")\n", + " else:\n", + " try_again = False\n", + " try_again = True\n", + " while try_again == True:\n", + " u2 = input(\"Enter your choice for Place 2: \")\n", + " u2 = u2.lower()\n", + " if u2 != \"r\" and u2 != \"b\" and u2 != \"o\" and u2 != \"y\" and u2 != \"p\" and u2 != \"g\" and u2 != \"w\":\n", + " print(\"Incorrect Selection\")\n", + " else:\n", + " try_again = False\n", + " try_again = True\n", + " while try_again == True:\n", + " u3 = input(\"Enter your choice for Place 3: \")\n", + " u3 = u3.lower()\n", + " if u3 != \"r\" and u3 != \"b\" and u3 != \"o\" and u3 != \"y\" and u3 != \"p\" and u3 != \"g\" and u3 != \"w\":\n", + " print(\"Incorrect Selection\")\n", + " else:\n", + " try_again = False\n", + " try_again = True\n", + " while try_again == True:\n", + " u4 = input(\"Enter your choice for Place 4: \")\n", + " u4 = u4.lower()\n", + " if u4 != \"r\" and u4 != \"b\" and u4 != \"o\" and u4 != \"y\" and u4 != \"p\" and u4 != \"g\" and u4 != \"w\":\n", + " print(\"Incorrect Selection\")\n", + " else:\n", + " try_again = False\n", + " correct = 0\n", + " wrong_place = 0\n", + " if c1 == u1:\n", + " correct = correct + 1\n", + " elif c1 == u2 or c1 == u3 or c1 == u4:\n", + " wrong_place = wrong_place + 1\n", + " if c2 == u2:\n", + " correct = correct + 1\n", + " elif c2 == u1 or c2 == u3 or c2 == u4:\n", + " wrong_place = wrong_place + 1\n", + " if c3 == u3:\n", + " correct = correct + 1\n", + " elif c3 == u1 or c3 == u2 or c3 == u4:\n", + " wrong_place = wrong_place + 1\n", + " if c4 == u4:\n", + " correct = correct + 1\n", + " elif c4 == u1 or c4 == u2 or c4 == u3:\n", + " wrong_place = wrong_place + 1\n", + " print(\"Correct Colour in the correct place: \",correct)\n", + " print(\"Correct Colour but in the wrong place: \",wrong_place)\n", + " print()\n", + " data2 = [correct,wrong_place]\n", + " return data2\n", + "def main():\n", + " (c1,c2,c3,c4) = select_col()\n", + " score = 0\n", + " play = True\n", + " while play == True:\n", + " (correct,wrong_place) = tryit(c1,c2,c3,c4)\n", + " score = score + 1\n", + " if correct == 4:\n", + " play = False\n", + " print(\"You Win!\")\n", + " print(\"You took\", score,\"guesses\")\n", + " \n", + "main()\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "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.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}