Skip to content

Commit f15cddb

Browse files
committed
working on P2M2 required code.
1 parent 64b8bee commit f15cddb

1 file changed

Lines changed: 64 additions & 7 deletions

File tree

Python Fundamentals/Module_2.2_Required_Code_Python_Fundamentals.ipynb

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,72 @@
6565
},
6666
{
6767
"cell_type": "code",
68-
"execution_count": 1,
69-
"metadata": {
70-
"collapsed": true
71-
},
72-
"outputs": [],
68+
"execution_count": 35,
69+
"metadata": {},
70+
"outputs": [
71+
{
72+
"name": "stdout",
73+
"output_type": "stream",
74+
"text": [
75+
"Look at all the NBA teams ['bulls', 'hawks', 'hornets', 'suns', 'nets']\n",
76+
"Name another NBA team. list\n",
77+
"['bulls', 'hawks', 'hornets', 'suns', 'nets']\n",
78+
"Name another NBA team. hawks\n",
79+
"Oof. Already had that one. They're gone. \n",
80+
"Name another NBA team. list\n",
81+
"['bulls', 'hornets', 'suns', 'nets']\n",
82+
"Name another NBA team. bulls\n",
83+
"Oof. Already had that one. They're gone. \n",
84+
"Name another NBA team. hornets\n",
85+
"Oof. Already had that one. They're gone. \n",
86+
"Name another NBA team. suns\n",
87+
"Oof. Already had that one. They're gone. \n",
88+
"Name another NBA team. nets\n",
89+
"Oof. Already had that one. They're gone. \n",
90+
"Name another NBA team. list\n"
91+
]
92+
}
93+
],
7394
"source": [
7495
"# [] create list-o-matic\n",
7596
"# [] copy and paste in edX assignment page\n",
7697
"\n",
98+
"def_list = ['bulls', 'hawks', 'hornets', 'suns', 'nets']\n",
99+
"print('Look at all the NBA teams', def_list)\n",
100+
"\n",
101+
"def list_o_matic(i):\n",
102+
" while def_list: \n",
103+
" global new_team\n",
104+
" if len(new_team) == 0:\n",
105+
" print(def_list.pop(), 'just got popped! ')\n",
106+
" new_team = input('Name another NBA team. ')\n",
107+
" elif new_team.startswith(' '):\n",
108+
" print('OK. Let\\'s try that again without the spaces. ')\n",
109+
" new_team = input('Name another NBA team. ')\n",
110+
" elif new_team.lower() == 'list':\n",
111+
" print(def_list)\n",
112+
" new_team = input('Name another NBA team. ') \n",
113+
" elif new_team in def_list:\n",
114+
" print('Oof. Already had that one. They\\'re gone. ')\n",
115+
" def_list.remove(new_team)\n",
116+
" new_team = input('Name another NBA team. ')\n",
117+
" elif new_team not in def_list:\n",
118+
" print('Nice. I\\'ll add that to the list. ')\n",
119+
" def_list.append(new_team)\n",
120+
" new_team = input('Name another NBA team. ')\n",
121+
" elif new_team.lower() == 'quit':\n",
122+
" print(\"Goodbye!\")\n",
123+
" break\n",
124+
" \n",
125+
"\n",
126+
"if def_list:\n",
127+
" new_team = input('Name another NBA team. ')\n",
128+
" if new_team.lower() == 'quit':\n",
129+
" print(\"Goodbye!\")\n",
130+
" else:\n",
131+
" list_o_matic(new_team)\n",
132+
"else:\n",
133+
" print(\"Goodbye.\")\n",
77134
"\n",
78135
"\n"
79136
]
@@ -89,7 +146,7 @@
89146
"metadata": {
90147
"anaconda-cloud": {},
91148
"kernelspec": {
92-
"display_name": "Python 3",
149+
"display_name": "Python 3 (ipykernel)",
93150
"language": "python",
94151
"name": "python3"
95152
},
@@ -103,7 +160,7 @@
103160
"name": "python",
104161
"nbconvert_exporter": "python",
105162
"pygments_lexer": "ipython3",
106-
"version": "3.8.8"
163+
"version": "3.9.7"
107164
}
108165
},
109166
"nbformat": 4,

0 commit comments

Comments
 (0)