Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions Password Project.ipynb
Original file line number Diff line number Diff line change
@@ -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
}