Add Titles

This commit is contained in:
Jimmy 2021-12-11 18:19:48 +13:00
parent 8be959c68f
commit 850a8adc84
1 changed files with 440 additions and 202 deletions

View File

@ -10,173 +10,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 25,
"id": "0046af84-de64-4023-bdf5-335177caf22a", "id": "d8f95dd9-11ad-455d-854a-86a12d84fbda",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pico Fumi\n"
]
}
],
"source": [
"print(\"Pico Fumi\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "3adeee26-8a18-4bad-946b-3d06920ef82f",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter a three digit number 333\n"
]
}
],
"source": [
"guess = input(\"Enter a three digit number:\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "7e1a2228-3316-4652-9051-70c355de94bb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"333\n"
]
}
],
"source": [
"print(number)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "f4412eef-6b79-4329-b8e7-85f916d3dfbf",
"metadata": {},
"outputs": [],
"source": [
"import random \n",
"random.seed()"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "d613f588-cfd6-447d-a0f5-4444e051b5b2",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"670\n"
]
}
],
"source": [
"number = random.randrange(1000)\n",
"print(number)"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "6194de2b-2dbe-4c49-bc00-e5bed3c35f1f",
"metadata": {},
"outputs": [],
"source": [
"finished = False"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "e6e0b1c2-7c4b-4538-8421-bfdd027b1857",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter a three digit number: 1234\n",
"Enter a three digit number: 333\n",
"Enter a three digit number: 670\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"You win\n"
]
}
],
"source": [
"while finished == False:\n",
" guess = input(\"Enter a three digit number:\")\n",
" # covert to integer\n",
" guess = int(guess)\n",
" if guess == number:\n",
" print(\"You win\")\n",
" finished = True"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "232eb403-b705-447e-8d16-0909c4e63e6a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"482\n"
]
}
],
"source": [
"number = random.randrange(1000)\n",
"print(number)"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "12d5c294-7fc8-47ad-a3bd-45d10bbed198",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['4', '8', '2']\n"
]
}
],
"source": [
"number_parts = [s for s in str(number)]\n",
"print(number_parts)"
]
},
{
"cell_type": "code",
"execution_count": 79,
"id": "a4d0cfc2-34a1-43e8-8c91-5fe2918a4e9e",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -191,7 +26,7 @@
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"1 2 3 \n", "1 2 3 \n",
"P P \n", " \n",
"\n" "\n"
] ]
}, },
@ -215,7 +50,399 @@
"name": "stdin", "name": "stdin",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Enter a three digit number: 531\n" "Enter a three digit number: 789\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"7 8 9 \n",
" F \n",
"\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter a three digit number: 588\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"5 8 8 \n",
"F F P \n",
"\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter a three digit number: 585\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"5 8 5 \n",
"F F P \n",
"\n",
"You loose!\n",
"5 8 0 "
]
}
],
"source": [
"%run picofumi.py"
]
},
{
"cell_type": "markdown",
"id": "f97654b6-de87-4a5a-9dfb-e32eac6b62cd",
"metadata": {},
"source": [
"## Printing"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "0046af84-de64-4023-bdf5-335177caf22a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pico Fumi\n"
]
}
],
"source": [
"print(\"Pico Fumi\")"
]
},
{
"cell_type": "markdown",
"id": "ce8f228c-dbb3-4b49-87ea-2234d283f49d",
"metadata": {},
"source": [
"## Variables"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "781cbd75-5b16-4740-ac88-fda9672bcdbd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"123\n"
]
}
],
"source": [
"guess = \"123\"\n",
"print(guess)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "b41186fa-ff8a-4e5e-ba55-1c9450a5c9af",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n"
]
}
],
"source": [
"guesses = 0\n",
"print(guesses)"
]
},
{
"cell_type": "markdown",
"id": "4304923b-cbc9-48ca-9ee8-766487115c2f",
"metadata": {},
"source": [
"## Get User Input"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "3adeee26-8a18-4bad-946b-3d06920ef82f",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter a three digit number: 123\n"
]
}
],
"source": [
"guess = input(\"Enter a three digit number:\")"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "ec055f06-6fdd-4ab9-bce2-d56c82093c4b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"123\n"
]
}
],
"source": [
"print(guess)"
]
},
{
"cell_type": "markdown",
"id": "6e3fa703-3f5f-4622-b8f5-349f61371282",
"metadata": {},
"source": [
"## Break guess into 3 parts"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "7e1a2228-3316-4652-9051-70c355de94bb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['1', '2', '3']\n"
]
}
],
"source": [
"guess = list(guess)\n",
"print(guess)"
]
},
{
"cell_type": "markdown",
"id": "ccd7b9d1-c266-498e-9f46-63c522c4d332",
"metadata": {},
"source": [
"## Itterate over the parts"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "ddca84c9-2fff-4302-afd0-7096649bcdc7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5\n",
"8\n",
"5\n"
]
}
],
"source": [
"for part in guess:\n",
" print(part)"
]
},
{
"cell_type": "markdown",
"id": "77ab1ca2-0ea0-43b3-b6bd-d4438fa8141d",
"metadata": {},
"source": [
"## Random Numbers"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "f4412eef-6b79-4329-b8e7-85f916d3dfbf",
"metadata": {},
"outputs": [],
"source": [
"import random \n",
"random.seed()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c9324728-63c2-4023-92fc-3e1e80dff03a",
"metadata": {},
"outputs": [],
"source": [
"number = random.randrange(100,999)\n",
"print(number)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "6194de2b-2dbe-4c49-bc00-e5bed3c35f1f",
"metadata": {},
"outputs": [],
"source": [
"finished = False"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "e6e0b1c2-7c4b-4538-8421-bfdd027b1857",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter a three digit number: 123\n",
"Enter a three digit number: 123\n",
"Enter a three digit number: 345\n",
"Enter a three digit number: 23\n",
"Enter a three digit number: 100\n",
"Enter a three digit number: 675\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"You win\n"
]
}
],
"source": [
"while finished == False:\n",
" guess = input(\"Enter a three digit number:\")\n",
" # covert to integer\n",
" guess = int(guess)675\n",
" if guess == number:\n",
" print(\"You win\")\n",
" finished = True"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "232eb403-b705-447e-8d16-0909c4e63e6a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"707\n"
]
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 9,
"id": "12d5c294-7fc8-47ad-a3bd-45d10bbed198",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['7', '0', '7']\n"
]
}
],
"source": [
"number_parts = [s for s in str(number)]\n",
"print(number_parts)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "a4d0cfc2-34a1-43e8-8c91-5fe2918a4e9e",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter a three digit number: 123\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 2 3 \n",
"P \n",
"\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter a three digit number: 456\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"4 5 6 \n",
" \n",
"\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter a three digit number: 789\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"7 8 9 \n",
"P P \n",
"\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter a three digit number: 817\n"
] ]
}, },
{ {
@ -226,50 +453,61 @@
] ]
} }
], ],
"source": []
},
{
"cell_type": "code",
"execution_count": 22,
"id": "c43c7dc8-93f2-4f61-821f-1f8f0c2aba39",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"9\r"
]
}
],
"source": [ "source": [
"number = random.randrange(1000)\n", "from time import sleep\n",
"number_parts = [s for s in str(number)]\n", "for i in range(10):\n",
"guesses = 0\n", " print(i, end=\"\\r\")\n",
"while True:\n", " sleep(1)"
" \n", ]
" if guesses == 5:\n", },
" print(\"You loose!\")\n", {
" break\n", "cell_type": "code",
" hint = [\" \", \" \", \" \"]\n", "execution_count": 22,
" guess = input(\"Enter a three digit number:\")\n", "id": "f647c557-d247-48b9-8c31-5623dea46336",
" while len(guess) != 3:\n", "metadata": {},
" guess = input(\"Enter a three digit number:\")\n", "outputs": [
" \n", {
" \n", "name": "stdout",
" guess = [s for s in guess]\n", "output_type": "stream",
" if guess == number_parts:\n", "text": [
" print(\"You win!\")\n", "IPython will make a temporary file named: /tmp/ipython_edit_m0vz1ei2/ipython_edit_oww2f6iw.py\n"
" break\n", ]
" for index, value in enumerate(guess):\n", }
" print(value, end=\" \")\n", ],
" if value in number_parts:\n", "source": [
" hint[index] = \"P\"\n", "%edit"
" print(\"\")\n",
" for index, value in enumerate(guess):\n",
" if number_parts[index] == value:\n",
" hint[index] = \"F\"\n",
" print(hint[index], end=\" \")\n",
" guesses += 1\n",
" print(\"\\n\")"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "f647c557-d247-48b9-8c31-5623dea46336", "id": "1abd05b8-dfca-4fcc-8bb0-57dd77329086",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [] "source": [
"ls\n"
]
} }
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python 3 (ipykernel)",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -283,7 +521,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.9.9" "version": "3.10.1"
} }
}, },
"nbformat": 4, "nbformat": 4,