|
134 | 134 | }, |
135 | 135 | { |
136 | 136 | "cell_type": "code", |
137 | | - "execution_count": 6, |
| 137 | + "execution_count": 8, |
138 | 138 | "metadata": {}, |
139 | 139 | "outputs": [ |
140 | 140 | { |
141 | 141 | "data": { |
142 | 142 | "text/plain": [ |
143 | | - "Card(rank='6', suit='diamonds')" |
| 143 | + "Card(rank='K', suit='diamonds')" |
144 | 144 | ] |
145 | 145 | }, |
146 | | - "execution_count": 6, |
| 146 | + "execution_count": 8, |
147 | 147 | "metadata": {}, |
148 | 148 | "output_type": "execute_result" |
149 | 149 | } |
|
157 | 157 | }, |
158 | 158 | { |
159 | 159 | "cell_type": "code", |
160 | | - "execution_count": 7, |
| 160 | + "execution_count": 9, |
161 | 161 | "metadata": {}, |
162 | 162 | "outputs": [ |
163 | 163 | { |
|
168 | 168 | " Card(rank='4', suit='spades')]" |
169 | 169 | ] |
170 | 170 | }, |
171 | | - "execution_count": 7, |
| 171 | + "execution_count": 9, |
172 | 172 | "metadata": {}, |
173 | 173 | "output_type": "execute_result" |
174 | 174 | } |
|
179 | 179 | }, |
180 | 180 | { |
181 | 181 | "cell_type": "code", |
182 | | - "execution_count": 8, |
| 182 | + "execution_count": 10, |
183 | 183 | "metadata": {}, |
184 | 184 | "outputs": [ |
185 | 185 | { |
|
191 | 191 | " Card(rank='A', suit='hearts')]" |
192 | 192 | ] |
193 | 193 | }, |
194 | | - "execution_count": 8, |
| 194 | + "execution_count": 10, |
195 | 195 | "metadata": {}, |
196 | 196 | "output_type": "execute_result" |
197 | 197 | } |
|
202 | 202 | }, |
203 | 203 | { |
204 | 204 | "cell_type": "code", |
205 | | - "execution_count": 9, |
| 205 | + "execution_count": 11, |
206 | 206 | "metadata": {}, |
207 | 207 | "outputs": [ |
208 | 208 | { |
|
271 | 271 | }, |
272 | 272 | { |
273 | 273 | "cell_type": "code", |
274 | | - "execution_count": 10, |
| 274 | + "execution_count": 12, |
275 | 275 | "metadata": {}, |
276 | 276 | "outputs": [ |
277 | 277 | { |
|
340 | 340 | }, |
341 | 341 | { |
342 | 342 | "cell_type": "code", |
343 | | - "execution_count": 11, |
| 343 | + "execution_count": 13, |
344 | 344 | "metadata": {}, |
345 | 345 | "outputs": [ |
346 | 346 | { |
|
349 | 349 | "True" |
350 | 350 | ] |
351 | 351 | }, |
352 | | - "execution_count": 11, |
| 352 | + "execution_count": 13, |
353 | 353 | "metadata": {}, |
354 | 354 | "output_type": "execute_result" |
355 | 355 | } |
|
360 | 360 | }, |
361 | 361 | { |
362 | 362 | "cell_type": "code", |
363 | | - "execution_count": 12, |
| 363 | + "execution_count": 14, |
364 | 364 | "metadata": {}, |
365 | 365 | "outputs": [ |
366 | 366 | { |
|
369 | 369 | "False" |
370 | 370 | ] |
371 | 371 | }, |
372 | | - "execution_count": 12, |
| 372 | + "execution_count": 14, |
373 | 373 | "metadata": {}, |
374 | 374 | "output_type": "execute_result" |
375 | 375 | } |
|
380 | 380 | }, |
381 | 381 | { |
382 | 382 | "cell_type": "code", |
383 | | - "execution_count": 13, |
| 383 | + "execution_count": 16, |
384 | 384 | "metadata": {}, |
385 | 385 | "outputs": [ |
386 | 386 | { |
387 | 387 | "name": "stdout", |
388 | 388 | "output_type": "stream", |
389 | 389 | "text": [ |
390 | | - "Card(rank='2', suit='clubs')\n", |
391 | | - "Card(rank='2', suit='diamonds')\n", |
392 | | - "Card(rank='2', suit='hearts')\n", |
393 | | - "Card(rank='2', suit='spades')\n", |
394 | | - "Card(rank='3', suit='clubs')\n", |
395 | | - "Card(rank='3', suit='diamonds')\n", |
396 | | - "Card(rank='3', suit='hearts')\n", |
397 | | - "Card(rank='3', suit='spades')\n", |
398 | | - "Card(rank='4', suit='clubs')\n", |
399 | | - "Card(rank='4', suit='diamonds')\n", |
400 | | - "Card(rank='4', suit='hearts')\n", |
401 | | - "Card(rank='4', suit='spades')\n", |
402 | | - "Card(rank='5', suit='clubs')\n", |
403 | | - "Card(rank='5', suit='diamonds')\n", |
404 | | - "Card(rank='5', suit='hearts')\n", |
405 | | - "Card(rank='5', suit='spades')\n", |
406 | | - "Card(rank='6', suit='clubs')\n", |
407 | | - "Card(rank='6', suit='diamonds')\n", |
408 | | - "Card(rank='6', suit='hearts')\n", |
409 | | - "Card(rank='6', suit='spades')\n", |
410 | | - "Card(rank='7', suit='clubs')\n", |
411 | | - "Card(rank='7', suit='diamonds')\n", |
412 | | - "Card(rank='7', suit='hearts')\n", |
413 | | - "Card(rank='7', suit='spades')\n", |
414 | | - "Card(rank='8', suit='clubs')\n", |
415 | | - "Card(rank='8', suit='diamonds')\n", |
416 | | - "Card(rank='8', suit='hearts')\n", |
417 | | - "Card(rank='8', suit='spades')\n", |
418 | | - "Card(rank='9', suit='clubs')\n", |
419 | | - "Card(rank='9', suit='diamonds')\n", |
420 | | - "Card(rank='9', suit='hearts')\n", |
421 | | - "Card(rank='9', suit='spades')\n", |
422 | | - "Card(rank='10', suit='clubs')\n", |
423 | | - "Card(rank='10', suit='diamonds')\n", |
424 | | - "Card(rank='10', suit='hearts')\n", |
425 | | - "Card(rank='10', suit='spades')\n", |
426 | | - "Card(rank='J', suit='clubs')\n", |
427 | | - "Card(rank='J', suit='diamonds')\n", |
428 | | - "Card(rank='J', suit='hearts')\n", |
429 | | - "Card(rank='J', suit='spades')\n", |
430 | | - "Card(rank='Q', suit='clubs')\n", |
431 | | - "Card(rank='Q', suit='diamonds')\n", |
432 | | - "Card(rank='Q', suit='hearts')\n", |
433 | | - "Card(rank='Q', suit='spades')\n", |
434 | | - "Card(rank='K', suit='clubs')\n", |
435 | | - "Card(rank='K', suit='diamonds')\n", |
436 | | - "Card(rank='K', suit='hearts')\n", |
437 | | - "Card(rank='K', suit='spades')\n", |
438 | | - "Card(rank='A', suit='clubs')\n", |
439 | | - "Card(rank='A', suit='diamonds')\n", |
440 | | - "Card(rank='A', suit='hearts')\n", |
441 | | - "Card(rank='A', suit='spades')\n" |
| 390 | + "0 Card(rank='2', suit='clubs')\n", |
| 391 | + "1 Card(rank='2', suit='diamonds')\n", |
| 392 | + "2 Card(rank='2', suit='hearts')\n", |
| 393 | + "3 Card(rank='2', suit='spades')\n", |
| 394 | + "4 Card(rank='3', suit='clubs')\n", |
| 395 | + "5 Card(rank='3', suit='diamonds')\n", |
| 396 | + "6 Card(rank='3', suit='hearts')\n", |
| 397 | + "7 Card(rank='3', suit='spades')\n", |
| 398 | + "8 Card(rank='4', suit='clubs')\n", |
| 399 | + "9 Card(rank='4', suit='diamonds')\n", |
| 400 | + "10 Card(rank='4', suit='hearts')\n", |
| 401 | + "11 Card(rank='4', suit='spades')\n", |
| 402 | + "12 Card(rank='5', suit='clubs')\n", |
| 403 | + "13 Card(rank='5', suit='diamonds')\n", |
| 404 | + "14 Card(rank='5', suit='hearts')\n", |
| 405 | + "15 Card(rank='5', suit='spades')\n", |
| 406 | + "16 Card(rank='6', suit='clubs')\n", |
| 407 | + "17 Card(rank='6', suit='diamonds')\n", |
| 408 | + "18 Card(rank='6', suit='hearts')\n", |
| 409 | + "19 Card(rank='6', suit='spades')\n", |
| 410 | + "20 Card(rank='7', suit='clubs')\n", |
| 411 | + "21 Card(rank='7', suit='diamonds')\n", |
| 412 | + "22 Card(rank='7', suit='hearts')\n", |
| 413 | + "23 Card(rank='7', suit='spades')\n", |
| 414 | + "24 Card(rank='8', suit='clubs')\n", |
| 415 | + "25 Card(rank='8', suit='diamonds')\n", |
| 416 | + "26 Card(rank='8', suit='hearts')\n", |
| 417 | + "27 Card(rank='8', suit='spades')\n", |
| 418 | + "28 Card(rank='9', suit='clubs')\n", |
| 419 | + "29 Card(rank='9', suit='diamonds')\n", |
| 420 | + "30 Card(rank='9', suit='hearts')\n", |
| 421 | + "31 Card(rank='9', suit='spades')\n", |
| 422 | + "32 Card(rank='10', suit='clubs')\n", |
| 423 | + "33 Card(rank='10', suit='diamonds')\n", |
| 424 | + "34 Card(rank='10', suit='hearts')\n", |
| 425 | + "35 Card(rank='10', suit='spades')\n", |
| 426 | + "36 Card(rank='J', suit='clubs')\n", |
| 427 | + "37 Card(rank='J', suit='diamonds')\n", |
| 428 | + "38 Card(rank='J', suit='hearts')\n", |
| 429 | + "39 Card(rank='J', suit='spades')\n", |
| 430 | + "40 Card(rank='Q', suit='clubs')\n", |
| 431 | + "41 Card(rank='Q', suit='diamonds')\n", |
| 432 | + "42 Card(rank='Q', suit='hearts')\n", |
| 433 | + "43 Card(rank='Q', suit='spades')\n", |
| 434 | + "44 Card(rank='K', suit='clubs')\n", |
| 435 | + "45 Card(rank='K', suit='diamonds')\n", |
| 436 | + "46 Card(rank='K', suit='hearts')\n", |
| 437 | + "47 Card(rank='K', suit='spades')\n", |
| 438 | + "48 Card(rank='A', suit='clubs')\n", |
| 439 | + "49 Card(rank='A', suit='diamonds')\n", |
| 440 | + "50 Card(rank='A', suit='hearts')\n", |
| 441 | + "51 Card(rank='A', suit='spades')\n" |
442 | 442 | ] |
443 | 443 | } |
444 | 444 | ], |
|
449 | 449 | " rank_value = FrenchDeck.ranks.index(card.rank)\n", |
450 | 450 | " return rank_value * len(suit_values) + suit_values[card.suit]\n", |
451 | 451 | "\n", |
452 | | - "for card in sorted(deck, key=spades_high):\n", |
453 | | - " print(card)" |
| 452 | + "for idx, card in enumerate(sorted(deck, key=spades_high)):\n", |
| 453 | + " print(idx, card)" |
454 | 454 | ] |
455 | 455 | }, |
456 | 456 | { |
|
469 | 469 | }, |
470 | 470 | { |
471 | 471 | "cell_type": "code", |
472 | | - "execution_count": 14, |
| 472 | + "execution_count": 36, |
473 | 473 | "metadata": {}, |
474 | | - "outputs": [], |
| 474 | + "outputs": [ |
| 475 | + { |
| 476 | + "data": { |
| 477 | + "text/plain": [ |
| 478 | + "\"Vector('1', 2)\"" |
| 479 | + ] |
| 480 | + }, |
| 481 | + "execution_count": 36, |
| 482 | + "metadata": {}, |
| 483 | + "output_type": "execute_result" |
| 484 | + } |
| 485 | + ], |
475 | 486 | "source": [ |
476 | 487 | "import math\n", |
477 | 488 | "\n", |
|
496 | 507 | " return Vector(x, y)\n", |
497 | 508 | "\n", |
498 | 509 | " def __mul__(self, scalar):\n", |
499 | | - " return Vector(self.x * scalar, self.y * scalar)" |
| 510 | + " return Vector(self.x * scalar, self.y * scalar)\n", |
| 511 | + " \n", |
| 512 | + "v = Vector(\"1\", 2)\n", |
| 513 | + "v.__repr__()" |
500 | 514 | ] |
501 | 515 | }, |
502 | 516 | { |
503 | 517 | "cell_type": "code", |
504 | | - "execution_count": 15, |
| 518 | + "execution_count": 41, |
505 | 519 | "metadata": {}, |
506 | 520 | "outputs": [ |
507 | 521 | { |
|
510 | 524 | "Vector(4, 5)" |
511 | 525 | ] |
512 | 526 | }, |
513 | | - "execution_count": 15, |
| 527 | + "execution_count": 41, |
514 | 528 | "metadata": {}, |
515 | 529 | "output_type": "execute_result" |
516 | 530 | } |
|
523 | 537 | }, |
524 | 538 | { |
525 | 539 | "cell_type": "code", |
526 | | - "execution_count": 16, |
| 540 | + "execution_count": 42, |
527 | 541 | "metadata": {}, |
528 | 542 | "outputs": [ |
529 | 543 | { |
|
532 | 546 | "5.0" |
533 | 547 | ] |
534 | 548 | }, |
535 | | - "execution_count": 16, |
| 549 | + "execution_count": 42, |
536 | 550 | "metadata": {}, |
537 | 551 | "output_type": "execute_result" |
538 | 552 | } |
|
544 | 558 | }, |
545 | 559 | { |
546 | 560 | "cell_type": "code", |
547 | | - "execution_count": 17, |
| 561 | + "execution_count": 43, |
548 | 562 | "metadata": {}, |
549 | 563 | "outputs": [ |
550 | 564 | { |
|
553 | 567 | "Vector(9, 12)" |
554 | 568 | ] |
555 | 569 | }, |
556 | | - "execution_count": 17, |
| 570 | + "execution_count": 43, |
557 | 571 | "metadata": {}, |
558 | 572 | "output_type": "execute_result" |
559 | 573 | } |
|
564 | 578 | }, |
565 | 579 | { |
566 | 580 | "cell_type": "code", |
567 | | - "execution_count": 18, |
| 581 | + "execution_count": 44, |
568 | 582 | "metadata": {}, |
569 | 583 | "outputs": [ |
570 | 584 | { |
|
573 | 587 | "15.0" |
574 | 588 | ] |
575 | 589 | }, |
576 | | - "execution_count": 18, |
| 590 | + "execution_count": 44, |
577 | 591 | "metadata": {}, |
578 | 592 | "output_type": "execute_result" |
579 | 593 | } |
580 | 594 | ], |
581 | 595 | "source": [ |
582 | 596 | "abs(v * 3)" |
583 | 597 | ] |
| 598 | + }, |
| 599 | + { |
| 600 | + "cell_type": "code", |
| 601 | + "execution_count": 47, |
| 602 | + "metadata": {}, |
| 603 | + "outputs": [ |
| 604 | + { |
| 605 | + "ename": "AttributeError", |
| 606 | + "evalue": "'NoneType' object has no attribute '__len__'", |
| 607 | + "output_type": "error", |
| 608 | + "traceback": [ |
| 609 | + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
| 610 | + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", |
| 611 | + "Cell \u001b[0;32mIn[47], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m a \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 2\u001b[0m a\u001b[38;5;241m.\u001b[39m\u001b[38;5;21m__bool__\u001b[39m()\n\u001b[0;32m----> 3\u001b[0m \u001b[43ma\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[38;5;21;43m__len__\u001b[39;49m()\n", |
| 612 | + "\u001b[0;31mAttributeError\u001b[0m: 'NoneType' object has no attribute '__len__'" |
| 613 | + ] |
| 614 | + } |
| 615 | + ], |
| 616 | + "source": [ |
| 617 | + "a = None\n", |
| 618 | + "a.__bool__()\n", |
| 619 | + "a.__len__()" |
| 620 | + ] |
584 | 621 | } |
585 | 622 | ], |
586 | 623 | "metadata": { |
|
599 | 636 | "name": "python", |
600 | 637 | "nbconvert_exporter": "python", |
601 | 638 | "pygments_lexer": "ipython3", |
602 | | - "version": "3.8.0" |
| 639 | + "version": "3.9.6" |
603 | 640 | } |
604 | 641 | }, |
605 | 642 | "nbformat": 4, |
|
0 commit comments