You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
" guess= input('Enter a number of your choice')\n",
193
+
" guess= int(guess)\n",
194
+
" if (guess >100 and guess <1):\n",
195
+
" print ('OUT OF BOUNDS')\n",
196
+
" continue\n",
197
+
"\n",
198
+
" if (guess == x_guess):\n",
199
+
" l= len(guesses)\n",
200
+
" print('You are successful')\n",
201
+
" print('The number of guesses it took you is {}'.format(l))\n",
202
+
" break\n",
203
+
"\n",
204
+
" guesses.append(guess)\n",
205
+
"\n",
206
+
" if guesses[-2]:\n",
207
+
" if abs(guess-x_guess)< abs(guess-guesses[-2]):\n",
208
+
" print ('WARMER')\n",
209
+
" else:\n",
210
+
" print('COLDER') \n",
211
+
" else:\n",
212
+
" if abs(x_guess-guess) <= 10:\n",
213
+
" print('WARM!')\n",
214
+
" else:\n",
215
+
" print('COLD!') \n",
216
+
""
217
+
],
218
+
"execution_count": null,
219
+
"outputs": [
220
+
{
221
+
"output_type": "stream",
222
+
"text": [
223
+
"Enter a number of your choice45\n",
224
+
"COLD!\n",
225
+
"Enter a number of your choice40\n",
226
+
"COLDER\n",
227
+
"Enter a number of your choice39\n",
228
+
"COLDER\n",
229
+
"Enter a number of your choice47\n",
230
+
"COLDER\n",
231
+
"Enter a number of your choice53\n",
232
+
"COLDER\n",
233
+
"Enter a number of your choice22\n",
234
+
"WARMER\n",
235
+
"Enter a number of your choice20\n",
236
+
"COLDER\n",
237
+
"Enter a number of your choice21\n",
238
+
"COLDER\n",
239
+
"Enter a number of your choice24\n",
240
+
"WARMER\n",
241
+
"Enter a number of your choice25\n",
242
+
"COLDER\n",
243
+
"Enter a number of your choice23\n",
244
+
"You are successful\n",
245
+
"The number of guesses it took you is 11\n"
246
+
],
247
+
"name": "stdout"
248
+
}
249
+
]
250
+
},
251
+
{
252
+
"cell_type": "markdown",
253
+
"metadata": {
254
+
"id": "ztcaTsf3trIj"
255
+
},
256
+
"source": [
257
+
"#### Write a `while` loop that compares the player's guess to our number. If the player guesses correctly, break from the loop. Otherwise, tell the player if they're warmer or colder, and continue asking for guesses.\n",
258
+
"\n",
259
+
"Some hints:\n",
260
+
"* it may help to sketch out all possible combinations on paper first!\n",
261
+
"* you can use the `abs()` function to find the positive difference between two numbers\n",
262
+
"* if you append all new guesses to the list, then the previous guess is given as `guesses[-2]`"
263
+
]
264
+
},
265
+
{
266
+
"cell_type": "code",
267
+
"metadata": {
268
+
"collapsed": true,
269
+
"id": "HL77f27strIk"
270
+
},
271
+
"source": [
272
+
"while True:\n",
273
+
"\n",
274
+
" # we can copy the code from above to take an input\n",
275
+
"\n",
276
+
" pass"
277
+
],
278
+
"execution_count": null,
279
+
"outputs": []
280
+
},
281
+
{
282
+
"cell_type": "markdown",
283
+
"metadata": {
284
+
"id": "3_Mu35R8trIl"
285
+
},
286
+
"source": [
287
+
"That's it! You've just programmed your first game!\n",
288
+
"\n",
289
+
"In the next section we'll learn how to turn some of these repetitive actions into *functions* that can be called whenever we need them."
0 commit comments