PicoFumi/notebooks/picofumi.ipynb

561 lines
11 KiB
Plaintext
Raw Normal View History

2021-11-08 07:51:24 +00:00
{
"cells": [
{
"cell_type": "markdown",
"id": "e1d4d9e8-1781-4d55-9a57-d7c505009a04",
"metadata": {},
"source": [
"# Pico Fumi"
]
2021-12-08 07:54:31 +00:00
},
{
"cell_type": "code",
2021-12-13 11:51:51 +00:00
"execution_count": null,
2021-12-11 05:19:48 +00:00
"id": "d8f95dd9-11ad-455d-854a-86a12d84fbda",
"metadata": {},
2021-12-13 11:51:51 +00:00
"outputs": [],
2021-12-11 05:19:48 +00:00
"source": [
"%run picofumi.py"
]
},
{
"cell_type": "markdown",
"id": "f97654b6-de87-4a5a-9dfb-e32eac6b62cd",
"metadata": {},
"source": [
"## Printing"
]
},
{
"cell_type": "code",
2021-12-13 11:51:51 +00:00
"execution_count": null,
2021-12-08 07:54:31 +00:00
"id": "0046af84-de64-4023-bdf5-335177caf22a",
2021-12-13 11:51:51 +00:00
"metadata": {
"tags": []
},
"outputs": [],
2021-12-08 07:54:31 +00:00
"source": [
"print(\"Pico Fumi\")"
]
},
2021-12-11 05:19:48 +00:00
{
"cell_type": "markdown",
"id": "ce8f228c-dbb3-4b49-87ea-2234d283f49d",
"metadata": {},
"source": [
"## Variables"
]
},
2021-12-08 07:54:31 +00:00
{
"cell_type": "code",
2021-12-13 11:51:51 +00:00
"execution_count": null,
2021-12-11 05:19:48 +00:00
"id": "781cbd75-5b16-4740-ac88-fda9672bcdbd",
"metadata": {},
2021-12-13 11:51:51 +00:00
"outputs": [],
"source": [
"#string\n",
"guess = \"123\"\n",
"print(guess)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b41186fa-ff8a-4e5e-ba55-1c9450a5c9af",
"metadata": {},
"outputs": [],
"source": [
"#integer \n",
"guesses = 0\n",
"print(guesses)"
]
},
{
"cell_type": "markdown",
"id": "4304923b-cbc9-48ca-9ee8-766487115c2f",
"metadata": {},
"source": [
"## Get User Input"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "3adeee26-8a18-4bad-946b-3d06920ef82f",
"metadata": {},
2021-12-11 05:19:48 +00:00
"outputs": [
{
2021-12-13 11:51:51 +00:00
"name": "stdin",
2021-12-11 05:19:48 +00:00
"output_type": "stream",
"text": [
2021-12-13 11:51:51 +00:00
"Enter a three digit number: 1\n"
2021-12-11 05:19:48 +00:00
]
}
],
"source": [
2021-12-13 11:51:51 +00:00
"guess = input(\"Enter a three digit number:\")"
2021-12-11 05:19:48 +00:00
]
},
{
"cell_type": "code",
2021-12-13 11:51:51 +00:00
"execution_count": 17,
"id": "ec055f06-6fdd-4ab9-bce2-d56c82093c4b",
2021-12-11 05:19:48 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2021-12-13 11:51:51 +00:00
"1\n"
2021-12-11 05:19:48 +00:00
]
}
],
"source": [
2021-12-13 11:51:51 +00:00
"print(guess)"
2021-12-11 05:19:48 +00:00
]
},
{
"cell_type": "markdown",
2021-12-13 11:51:51 +00:00
"id": "8999ef19-6a3c-41ea-bf2b-11dcbbe64070",
2021-12-11 05:19:48 +00:00
"metadata": {},
"source": [
2021-12-13 11:51:51 +00:00
"## Check that the guess a 3 digit number"
2021-12-11 05:19:48 +00:00
]
},
{
"cell_type": "code",
2021-12-13 11:51:51 +00:00
"execution_count": 18,
"id": "f7bcf18f-4e98-453f-bc1f-ef61b0aa55e4",
2021-12-08 07:54:31 +00:00
"metadata": {},
"outputs": [
{
2021-12-13 11:51:51 +00:00
"data": {
"text/plain": [
"1"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(guess)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "53fca278-f55e-43f1-ab5f-f6df4fb7c163",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(guess) == 3"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "bd9b231e-53c5-4b05-8f55-86ccf289b1e1",
"metadata": {},
"outputs": [
{
"name": "stdout",
2021-12-08 07:54:31 +00:00
"output_type": "stream",
"text": [
2021-12-13 11:51:51 +00:00
"Guess is not 3 digits\n"
2021-12-08 07:54:31 +00:00
]
}
],
"source": [
2021-12-13 11:51:51 +00:00
"if len(guess) != 3:\n",
" print(\"Guess is not 3 digits\")"
]
},
{
"cell_type": "markdown",
"id": "2f806636-3296-42ce-914f-356e34e066a7",
"metadata": {},
"source": [
"## Re-prompt the user until they enter a 3 digit number"
2021-12-08 07:54:31 +00:00
]
},
{
"cell_type": "code",
2021-12-13 11:51:51 +00:00
"execution_count": 28,
"id": "d427210a-75be-4a47-83e2-fbdffa2b2644",
2021-12-08 07:54:31 +00:00
"metadata": {},
"outputs": [
{
2021-12-13 11:51:51 +00:00
"name": "stdin",
2021-12-08 07:54:31 +00:00
"output_type": "stream",
"text": [
2021-12-13 11:51:51 +00:00
"Enter a three digit number: 123\n"
2021-12-08 07:54:31 +00:00
]
}
],
"source": [
2021-12-13 11:51:51 +00:00
"guess = input(\"Enter a three digit number:\")\n",
"while len(guess) != 3:\n",
" guess = input(\"Enter a three digit number:\")"
2021-12-11 05:19:48 +00:00
]
},
{
"cell_type": "markdown",
"id": "6e3fa703-3f5f-4622-b8f5-349f61371282",
"metadata": {},
"source": [
"## Break guess into 3 parts"
2021-12-08 07:54:31 +00:00
]
},
{
"cell_type": "code",
2021-12-13 11:51:51 +00:00
"execution_count": 56,
2021-12-11 05:19:48 +00:00
"id": "7e1a2228-3316-4652-9051-70c355de94bb",
2021-12-08 07:54:31 +00:00
"metadata": {},
2021-12-11 05:19:48 +00:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2021-12-13 11:51:51 +00:00
"['1', '2', '3']\n",
"1\n",
"3\n"
2021-12-11 05:19:48 +00:00
]
}
],
2021-12-08 07:54:31 +00:00
"source": [
2021-12-11 05:19:48 +00:00
"guess = list(guess)\n",
2021-12-13 11:51:51 +00:00
"print(guess)\n",
"print(guess[0])\n",
"print(guess[2])"
2021-12-11 05:19:48 +00:00
]
},
{
"cell_type": "markdown",
"id": "ccd7b9d1-c266-498e-9f46-63c522c4d332",
"metadata": {},
"source": [
2021-12-13 11:51:51 +00:00
"## Itterate over the guess"
2021-12-08 07:54:31 +00:00
]
},
{
"cell_type": "code",
2021-12-13 11:51:51 +00:00
"execution_count": 57,
2021-12-11 05:19:48 +00:00
"id": "ddca84c9-2fff-4302-afd0-7096649bcdc7",
2021-12-08 07:54:31 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2021-12-13 11:51:51 +00:00
"1\n",
"2\n",
"3\n"
2021-12-08 07:54:31 +00:00
]
}
],
"source": [
2021-12-11 05:19:48 +00:00
"for part in guess:\n",
" print(part)"
]
},
{
"cell_type": "code",
2021-12-13 11:51:51 +00:00
"execution_count": 58,
"id": "f631cc60-92e9-4c16-a5ab-4f50dfd10cc2",
2021-12-11 05:19:48 +00:00
"metadata": {},
2021-12-13 11:51:51 +00:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"index 0 value 1\n",
"index 1 value 2\n",
"index 2 value 3\n"
]
}
],
2021-12-11 05:19:48 +00:00
"source": [
2021-12-13 11:51:51 +00:00
"for index, value in enumerate(guess):\n",
" print(f'index {index} value {value}')"
2021-12-11 05:19:48 +00:00
]
},
{
2021-12-13 11:51:51 +00:00
"cell_type": "markdown",
"id": "201cae7a-2cc5-4ff0-ac16-730091e24b72",
2021-12-11 05:19:48 +00:00
"metadata": {},
"source": [
2021-12-13 11:51:51 +00:00
"## Functions"
2021-12-08 07:54:31 +00:00
]
},
{
"cell_type": "code",
2021-12-13 11:51:51 +00:00
"execution_count": 33,
"id": "3aebea62-fa40-4e87-8229-3aafb051a006",
2021-12-08 07:54:31 +00:00
"metadata": {},
"outputs": [],
"source": [
2021-12-13 11:51:51 +00:00
"def GetGuess():\n",
" guess = input(\"Enter a three digit number:\")\n",
" while len(guess) != 3:\n",
" guess = input(\"Enter a three digit number:\")\n",
" return list(guess)"
2021-12-08 07:54:31 +00:00
]
},
{
"cell_type": "code",
2021-12-13 11:51:51 +00:00
"execution_count": 34,
"id": "a2430233-5753-433d-bada-d8ee086f2bb2",
2021-12-08 07:54:31 +00:00
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
2021-12-13 11:51:51 +00:00
"Enter a three digit number: 12\n",
"Enter a three digit number: 12\n",
"Enter a three digit number: 34\n",
"Enter a three digit number: 123\n"
2021-12-08 07:54:31 +00:00
]
},
{
2021-12-13 11:51:51 +00:00
"data": {
"text/plain": [
"['1', '2', '3']"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
2021-12-08 07:54:31 +00:00
}
],
"source": [
2021-12-13 11:51:51 +00:00
"GetGuess()"
]
},
{
"cell_type": "markdown",
"id": "77ab1ca2-0ea0-43b3-b6bd-d4438fa8141d",
"metadata": {},
"source": [
"## Random Numbers"
2021-12-08 07:54:31 +00:00
]
},
{
"cell_type": "code",
2021-12-13 11:51:51 +00:00
"execution_count": 35,
"id": "f4412eef-6b79-4329-b8e7-85f916d3dfbf",
"metadata": {},
"outputs": [],
"source": [
"import random \n",
"random.seed()"
]
},
{
"cell_type": "code",
"execution_count": 44,
"id": "c9324728-63c2-4023-92fc-3e1e80dff03a",
2021-12-08 07:54:31 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2021-12-13 11:51:51 +00:00
"536\n"
2021-12-08 07:54:31 +00:00
]
}
],
2021-12-13 11:51:51 +00:00
"source": [
"number = random.randrange(100,999)\n",
"print(number)"
]
2021-12-08 07:54:31 +00:00
},
{
"cell_type": "code",
2021-12-13 11:51:51 +00:00
"execution_count": 47,
"id": "183e5444-2b79-4366-84cf-4da91c2547cf",
2021-12-08 07:54:31 +00:00
"metadata": {},
"outputs": [
{
2021-12-13 11:51:51 +00:00
"data": {
"text/plain": [
"int"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
2021-12-08 07:54:31 +00:00
}
],
"source": [
2021-12-13 11:51:51 +00:00
"type(number)"
2021-12-08 07:54:31 +00:00
]
},
{
"cell_type": "code",
2021-12-13 11:51:51 +00:00
"execution_count": 48,
"id": "afe9d668-aefd-4021-9028-a21b04e931cd",
"metadata": {},
"outputs": [],
"source": [
"number = str(number)\n",
"number = list(number)"
]
},
{
"cell_type": "markdown",
"id": "a5f6f56b-0678-4f82-9539-ae7c798d6c63",
"metadata": {},
"source": [
"## Check if number guessed is correct"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "6194de2b-2dbe-4c49-bc00-e5bed3c35f1f",
2021-12-08 07:54:31 +00:00
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
2021-12-13 11:51:51 +00:00
"Enter a three digit number: \n",
2021-12-08 07:54:31 +00:00
"Enter a three digit number: 123\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
2021-12-13 11:51:51 +00:00
"You guessed wrong\n"
2021-12-08 07:54:31 +00:00
]
}
],
2021-12-13 11:51:51 +00:00
"source": [
"guess = GetGuess()\n",
"if guess == number:\n",
" print(\"You guessed correctly\")\n",
"else:\n",
" print(\"You guessed wrong\")"
]
},
{
"cell_type": "markdown",
"id": "0496040d-4d2c-4580-9993-d1832568cd6b",
"metadata": {},
"source": [
"## Check Fumi"
]
2021-12-11 05:19:48 +00:00
},
{
"cell_type": "code",
2021-12-13 11:51:51 +00:00
"execution_count": 55,
"id": "ab9145db-4662-41ae-ba38-6c66c7402d80",
2021-12-11 05:19:48 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2021-12-13 11:51:51 +00:00
"index 0 value 1\n",
"index 1 value 2\n",
"index 2 value 3\n"
2021-12-11 05:19:48 +00:00
]
}
],
2021-12-08 07:54:31 +00:00
"source": [
2021-12-13 11:51:51 +00:00
"for index, value in enumerate(guess):\n",
" print(f'index {index} value {value}')"
2021-12-08 07:54:31 +00:00
]
},
{
"cell_type": "code",
2021-12-13 11:51:51 +00:00
"execution_count": null,
2021-12-08 07:54:31 +00:00
"id": "f647c557-d247-48b9-8c31-5623dea46336",
"metadata": {},
2021-12-13 11:51:51 +00:00
"outputs": [],
2021-12-11 05:19:48 +00:00
"source": [
2021-12-13 11:51:51 +00:00
"# %load picofumi.py\n",
"import random \n",
"random.seed()\n",
"\n",
"number = random.randrange(100, 999)\n",
"number = list(str(number))\n",
"guesses = 0\n",
"while True:\n",
" \n",
" if guesses == 5:\n",
" print(\"You loose!\")\n",
" for value in number:\n",
" print(value, end=\" \")\n",
" break\n",
" hint = [\" \", \" \", \" \"]\n",
" guess = input(\"Enter a three digit number:\")\n",
" while len(guess) != 3:\n",
" guess = input(\"Enter a three digit number:\")\n",
" \n",
" guess = list(guess)\n",
" if guess == number:\n",
" print(\"You win!\")\n",
" break\n",
" for index, value in enumerate(guess):\n",
" print(value, end=\" \")\n",
" if value in number:\n",
" hint[index] = \"P\"\n",
" print(\"\")\n",
" for index, value in enumerate(guess):\n",
" if number[index] == value:\n",
" hint[index] = \"F\"\n",
" print(hint[index], end=\" \")\n",
" guesses += 1\n",
" print(\"\\n\")"
2021-12-11 05:19:48 +00:00
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1abd05b8-dfca-4fcc-8bb0-57dd77329086",
"metadata": {},
2021-12-08 07:54:31 +00:00
"outputs": [],
2021-12-11 05:19:48 +00:00
"source": [
"ls\n"
]
2021-11-08 07:51:24 +00:00
}
],
"metadata": {
"kernelspec": {
2021-12-11 05:19:48 +00:00
"display_name": "Python 3 (ipykernel)",
2021-11-08 07:51:24 +00:00
"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",
2021-12-11 05:19:48 +00:00
"version": "3.10.1"
2021-11-08 07:51:24 +00:00
}
},
"nbformat": 4,
"nbformat_minor": 5
}