You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.8 KiB
Plaintext
80 lines
1.8 KiB
Plaintext
2 years ago
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"id": "666a35e1-435d-4555-8193-9258ff568e21",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"class letterLeaf:\n",
|
||
|
" def __init__(self,question):\n",
|
||
|
" self.yes = None\n",
|
||
|
" self.no = None\n",
|
||
|
" self.question = question\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"id": "254b714a-2504-4cc0-9a78-21d406ddbb2f",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# tree traversals, here to print stuff \n",
|
||
|
"def inorder(treeName):\n",
|
||
|
" if treeName:\n",
|
||
|
" inorder(treeName.yes)\n",
|
||
|
" print(treeName.question)\n",
|
||
|
" inorder(treeName.no)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"id": "e8512457-7944-4604-92c7-29f90ab6c3db",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# interactive user input utility \n",
|
||
|
"def saysYes(ques):\n",
|
||
|
" while True:\n",
|
||
|
" ans = input(ques)\n",
|
||
|
" ans = ans[0:1].lower()\n",
|
||
|
" if ans == 'y': return True\n",
|
||
|
" else : return False"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "8415d1d2-211a-4e82-b331-85527e8c1510",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"reference\n",
|
||
|
"https://web.stonehill.edu/compsci/CS211/Assignmenta%202015/TreeAssignment.pdf"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"kernelspec": {
|
||
|
"display_name": "Python 3 (ipykernel)",
|
||
|
"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",
|
||
2 years ago
|
"version": "3.10.4"
|
||
2 years ago
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 5
|
||
|
}
|