|
677 | 677 | },
|
678 | 678 | {
|
679 | 679 | "cell_type": "code",
|
680 |
| - "execution_count": 12, |
| 680 | + "execution_count": 1, |
681 | 681 | "id": "4b88b1f7-2ac2-4924-a0c5-3ee98ca0728b",
|
682 | 682 | "metadata": {
|
683 | 683 | "editable": true,
|
|
690 | 690 | },
|
691 | 691 | "outputs": [
|
692 | 692 | {
|
693 |
| - "ename": "LoadError", |
694 |
| - "evalue": "ArgumentError: Package JSON not found in current path.\n- Run `import Pkg; Pkg.add(\"JSON\")` to install the JSON package.", |
695 |
| - "output_type": "error", |
696 |
| - "traceback": [ |
697 |
| - "ArgumentError: Package JSON not found in current path.\n- Run `import Pkg; Pkg.add(\"JSON\")` to install the JSON package.", |
698 |
| - "", |
699 |
| - "Stacktrace:", |
700 |
| - " [1] macro expansion", |
701 |
| - " @ .\\loading.jl:2296 [inlined]", |
702 |
| - " [2] macro expansion", |
703 |
| - " @ .\\lock.jl:273 [inlined]", |
704 |
| - " [3] __require(into::Module, mod::Symbol)", |
705 |
| - " @ Base .\\loading.jl:2271", |
706 |
| - " [4] #invoke_in_world#3", |
707 |
| - " @ .\\essentials.jl:1089 [inlined]", |
708 |
| - " [5] invoke_in_world", |
709 |
| - " @ .\\essentials.jl:1086 [inlined]", |
710 |
| - " [6] require(into::Module, mod::Symbol)", |
711 |
| - " @ Base .\\loading.jl:2260" |
712 |
| - ] |
| 693 | + "data": { |
| 694 | + "text/html": [ |
| 695 | + "<style>\n", |
| 696 | + ".quiz-question {\n", |
| 697 | + " background-color: #6c63ff;\n", |
| 698 | + " color: white;\n", |
| 699 | + " padding: 12px;\n", |
| 700 | + " border-radius: 10px;\n", |
| 701 | + " font-weight: bold;\n", |
| 702 | + " font-size: 1.2em;\n", |
| 703 | + " margin-bottom: 10px;\n", |
| 704 | + "}\n", |
| 705 | + "\n", |
| 706 | + ".quiz-form {\n", |
| 707 | + " margin-bottom: 20px;\n", |
| 708 | + "}\n", |
| 709 | + "\n", |
| 710 | + ".quiz-answer {\n", |
| 711 | + " display: block;\n", |
| 712 | + " background-color: #f2f2f2;\n", |
| 713 | + " border: none;\n", |
| 714 | + " border-radius: 10px;\n", |
| 715 | + " padding: 10px;\n", |
| 716 | + " margin: 5px 0;\n", |
| 717 | + " font-size: 1em;\n", |
| 718 | + " cursor: pointer;\n", |
| 719 | + " text-align: left;\n", |
| 720 | + " transition: background-color 0.3s;\n", |
| 721 | + " width: 100%;\n", |
| 722 | + "}\n", |
| 723 | + "\n", |
| 724 | + ".quiz-answer:hover {\n", |
| 725 | + " background-color: #e0e0e0;\n", |
| 726 | + "}\n", |
| 727 | + "\n", |
| 728 | + ".correct {\n", |
| 729 | + " background-color: #4CAF50 !important;\n", |
| 730 | + " color: white !important;\n", |
| 731 | + " border: none;\n", |
| 732 | + "}\n", |
| 733 | + "\n", |
| 734 | + ".incorrect {\n", |
| 735 | + " background-color: #D32F2F !important;\n", |
| 736 | + " color: white !important;\n", |
| 737 | + " border: none;\n", |
| 738 | + "}\n", |
| 739 | + "\n", |
| 740 | + ".feedback {\n", |
| 741 | + " margin-top: 10px;\n", |
| 742 | + " font-weight: bold;\n", |
| 743 | + " font-size: 1em;\n", |
| 744 | + "}\n", |
| 745 | + "</style>\n", |
| 746 | + "\n", |
| 747 | + "<script>\n", |
| 748 | + "function handleAnswer(qid, aid, feedback, isCorrect) {\n", |
| 749 | + " // Reset all buttons for the question\n", |
| 750 | + " let buttons = document.querySelectorAll(\".answer-\" + qid);\n", |
| 751 | + " buttons.forEach(btn => {\n", |
| 752 | + " btn.classList.remove('correct', 'incorrect');\n", |
| 753 | + " });\n", |
| 754 | + "\n", |
| 755 | + " // Apply correct/incorrect to selected\n", |
| 756 | + " let selected = document.getElementById(aid);\n", |
| 757 | + " selected.classList.add(isCorrect ? 'correct' : 'incorrect');\n", |
| 758 | + "\n", |
| 759 | + " // Show feedback below the question\n", |
| 760 | + " let feedbackBox = document.getElementById('feedback_' + qid);\n", |
| 761 | + " feedbackBox.innerHTML = feedback;\n", |
| 762 | + " feedbackBox.style.color = isCorrect ? 'green' : 'red';\n", |
| 763 | + "}\n", |
| 764 | + "</script>\n", |
| 765 | + "<div class=\"quiz-question\">Which of the following is the most memory-efficient way to read a very large text file line-by-line in Julia?</div><form class=\"quiz-form\"><button type=\"button\" class=\"quiz-answer answer-1\" id=\"q1_a1\"\n", |
| 766 | + " onclick=\"handleAnswer('1', 'q1_a1', 'Incorrect', false)\">\n", |
| 767 | + " read(file, String)\n", |
| 768 | + "</button>\n", |
| 769 | + "<button type=\"button\" class=\"quiz-answer answer-1\" id=\"q1_a2\"\n", |
| 770 | + " onclick=\"handleAnswer('1', 'q1_a2', 'Incorrect', false)\">\n", |
| 771 | + " readline(file)\n", |
| 772 | + "</button>\n", |
| 773 | + "<button type=\"button\" class=\"quiz-answer answer-1\" id=\"q1_a3\"\n", |
| 774 | + " onclick=\"handleAnswer('1', 'q1_a3', 'Correct', true)\">\n", |
| 775 | + " eachline(file)\n", |
| 776 | + "</button>\n", |
| 777 | + "<button type=\"button\" class=\"quiz-answer answer-1\" id=\"q1_a4\"\n", |
| 778 | + " onclick=\"handleAnswer('1', 'q1_a4', 'Incorrect', false)\">\n", |
| 779 | + " readlines(file)\n", |
| 780 | + "</button>\n", |
| 781 | + "<div class=\"feedback\" id=\"feedback_1\"></div></form><hr><div class=\"quiz-question\">In Julia, what is the recommended way to ensure a file is always closed after reading or writing, even if an error occurs during processing?</div><form class=\"quiz-form\"><button type=\"button\" class=\"quiz-answer answer-2\" id=\"q2_a1\"\n", |
| 782 | + " onclick=\"handleAnswer('2', 'q2_a1', 'Incorrect', false)\">\n", |
| 783 | + " Manually call close(file) after reading/writing.\n", |
| 784 | + "</button>\n", |
| 785 | + "<button type=\"button\" class=\"quiz-answer answer-2\" id=\"q2_a2\"\n", |
| 786 | + " onclick=\"handleAnswer('2', 'q2_a2', 'Incorrect', false)\">\n", |
| 787 | + " Use try..catch..finally to close the file\n", |
| 788 | + "</button>\n", |
| 789 | + "<button type=\"button\" class=\"quiz-answer answer-2\" id=\"q2_a3\"\n", |
| 790 | + " onclick=\"handleAnswer('2', 'q2_a3', 'Correct', true)\">\n", |
| 791 | + " Use the do block form of open()\n", |
| 792 | + "</button>\n", |
| 793 | + "<button type=\"button\" class=\"quiz-answer answer-2\" id=\"q2_a4\"\n", |
| 794 | + " onclick=\"handleAnswer('2', 'q2_a4', 'Incorrect', false)\">\n", |
| 795 | + " Let Julias garbage collector handle it\n", |
| 796 | + "</button>\n", |
| 797 | + "<div class=\"feedback\" id=\"feedback_2\"></div></form><hr>" |
| 798 | + ] |
| 799 | + }, |
| 800 | + "metadata": {}, |
| 801 | + "output_type": "display_data" |
713 | 802 | }
|
714 | 803 | ],
|
715 | 804 | "source": [
|
|
817 | 906 | "# Use the function\n",
|
818 | 907 | "show_quiz_from_json(\"questions/summary_io.json\")"
|
819 | 908 | ]
|
| 909 | + }, |
| 910 | + { |
| 911 | + "cell_type": "code", |
| 912 | + "execution_count": null, |
| 913 | + "id": "09d9a8d1-84b5-40e0-94f4-ba8415cf59b6", |
| 914 | + "metadata": {}, |
| 915 | + "outputs": [], |
| 916 | + "source": [] |
820 | 917 | }
|
821 | 918 | ],
|
822 | 919 | "metadata": {
|
823 | 920 | "kernelspec": {
|
824 |
| - "display_name": "Julia 1.10.9", |
| 921 | + "display_name": "Julia 1.11.5", |
825 | 922 | "language": "julia",
|
826 |
| - "name": "julia-1.10" |
| 923 | + "name": "julia-1.11" |
827 | 924 | },
|
828 | 925 | "language_info": {
|
829 | 926 | "file_extension": ".jl",
|
830 | 927 | "mimetype": "application/julia",
|
831 | 928 | "name": "julia",
|
832 |
| - "version": "1.10.9" |
| 929 | + "version": "1.11.5" |
833 | 930 | }
|
834 | 931 | },
|
835 | 932 | "nbformat": 4,
|
|
0 commit comments