292 lines
5.7 KiB
Plaintext
292 lines
5.7 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "e1d4d9e8-1781-4d55-9a57-d7c505009a04",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Pico Fumi"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "0046af84-de64-4023-bdf5-335177caf22a",
|
|
"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": {},
|
|
"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 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",
|
|
" P \n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdin",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Enter a three digit number: 531\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"You win!\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"number = random.randrange(1000)\n",
|
|
"number_parts = [s for s in str(number)]\n",
|
|
"guesses = 0\n",
|
|
"while True:\n",
|
|
" \n",
|
|
" if guesses == 5:\n",
|
|
" print(\"You loose!\")\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",
|
|
" \n",
|
|
" guess = [s for s in guess]\n",
|
|
" if guess == number_parts:\n",
|
|
" print(\"You win!\")\n",
|
|
" break\n",
|
|
" for index, value in enumerate(guess):\n",
|
|
" print(value, end=\" \")\n",
|
|
" if value in number_parts:\n",
|
|
" hint[index] = \"P\"\n",
|
|
" 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",
|
|
"execution_count": null,
|
|
"id": "f647c557-d247-48b9-8c31-5623dea46336",
|
|
"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.9.9"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|