PicoFumi/notebooks/picofumi.ipynb

617 lines
11 KiB
Plaintext
Raw Normal View History

2021-11-08 07:51:24 +00:00
{
"cells": [
{
"cell_type": "markdown",
2022-01-08 02:13:00 +00:00
"id": "571ac5d7",
2021-11-08 07:51:24 +00:00
"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,
2022-01-08 02:13:00 +00:00
"id": "72ae05ab",
2021-12-11 05:19:48 +00:00
"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",
2022-01-08 02:13:00 +00:00
"id": "7760dfcf",
2021-12-11 05:19:48 +00:00
"metadata": {},
"source": [
"## Printing"
]
},
{
"cell_type": "code",
2022-01-08 02:13:00 +00:00
"execution_count": 1,
"id": "1eabbdcf",
2021-12-13 11:51:51 +00:00
"metadata": {
"tags": []
},
2022-01-08 02:13:00 +00:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pico Fumi\n"
]
}
],
2021-12-08 07:54:31 +00:00
"source": [
"print(\"Pico Fumi\")"
]
},
2021-12-11 05:19:48 +00:00
{
"cell_type": "markdown",
2022-01-08 02:13:00 +00:00
"id": "c4d898da",
2021-12-11 05:19:48 +00:00
"metadata": {},
"source": [
"## Variables"
]
},
2021-12-08 07:54:31 +00:00
{
"cell_type": "code",
2022-01-08 02:13:00 +00:00
"execution_count": 2,
"id": "c9aa132b",
2021-12-11 05:19:48 +00:00
"metadata": {},
2022-01-08 02:13:00 +00:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"123\n"
]
}
],
2021-12-13 11:51:51 +00:00
"source": [
"#string\n",
"guess = \"123\"\n",
"print(guess)"
]
},
{
"cell_type": "code",
2022-01-08 02:13:00 +00:00
"execution_count": 3,
"id": "64ae1dc1",
2021-12-13 11:51:51 +00:00
"metadata": {},
2022-01-08 02:13:00 +00:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n"
]
}
],
2021-12-13 11:51:51 +00:00
"source": [
"#integer \n",
"guesses = 0\n",
"print(guesses)"
]
},
{
"cell_type": "markdown",
2022-01-08 02:13:00 +00:00
"id": "0cd9ab76",
2021-12-13 11:51:51 +00:00
"metadata": {},
"source": [
"## Get User Input"
]
},
{
"cell_type": "code",
2022-01-08 02:13:00 +00:00
"execution_count": 4,
"id": "4524a662",
2021-12-13 11:51:51 +00:00
"metadata": {},
2021-12-11 05:19:48 +00:00
"outputs": [
{
2022-01-08 02:13:00 +00:00
"name": "stdout",
2021-12-11 05:19:48 +00:00
"output_type": "stream",
"text": [
2022-01-08 02:13:00 +00:00
"Enter a three digit number:123\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",
2022-01-08 02:13:00 +00:00
"execution_count": 5,
"id": "cbaea031",
2021-12-11 05:19:48 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2022-01-08 02:13:00 +00:00
"123\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",
2022-01-08 02:13:00 +00:00
"id": "402a7d7c",
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",
2022-01-08 02:13:00 +00:00
"execution_count": 6,
"id": "de4d4fbb",
2021-12-08 07:54:31 +00:00
"metadata": {},
"outputs": [
{
2021-12-13 11:51:51 +00:00
"data": {
"text/plain": [
2022-01-08 02:13:00 +00:00
"3"
2021-12-13 11:51:51 +00:00
]
},
2022-01-08 02:13:00 +00:00
"execution_count": 6,
2021-12-13 11:51:51 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(guess)"
]
},
{
"cell_type": "code",
2022-01-08 02:13:00 +00:00
"execution_count": 7,
"id": "f747159b",
2021-12-13 11:51:51 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2022-01-08 02:13:00 +00:00
"True"
2021-12-13 11:51:51 +00:00
]
},
2022-01-08 02:13:00 +00:00
"execution_count": 7,
2021-12-13 11:51:51 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(guess) == 3"
]
},
{
"cell_type": "code",
2022-01-08 02:13:00 +00:00
"execution_count": 8,
"id": "b82b11f8",
2021-12-13 11:51:51 +00:00
"metadata": {},
2022-01-08 02:13:00 +00:00
"outputs": [],
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",
2022-01-08 02:13:00 +00:00
"id": "9cf640e2",
2021-12-13 11:51:51 +00:00
"metadata": {},
"source": [
"## Re-prompt the user until they enter a 3 digit number"
2021-12-08 07:54:31 +00:00
]
},
{
"cell_type": "code",
2022-01-08 02:13:00 +00:00
"execution_count": 9,
"id": "3e42feef",
2021-12-08 07:54:31 +00:00
"metadata": {},
"outputs": [
{
2022-01-08 02:13:00 +00:00
"name": "stdout",
2021-12-08 07:54:31 +00:00
"output_type": "stream",
"text": [
2022-01-08 02:13:00 +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",
2022-01-08 02:13:00 +00:00
"id": "5871ca62",
2021-12-11 05:19:48 +00:00
"metadata": {},
"source": [
"## Break guess into 3 parts"
2021-12-08 07:54:31 +00:00
]
},
{
"cell_type": "code",
2022-01-08 02:13:00 +00:00
"execution_count": 10,
"id": "f0823ff9",
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",
2022-01-08 02:13:00 +00:00
"id": "8b32aac0",
2021-12-11 05:19:48 +00:00
"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",
2022-01-08 02:13:00 +00:00
"execution_count": 11,
"id": "d2c97cb7",
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",
2022-01-08 02:13:00 +00:00
"execution_count": 12,
"id": "cdb0cd32",
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",
2022-01-08 02:13:00 +00:00
"id": "f43efa21",
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",
2022-01-08 02:13:00 +00:00
"execution_count": 10,
"id": "4fdded17",
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",
2022-01-08 02:13:00 +00:00
"execution_count": 14,
"id": "886517d8",
2021-12-08 07:54:31 +00:00
"metadata": {},
"outputs": [
{
2022-01-08 02:13:00 +00:00
"name": "stdout",
2021-12-08 07:54:31 +00:00
"output_type": "stream",
"text": [
2022-01-08 02:13:00 +00:00
"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']"
]
},
2022-01-08 02:13:00 +00:00
"execution_count": 14,
2021-12-13 11:51:51 +00:00
"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",
2022-01-08 02:13:00 +00:00
"id": "b18f748b",
2021-12-13 11:51:51 +00:00
"metadata": {},
"source": [
"## Random Numbers"
2021-12-08 07:54:31 +00:00
]
},
{
"cell_type": "code",
2022-01-08 02:13:00 +00:00
"execution_count": 2,
"id": "785a2c42",
2021-12-13 11:51:51 +00:00
"metadata": {},
"outputs": [],
"source": [
"import random \n",
"random.seed()"
]
},
{
"cell_type": "code",
2022-01-08 02:13:00 +00:00
"execution_count": 6,
"id": "d1778d13",
2021-12-08 07:54:31 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2022-01-08 02:13:00 +00:00
"437\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",
2022-01-08 02:13:00 +00:00
"execution_count": 7,
"id": "cd137952",
2021-12-08 07:54:31 +00:00
"metadata": {},
"outputs": [
{
2021-12-13 11:51:51 +00:00
"data": {
"text/plain": [
"int"
]
},
2022-01-08 02:13:00 +00:00
"execution_count": 7,
2021-12-13 11:51:51 +00:00
"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",
2022-01-08 02:13:00 +00:00
"execution_count": 8,
"id": "a270063a",
2021-12-13 11:51:51 +00:00
"metadata": {},
"outputs": [],
"source": [
2022-01-08 02:13:00 +00:00
"#covert to a string\n",
2021-12-13 11:51:51 +00:00
"number = str(number)\n",
2022-01-08 02:13:00 +00:00
"#split into 3 parts\n",
2021-12-13 11:51:51 +00:00
"number = list(number)"
]
},
{
"cell_type": "markdown",
2022-01-08 02:13:00 +00:00
"id": "727a1c33",
2021-12-13 11:51:51 +00:00
"metadata": {},
"source": [
"## Check if number guessed is correct"
]
},
{
"cell_type": "code",
2022-01-08 02:13:00 +00:00
"execution_count": 11,
"id": "dc005fde",
"metadata": {
"scrolled": true
},
2021-12-08 07:54:31 +00:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2022-01-08 02:13:00 +00:00
"Enter a three digit number:472\n",
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",
2022-01-08 02:13:00 +00:00
"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",
2021-12-13 11:51:51 +00:00
"metadata": {},
"source": [
"## Check Fumi"
]
2021-12-11 05:19:48 +00:00
},
{
"cell_type": "code",
2022-01-08 02:13:00 +00:00
"execution_count": 16,
"id": "6591943b",
2021-12-11 05:19:48 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2022-01-08 02:13:00 +00:00
"['4', '7', '2']\n",
"['F', 'P', '']\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",
2022-01-08 02:13:00 +00:00
" if value == number[index]:\n",
" hint[index] = \"F\"\n",
"print(guess)\n",
"print(hint)"
]
},
{
"cell_type": "markdown",
"id": "f19d453f",
"metadata": {},
"source": [
"## Putting it together"
2021-12-08 07:54:31 +00:00
]
},
{
"cell_type": "code",
2021-12-13 11:51:51 +00:00
"execution_count": null,
2022-01-08 02:13:00 +00:00
"id": "fa759ece",
2021-12-08 07:54:31 +00:00
"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,
2022-01-08 02:13:00 +00:00
"id": "39b1ea60",
2021-12-11 05:19:48 +00:00
"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",
2022-01-08 02:13:00 +00:00
"version": "3.9.7"
},
"nteract": {
"version": "nteract-on-jupyter@2.1.3"
2021-11-08 07:51:24 +00:00
}
},
"nbformat": 4,
"nbformat_minor": 5
}