|
65 | 65 | }, |
66 | 66 | { |
67 | 67 | "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 | + ], |
73 | 94 | "source": [ |
74 | 95 | "# [] create list-o-matic\n", |
75 | 96 | "# [] copy and paste in edX assignment page\n", |
76 | 97 | "\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", |
77 | 134 | "\n", |
78 | 135 | "\n" |
79 | 136 | ] |
|
89 | 146 | "metadata": { |
90 | 147 | "anaconda-cloud": {}, |
91 | 148 | "kernelspec": { |
92 | | - "display_name": "Python 3", |
| 149 | + "display_name": "Python 3 (ipykernel)", |
93 | 150 | "language": "python", |
94 | 151 | "name": "python3" |
95 | 152 | }, |
|
103 | 160 | "name": "python", |
104 | 161 | "nbconvert_exporter": "python", |
105 | 162 | "pygments_lexer": "ipython3", |
106 | | - "version": "3.8.8" |
| 163 | + "version": "3.9.7" |
107 | 164 | } |
108 | 165 | }, |
109 | 166 | "nbformat": 4, |
|
0 commit comments