Pico and Fumi check

This commit is contained in:
Jimmy 2022-01-08 02:13:00 +00:00
parent 5ecc7874fc
commit 29f048708e
1 changed files with 154 additions and 98 deletions

View File

@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "e1d4d9e8-1781-4d55-9a57-d7c505009a04", "id": "571ac5d7",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# Pico Fumi" "# Pico Fumi"
@ -11,7 +11,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "d8f95dd9-11ad-455d-854a-86a12d84fbda", "id": "72ae05ab",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -20,7 +20,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "f97654b6-de87-4a5a-9dfb-e32eac6b62cd", "id": "7760dfcf",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Printing" "## Printing"
@ -28,19 +28,27 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 1,
"id": "0046af84-de64-4023-bdf5-335177caf22a", "id": "1eabbdcf",
"metadata": { "metadata": {
"tags": [] "tags": []
}, },
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pico Fumi\n"
]
}
],
"source": [ "source": [
"print(\"Pico Fumi\")" "print(\"Pico Fumi\")"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "ce8f228c-dbb3-4b49-87ea-2234d283f49d", "id": "c4d898da",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Variables" "## Variables"
@ -48,10 +56,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 2,
"id": "781cbd75-5b16-4740-ac88-fda9672bcdbd", "id": "c9aa132b",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"123\n"
]
}
],
"source": [ "source": [
"#string\n", "#string\n",
"guess = \"123\"\n", "guess = \"123\"\n",
@ -60,10 +76,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 3,
"id": "b41186fa-ff8a-4e5e-ba55-1c9450a5c9af", "id": "64ae1dc1",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n"
]
}
],
"source": [ "source": [
"#integer \n", "#integer \n",
"guesses = 0\n", "guesses = 0\n",
@ -72,7 +96,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "4304923b-cbc9-48ca-9ee8-766487115c2f", "id": "0cd9ab76",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Get User Input" "## Get User Input"
@ -80,15 +104,15 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 16, "execution_count": 4,
"id": "3adeee26-8a18-4bad-946b-3d06920ef82f", "id": "4524a662",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdin", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Enter a three digit number: 1\n" "Enter a three digit number:123\n"
] ]
} }
], ],
@ -98,15 +122,15 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": 5,
"id": "ec055f06-6fdd-4ab9-bce2-d56c82093c4b", "id": "cbaea031",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"1\n" "123\n"
] ]
} }
], ],
@ -116,7 +140,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "8999ef19-6a3c-41ea-bf2b-11dcbbe64070", "id": "402a7d7c",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Check that the guess a 3 digit number" "## Check that the guess a 3 digit number"
@ -124,17 +148,17 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18, "execution_count": 6,
"id": "f7bcf18f-4e98-453f-bc1f-ef61b0aa55e4", "id": "de4d4fbb",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"1" "3"
] ]
}, },
"execution_count": 18, "execution_count": 6,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -145,17 +169,17 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22, "execution_count": 7,
"id": "53fca278-f55e-43f1-ab5f-f6df4fb7c163", "id": "f747159b",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"False" "True"
] ]
}, },
"execution_count": 22, "execution_count": 7,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -166,18 +190,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23, "execution_count": 8,
"id": "bd9b231e-53c5-4b05-8f55-86ccf289b1e1", "id": "b82b11f8",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"Guess is not 3 digits\n"
]
}
],
"source": [ "source": [
"if len(guess) != 3:\n", "if len(guess) != 3:\n",
" print(\"Guess is not 3 digits\")" " print(\"Guess is not 3 digits\")"
@ -185,7 +201,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "2f806636-3296-42ce-914f-356e34e066a7", "id": "9cf640e2",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Re-prompt the user until they enter a 3 digit number" "## Re-prompt the user until they enter a 3 digit number"
@ -193,15 +209,15 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 28, "execution_count": 9,
"id": "d427210a-75be-4a47-83e2-fbdffa2b2644", "id": "3e42feef",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdin", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Enter a three digit number: 123\n" "Enter a three digit number:123\n"
] ]
} }
], ],
@ -213,7 +229,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "6e3fa703-3f5f-4622-b8f5-349f61371282", "id": "5871ca62",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Break guess into 3 parts" "## Break guess into 3 parts"
@ -221,8 +237,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 56, "execution_count": 10,
"id": "7e1a2228-3316-4652-9051-70c355de94bb", "id": "f0823ff9",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -244,7 +260,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "ccd7b9d1-c266-498e-9f46-63c522c4d332", "id": "8b32aac0",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Itterate over the guess" "## Itterate over the guess"
@ -252,8 +268,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 57, "execution_count": 11,
"id": "ddca84c9-2fff-4302-afd0-7096649bcdc7", "id": "d2c97cb7",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -273,8 +289,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 58, "execution_count": 12,
"id": "f631cc60-92e9-4c16-a5ab-4f50dfd10cc2", "id": "cdb0cd32",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -294,7 +310,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "201cae7a-2cc5-4ff0-ac16-730091e24b72", "id": "f43efa21",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Functions" "## Functions"
@ -302,8 +318,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 33, "execution_count": 10,
"id": "3aebea62-fa40-4e87-8229-3aafb051a006", "id": "4fdded17",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -316,18 +332,15 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 34, "execution_count": 14,
"id": "a2430233-5753-433d-bada-d8ee086f2bb2", "id": "886517d8",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdin", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Enter a three digit number: 12\n", "Enter a three digit number:123\n"
"Enter a three digit number: 12\n",
"Enter a three digit number: 34\n",
"Enter a three digit number: 123\n"
] ]
}, },
{ {
@ -336,7 +349,7 @@
"['1', '2', '3']" "['1', '2', '3']"
] ]
}, },
"execution_count": 34, "execution_count": 14,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -347,7 +360,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "77ab1ca2-0ea0-43b3-b6bd-d4438fa8141d", "id": "b18f748b",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Random Numbers" "## Random Numbers"
@ -355,8 +368,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 35, "execution_count": 2,
"id": "f4412eef-6b79-4329-b8e7-85f916d3dfbf", "id": "785a2c42",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -366,15 +379,15 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 44, "execution_count": 6,
"id": "c9324728-63c2-4023-92fc-3e1e80dff03a", "id": "d1778d13",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"536\n" "437\n"
] ]
} }
], ],
@ -385,8 +398,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 47, "execution_count": 7,
"id": "183e5444-2b79-4366-84cf-4da91c2547cf", "id": "cd137952",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -395,7 +408,7 @@
"int" "int"
] ]
}, },
"execution_count": 47, "execution_count": 7,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -406,18 +419,20 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 48, "execution_count": 8,
"id": "afe9d668-aefd-4021-9028-a21b04e931cd", "id": "a270063a",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"#covert to a string\n",
"number = str(number)\n", "number = str(number)\n",
"#split into 3 parts\n",
"number = list(number)" "number = list(number)"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "a5f6f56b-0678-4f82-9539-ae7c798d6c63", "id": "727a1c33",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Check if number guessed is correct" "## Check if number guessed is correct"
@ -425,22 +440,17 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 51, "execution_count": 11,
"id": "6194de2b-2dbe-4c49-bc00-e5bed3c35f1f", "id": "dc005fde",
"metadata": {}, "metadata": {
"outputs": [ "scrolled": true
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter a three digit number: \n",
"Enter a three digit number: 123\n"
]
}, },
"outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Enter a three digit number:472\n",
"You guessed wrong\n" "You guessed wrong\n"
] ]
} }
@ -455,7 +465,40 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "0496040d-4d2c-4580-9993-d1832568cd6b", "id": "f0aef1a9",
"metadata": {},
"source": [
"## Check Pico"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "c3752fcd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['4', '7', '2']\n",
"['P', 'P', '']\n"
]
}
],
"source": [
"hint = [\"\", \"\", \"\"]\n",
"for index, value in enumerate(guess):\n",
" if value in number:\n",
" #if value in number and value != number[index]:\n",
" hint[index] = \"P\"\n",
"print(guess)\n",
"print(hint)"
]
},
{
"cell_type": "markdown",
"id": "8ffb6ece",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Check Fumi" "## Check Fumi"
@ -463,29 +506,39 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 55, "execution_count": 16,
"id": "ab9145db-4662-41ae-ba38-6c66c7402d80", "id": "6591943b",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"index 0 value 1\n", "['4', '7', '2']\n",
"index 1 value 2\n", "['F', 'P', '']\n"
"index 2 value 3\n"
] ]
} }
], ],
"source": [ "source": [
"for index, value in enumerate(guess):\n", "for index, value in enumerate(guess):\n",
" print(f'index {index} value {value}')" " if value == number[index]:\n",
" hint[index] = \"F\"\n",
"print(guess)\n",
"print(hint)"
]
},
{
"cell_type": "markdown",
"id": "f19d453f",
"metadata": {},
"source": [
"## Putting it together"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "f647c557-d247-48b9-8c31-5623dea46336", "id": "fa759ece",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -528,7 +581,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "1abd05b8-dfca-4fcc-8bb0-57dd77329086", "id": "39b1ea60",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -552,7 +605,10 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.10.1" "version": "3.9.7"
},
"nteract": {
"version": "nteract-on-jupyter@2.1.3"
} }
}, },
"nbformat": 4, "nbformat": 4,