[{"data":1,"prerenderedAt":3150},["ShallowReactive",2],{"doc-\u002Fhow-to\u002Fhow-to-debug-python-code-beginner-guide":3},{"id":4,"title":5,"body":6,"description":3143,"extension":3144,"meta":3145,"navigation":800,"path":3146,"seo":3147,"stem":3148,"__hash__":3149},"content\u002Fhow-to\u002Fhow-to-debug-python-code-beginner-guide.md","How to Debug Python Code (Beginner Guide)",{"type":7,"value":8,"toc":3093},"minimark",[9,13,22,25,46,53,58,64,150,153,164,182,186,189,205,209,215,218,229,232,245,252,256,259,264,267,270,323,326,412,415,432,435,445,449,452,455,474,477,488,492,495,498,551,553,595,598,615,618,641,647,653,657,660,740,743,750,755,758,772,776,887,889,922,925,929,1082,1084,1157,1167,1170,1174,1177,1266,1269,1325,1328,1332,1335,1339,1342,1386,1392,1395,1438,1442,1468,1478,1480,1503,1512,1516,1559,1566,1568,1616,1618,1627,1631,1688,1701,1703,1754,1756,1765,1769,1799,1808,1814,1852,1857,1859,1901,1915,1919,1925,1929,1932,2060,2062,2135,2142,2144,2261,2263,2333,2340,2343,2407,2414,2418,2421,2424,2427,2431,2434,2445,2448,2452,2455,2459,2462,2465,2539,2542,2640,2647,2651,2654,2669,2671,2684,2687,2691,2694,2697,2701,2704,2707,2711,2714,2719,2733,2736,2747,2750,2754,2757,2822,2826,2829,2898,2901,2933,2935,2996,3000,3004,3010,3014,3017,3024,3030,3034,3037,3041,3089],[10,11,5],"h1",{"id":12},"how-to-debug-python-code-beginner-guide",[14,15,16,17,21],"p",{},"Debugging means finding out ",[18,19,20],"strong",{},"why your Python code is not doing what you expect"," and then fixing it step by step.",[14,23,24],{},"This guide shows a simple process beginners can use to:",[26,27,28,32,35,43],"ul",{},[29,30,31],"li",{},"understand what debugging means",[29,33,34],{},"find the line causing a problem",[29,36,37,38,42],{},"use ",[39,40,41],"code",{},"print()"," and traceback messages",[29,44,45],{},"fix common mistakes without guessing",[14,47,48,49,52],{},"The goal is not to use advanced tools. The goal is to help you build a ",[18,50,51],{},"repeatable debugging process"," you can use in any Python program.",[54,55,57],"h2",{"id":56},"quick-way-to-start-debugging","Quick way to start debugging",[14,59,60,61,63],{},"When your code does not work, add simple ",[39,62,41],{}," lines to check which lines run and what values your variables contain.",[65,66,71],"pre",{"className":67,"code":68,"language":69,"meta":70,"style":70},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","print('Reached here')\nprint('value of x =', x)\nprint('type of x =', type(x))\n","python","",[39,72,73,99,122],{"__ignoreMap":70},[74,75,78,82,86,90,94,96],"span",{"class":76,"line":77},"line",1,[74,79,81],{"class":80},"sptTA","print",[74,83,85],{"class":84},"sP7_E","(",[74,87,89],{"class":88},"sjJ54","'",[74,91,93],{"class":92},"s_sjI","Reached here",[74,95,89],{"class":88},[74,97,98],{"class":84},")\n",[74,100,102,104,106,108,111,113,116,120],{"class":76,"line":101},2,[74,103,81],{"class":80},[74,105,85],{"class":84},[74,107,89],{"class":88},[74,109,110],{"class":92},"value of x =",[74,112,89],{"class":88},[74,114,115],{"class":84},",",[74,117,119],{"class":118},"slqww"," x",[74,121,98],{"class":84},[74,123,125,127,129,131,134,136,138,142,144,147],{"class":76,"line":124},3,[74,126,81],{"class":80},[74,128,85],{"class":84},[74,130,89],{"class":88},[74,132,133],{"class":92},"type of x =",[74,135,89],{"class":88},[74,137,115],{"class":84},[74,139,141],{"class":140},"sZMiF"," type",[74,143,85],{"class":84},[74,145,146],{"class":118},"x",[74,148,149],{"class":84},"))\n",[14,151,152],{},"This helps you answer questions like:",[26,154,155,158,161],{},[29,156,157],{},"Did this line run?",[29,159,160],{},"What value does the variable have right now?",[29,162,163],{},"Is the variable the type I expect?",[14,165,166,167,174,175,181],{},"If you are new to this, see the ",[168,169,171,173],"a",{"href":170},"\u002Freference\u002Fpython-print-function-explained",[39,172,41],{}," function explained"," and the ",[168,176,178,173],{"href":177},"\u002Freference\u002Fpython-type-function-explained",[39,179,180],{},"type()",".",[54,183,185],{"id":184},"what-this-page-helps-you-do","What this page helps you do",[14,187,188],{},"By the end of this page, you should be able to:",[26,190,191,194,197,202],{},[29,192,193],{},"Understand what debugging means in simple terms",[29,195,196],{},"Follow a repeatable process to find bugs",[29,198,199,200,42],{},"Use beginner-friendly tools like ",[39,201,41],{},[29,203,204],{},"Fix common code problems without guessing",[54,206,208],{"id":207},"what-debugging-means","What debugging means",[14,210,211,212,181],{},"Debugging means ",[18,213,214],{},"finding the cause of a problem in your code",[14,216,217],{},"A bug can be:",[26,219,220,223,226],{},[29,221,222],{},"an error message",[29,224,225],{},"the wrong output",[29,227,228],{},"code that runs but does nothing useful",[14,230,231],{},"The main goal is to find:",[26,233,234,240],{},[29,235,236,237],{},"the ",[18,238,239],{},"exact line",[29,241,236,242],{},[18,243,244],{},"exact reason",[14,246,247,248,181],{},"For a general introduction to Python errors, see ",[168,249,251],{"href":250},"\u002Flearn\u002Fpython-errors-and-exceptions-explained","Python errors and exceptions explained",[54,253,255],{"id":254},"start-with-the-error-message","Start with the error message",[14,257,258],{},"If your program shows an error, start there.",[260,261,263],"h3",{"id":262},"read-the-last-line-first","Read the last line first",[14,265,266],{},"The last line of the traceback usually tells you the error type.",[14,268,269],{},"For example:",[65,271,273],{"className":67,"code":272,"language":69,"meta":70,"style":70},"numbers = [10, 20, 30]\nprint(numbers[5])\n",[39,274,275,305],{"__ignoreMap":70},[74,276,277,281,285,288,292,294,297,299,302],{"class":76,"line":77},[74,278,280],{"class":279},"su5hD","numbers ",[74,282,284],{"class":283},"smGrS","=",[74,286,287],{"class":84}," [",[74,289,291],{"class":290},"srdBf","10",[74,293,115],{"class":84},[74,295,296],{"class":290}," 20",[74,298,115],{"class":84},[74,300,301],{"class":290}," 30",[74,303,304],{"class":84},"]\n",[74,306,307,309,311,314,317,320],{"class":76,"line":101},[74,308,81],{"class":80},[74,310,85],{"class":84},[74,312,313],{"class":118},"numbers",[74,315,316],{"class":84},"[",[74,318,319],{"class":290},"5",[74,321,322],{"class":84},"])\n",[14,324,325],{},"Output:",[65,327,329],{"className":67,"code":328,"language":69,"meta":70,"style":70},"Traceback (most recent call last):\n  File \"main.py\", line 2, in \u003Cmodule>\n    print(numbers[5])\nIndexError: list index out of range\n",[39,330,331,344,379,394],{"__ignoreMap":70},[74,332,333,336,338,341],{"class":76,"line":77},[74,334,335],{"class":118},"Traceback ",[74,337,85],{"class":84},[74,339,340],{"class":118},"most recent call last",[74,342,343],{"class":84},"):\n",[74,345,346,349,352,355,357,359,362,365,367,370,373,376],{"class":76,"line":101},[74,347,348],{"class":279},"  File ",[74,350,351],{"class":88},"\"",[74,353,354],{"class":92},"main.py",[74,356,351],{"class":88},[74,358,115],{"class":84},[74,360,361],{"class":279}," line ",[74,363,364],{"class":290},"2",[74,366,115],{"class":84},[74,368,369],{"class":283}," in",[74,371,372],{"class":283}," \u003C",[74,374,375],{"class":279},"module",[74,377,378],{"class":283},">\n",[74,380,381,384,386,388,390,392],{"class":76,"line":124},[74,382,383],{"class":80},"    print",[74,385,85],{"class":84},[74,387,313],{"class":118},[74,389,316],{"class":84},[74,391,319],{"class":290},[74,393,322],{"class":84},[74,395,397,400,403,406,409],{"class":76,"line":396},4,[74,398,399],{"class":140},"IndexError",[74,401,402],{"class":84},":",[74,404,405],{"class":140}," list",[74,407,408],{"class":279}," index out of ",[74,410,411],{"class":80},"range\n",[14,413,414],{},"The most important part to notice first is:",[65,416,418],{"className":67,"code":417,"language":69,"meta":70,"style":70},"IndexError: list index out of range\n",[39,419,420],{"__ignoreMap":70},[74,421,422,424,426,428,430],{"class":76,"line":77},[74,423,399],{"class":140},[74,425,402],{"class":84},[74,427,405],{"class":140},[74,429,408],{"class":279},[74,431,411],{"class":80},[14,433,434],{},"That tells you what kind of problem happened.",[14,436,437,438,181],{},"If you get this specific error, see ",[168,439,441,442],{"href":440},"\u002Ferrors\u002Findexerror-list-index-out-of-range-fix-explained","how to fix ",[39,443,444],{},"IndexError: list index out of range",[260,446,448],{"id":447},"check-the-line-number","Check the line number",[14,450,451],{},"The traceback also shows the line where Python found the problem.",[14,453,454],{},"In the example above, the problem is on line 2:",[65,456,458],{"className":67,"code":457,"language":69,"meta":70,"style":70},"print(numbers[5])\n",[39,459,460],{"__ignoreMap":70},[74,461,462,464,466,468,470,472],{"class":76,"line":77},[74,463,81],{"class":80},[74,465,85],{"class":84},[74,467,313],{"class":118},[74,469,316],{"class":84},[74,471,319],{"class":290},[74,473,322],{"class":84},[14,475,476],{},"Now ask:",[26,478,479,482,485],{},[29,480,481],{},"Does this variable contain what I think it contains?",[29,483,484],{},"Is this index valid?",[29,486,487],{},"Did I use the right function or value?",[260,489,491],{"id":490},"look-at-the-code-around-that-line","Look at the code around that line",[14,493,494],{},"Sometimes the real cause starts a few lines earlier.",[14,496,497],{},"Example:",[65,499,501],{"className":67,"code":500,"language":69,"meta":70,"style":70},"name = input(\"Enter your age: \")\nresult = name + 5\nprint(result)\n",[39,502,503,524,540],{"__ignoreMap":70},[74,504,505,508,510,513,515,517,520,522],{"class":76,"line":77},[74,506,507],{"class":279},"name ",[74,509,284],{"class":283},[74,511,512],{"class":80}," input",[74,514,85],{"class":84},[74,516,351],{"class":88},[74,518,519],{"class":92},"Enter your age: ",[74,521,351],{"class":88},[74,523,98],{"class":84},[74,525,526,529,531,534,537],{"class":76,"line":101},[74,527,528],{"class":279},"result ",[74,530,284],{"class":283},[74,532,533],{"class":279}," name ",[74,535,536],{"class":283},"+",[74,538,539],{"class":290}," 5\n",[74,541,542,544,546,549],{"class":76,"line":124},[74,543,81],{"class":80},[74,545,85],{"class":84},[74,547,548],{"class":118},"result",[74,550,98],{"class":84},[14,552,325],{},[65,554,556],{"className":67,"code":555,"language":69,"meta":70,"style":70},"TypeError: can only concatenate str (not \"int\") to str\n",[39,557,558],{"__ignoreMap":70},[74,559,560,563,565,568,571,574,578,581,584,586,589,592],{"class":76,"line":77},[74,561,562],{"class":140},"TypeError",[74,564,402],{"class":84},[74,566,567],{"class":279}," can only concatenate ",[74,569,570],{"class":140},"str",[74,572,573],{"class":84}," (",[74,575,577],{"class":576},"sVHd0","not",[74,579,580],{"class":88}," \"",[74,582,583],{"class":92},"int",[74,585,351],{"class":88},[74,587,588],{"class":84},")",[74,590,591],{"class":279}," to ",[74,593,594],{"class":140},"str\n",[14,596,597],{},"The failing line is:",[65,599,601],{"className":67,"code":600,"language":69,"meta":70,"style":70},"result = name + 5\n",[39,602,603],{"__ignoreMap":70},[74,604,605,607,609,611,613],{"class":76,"line":77},[74,606,528],{"class":279},[74,608,284],{"class":283},[74,610,533],{"class":279},[74,612,536],{"class":283},[74,614,539],{"class":290},[14,616,617],{},"But the real cause is above it:",[65,619,621],{"className":67,"code":620,"language":69,"meta":70,"style":70},"name = input(\"Enter your age: \")\n",[39,622,623],{"__ignoreMap":70},[74,624,625,627,629,631,633,635,637,639],{"class":76,"line":77},[74,626,507],{"class":279},[74,628,284],{"class":283},[74,630,512],{"class":80},[74,632,85],{"class":84},[74,634,351],{"class":88},[74,636,519],{"class":92},[74,638,351],{"class":88},[74,640,98],{"class":84},[14,642,643,646],{},[39,644,645],{},"input()"," returns a string, not a number. You need to convert it first.",[14,648,649,650,181],{},"If you see this kind of problem, read how to fix ",[39,651,652],{},"TypeError: unsupported operand type(s) for +",[54,654,656],{"id":655},"a-simple-debugging-checklist","A simple debugging checklist",[14,658,659],{},"Use this checklist every time your code breaks:",[661,662,663,673,686,696,708,720,730],"ol",{},[29,664,665,668],{},[18,666,667],{},"Reproduce the problem",[26,669,670],{},[29,671,672],{},"Run the code again and make sure you can see the same issue.",[29,674,675,678],{},[18,676,677],{},"Read the error message carefully",[26,679,680,683],{},[29,681,682],{},"Start with the last line.",[29,684,685],{},"Then read the traceback above it.",[29,687,688,691],{},[18,689,690],{},"Change one thing at a time",[26,692,693],{},[29,694,695],{},"If you change many lines at once, you may create new problems.",[29,697,698,703],{},[18,699,700,701],{},"Check variable values with ",[39,702,41],{},[26,704,705],{},[29,706,707],{},"Print important variables before the problem line.",[29,709,710,715],{},[18,711,712,713],{},"Check data types with ",[39,714,180],{},[26,716,717],{},[29,718,719],{},"A value may look right but still be the wrong type.",[29,721,722,725],{},[18,723,724],{},"Make the example smaller",[26,726,727],{},[29,728,729],{},"Remove unrelated code and focus on the smallest version that still has the bug.",[29,731,732,735],{},[18,733,734],{},"Test after each change",[26,736,737],{},[29,738,739],{},"This helps you see which change actually fixed the issue.",[14,741,742],{},"This process is much better than guessing.",[54,744,746,747,749],{"id":745},"use-print-to-inspect-your-code","Use ",[39,748,41],{}," to inspect your code",[14,751,752,754],{},[39,753,41],{}," is one of the easiest debugging tools for beginners.",[14,756,757],{},"Use it to:",[26,759,760,763,766,769],{},[29,761,762],{},"confirm whether a line runs",[29,764,765],{},"inspect variable values",[29,767,768],{},"inspect data types",[29,770,771],{},"compare expected values with actual values",[260,773,775],{"id":774},"example-check-whether-a-line-runs","Example: check whether a line runs",[65,777,779],{"className":67,"code":778,"language":69,"meta":70,"style":70},"print(\"Program started\")\n\nage = 20\nprint(\"Age has been set\")\n\nif age > 18:\n    print(\"Inside the if block\")\n\nprint(\"Program finished\")\n",[39,780,781,796,802,812,827,832,850,866,871],{"__ignoreMap":70},[74,782,783,785,787,789,792,794],{"class":76,"line":77},[74,784,81],{"class":80},[74,786,85],{"class":84},[74,788,351],{"class":88},[74,790,791],{"class":92},"Program started",[74,793,351],{"class":88},[74,795,98],{"class":84},[74,797,798],{"class":76,"line":101},[74,799,801],{"emptyLinePlaceholder":800},true,"\n",[74,803,804,807,809],{"class":76,"line":124},[74,805,806],{"class":279},"age ",[74,808,284],{"class":283},[74,810,811],{"class":290}," 20\n",[74,813,814,816,818,820,823,825],{"class":76,"line":396},[74,815,81],{"class":80},[74,817,85],{"class":84},[74,819,351],{"class":88},[74,821,822],{"class":92},"Age has been set",[74,824,351],{"class":88},[74,826,98],{"class":84},[74,828,830],{"class":76,"line":829},5,[74,831,801],{"emptyLinePlaceholder":800},[74,833,835,838,841,844,847],{"class":76,"line":834},6,[74,836,837],{"class":576},"if",[74,839,840],{"class":279}," age ",[74,842,843],{"class":283},">",[74,845,846],{"class":290}," 18",[74,848,849],{"class":84},":\n",[74,851,853,855,857,859,862,864],{"class":76,"line":852},7,[74,854,383],{"class":80},[74,856,85],{"class":84},[74,858,351],{"class":88},[74,860,861],{"class":92},"Inside the if block",[74,863,351],{"class":88},[74,865,98],{"class":84},[74,867,869],{"class":76,"line":868},8,[74,870,801],{"emptyLinePlaceholder":800},[74,872,874,876,878,880,883,885],{"class":76,"line":873},9,[74,875,81],{"class":80},[74,877,85],{"class":84},[74,879,351],{"class":88},[74,881,882],{"class":92},"Program finished",[74,884,351],{"class":88},[74,886,98],{"class":84},[14,888,325],{},[65,890,892],{"className":67,"code":891,"language":69,"meta":70,"style":70},"Program started\nAge has been set\nInside the if block\nProgram finished\n",[39,893,894,899,907,917],{"__ignoreMap":70},[74,895,896],{"class":76,"line":77},[74,897,898],{"class":279},"Program started\n",[74,900,901,904],{"class":76,"line":101},[74,902,903],{"class":279},"Age has been ",[74,905,906],{"class":140},"set\n",[74,908,909,912,914],{"class":76,"line":124},[74,910,911],{"class":279},"Inside the ",[74,913,837],{"class":576},[74,915,916],{"class":279}," block\n",[74,918,919],{"class":76,"line":396},[74,920,921],{"class":279},"Program finished\n",[14,923,924],{},"These messages act like checkpoints.",[260,926,928],{"id":927},"example-print-variable-values-before-a-failing-line","Example: print variable values before a failing line",[65,930,932],{"className":67,"code":931,"language":69,"meta":70,"style":70},"price = \"10\"\nquantity = 3\n\nprint(\"price =\", price)\nprint(\"quantity =\", quantity)\nprint(\"type of price =\", type(price))\nprint(\"type of quantity =\", type(quantity))\n\ntotal = price * quantity\nprint(total)\n",[39,933,934,948,958,962,982,1002,1026,1050,1054,1070],{"__ignoreMap":70},[74,935,936,939,941,943,945],{"class":76,"line":77},[74,937,938],{"class":279},"price ",[74,940,284],{"class":283},[74,942,580],{"class":88},[74,944,291],{"class":92},[74,946,947],{"class":88},"\"\n",[74,949,950,953,955],{"class":76,"line":101},[74,951,952],{"class":279},"quantity ",[74,954,284],{"class":283},[74,956,957],{"class":290}," 3\n",[74,959,960],{"class":76,"line":124},[74,961,801],{"emptyLinePlaceholder":800},[74,963,964,966,968,970,973,975,977,980],{"class":76,"line":396},[74,965,81],{"class":80},[74,967,85],{"class":84},[74,969,351],{"class":88},[74,971,972],{"class":92},"price =",[74,974,351],{"class":88},[74,976,115],{"class":84},[74,978,979],{"class":118}," price",[74,981,98],{"class":84},[74,983,984,986,988,990,993,995,997,1000],{"class":76,"line":829},[74,985,81],{"class":80},[74,987,85],{"class":84},[74,989,351],{"class":88},[74,991,992],{"class":92},"quantity =",[74,994,351],{"class":88},[74,996,115],{"class":84},[74,998,999],{"class":118}," quantity",[74,1001,98],{"class":84},[74,1003,1004,1006,1008,1010,1013,1015,1017,1019,1021,1024],{"class":76,"line":834},[74,1005,81],{"class":80},[74,1007,85],{"class":84},[74,1009,351],{"class":88},[74,1011,1012],{"class":92},"type of price =",[74,1014,351],{"class":88},[74,1016,115],{"class":84},[74,1018,141],{"class":140},[74,1020,85],{"class":84},[74,1022,1023],{"class":118},"price",[74,1025,149],{"class":84},[74,1027,1028,1030,1032,1034,1037,1039,1041,1043,1045,1048],{"class":76,"line":852},[74,1029,81],{"class":80},[74,1031,85],{"class":84},[74,1033,351],{"class":88},[74,1035,1036],{"class":92},"type of quantity =",[74,1038,351],{"class":88},[74,1040,115],{"class":84},[74,1042,141],{"class":140},[74,1044,85],{"class":84},[74,1046,1047],{"class":118},"quantity",[74,1049,149],{"class":84},[74,1051,1052],{"class":76,"line":868},[74,1053,801],{"emptyLinePlaceholder":800},[74,1055,1056,1059,1061,1064,1067],{"class":76,"line":873},[74,1057,1058],{"class":279},"total ",[74,1060,284],{"class":283},[74,1062,1063],{"class":279}," price ",[74,1065,1066],{"class":283},"*",[74,1068,1069],{"class":279}," quantity\n",[74,1071,1073,1075,1077,1080],{"class":76,"line":1072},10,[74,1074,81],{"class":80},[74,1076,85],{"class":84},[74,1078,1079],{"class":118},"total",[74,1081,98],{"class":84},[14,1083,325],{},[65,1085,1087],{"className":67,"code":1086,"language":69,"meta":70,"style":70},"price = 10\nquantity = 3\ntype of price = \u003Cclass 'str'>\ntype of quantity = \u003Cclass 'int'>\n101010\n",[39,1088,1089,1098,1106,1131,1152],{"__ignoreMap":70},[74,1090,1091,1093,1095],{"class":76,"line":77},[74,1092,938],{"class":279},[74,1094,284],{"class":283},[74,1096,1097],{"class":290}," 10\n",[74,1099,1100,1102,1104],{"class":76,"line":101},[74,1101,952],{"class":279},[74,1103,284],{"class":283},[74,1105,957],{"class":290},[74,1107,1108,1111,1114,1116,1118,1122,1125,1127,1129],{"class":76,"line":124},[74,1109,1110],{"class":140},"type",[74,1112,1113],{"class":279}," of price ",[74,1115,284],{"class":283},[74,1117,372],{"class":283},[74,1119,1121],{"class":1120},"sbsja","class",[74,1123,1124],{"class":88}," '",[74,1126,570],{"class":92},[74,1128,89],{"class":88},[74,1130,378],{"class":283},[74,1132,1133,1135,1138,1140,1142,1144,1146,1148,1150],{"class":76,"line":396},[74,1134,1110],{"class":140},[74,1136,1137],{"class":279}," of quantity ",[74,1139,284],{"class":283},[74,1141,372],{"class":283},[74,1143,1121],{"class":1120},[74,1145,1124],{"class":88},[74,1147,583],{"class":92},[74,1149,89],{"class":88},[74,1151,378],{"class":283},[74,1153,1154],{"class":76,"line":829},[74,1155,1156],{"class":290},"101010\n",[14,1158,1159,1160,1162,1163,1166],{},"This code does not crash, but the result may be surprising. Because ",[39,1161,1023],{}," is a string, ",[39,1164,1165],{},"\"10\" * 3"," repeats the string.",[14,1168,1169],{},"The printed type helps you spot the problem.",[260,1171,1173],{"id":1172},"example-use-clear-labels","Example: use clear labels",[14,1175,1176],{},"This is better:",[65,1178,1180],{"className":67,"code":1179,"language":69,"meta":70,"style":70},"x = 7\ny = 2\nprint(\"x =\", x)\nprint(\"y =\", y)\nprint(\"x \u002F y =\", x \u002F y)\n",[39,1181,1182,1192,1202,1221,1241],{"__ignoreMap":70},[74,1183,1184,1187,1189],{"class":76,"line":77},[74,1185,1186],{"class":279},"x ",[74,1188,284],{"class":283},[74,1190,1191],{"class":290}," 7\n",[74,1193,1194,1197,1199],{"class":76,"line":101},[74,1195,1196],{"class":279},"y ",[74,1198,284],{"class":283},[74,1200,1201],{"class":290}," 2\n",[74,1203,1204,1206,1208,1210,1213,1215,1217,1219],{"class":76,"line":124},[74,1205,81],{"class":80},[74,1207,85],{"class":84},[74,1209,351],{"class":88},[74,1211,1212],{"class":92},"x =",[74,1214,351],{"class":88},[74,1216,115],{"class":84},[74,1218,119],{"class":118},[74,1220,98],{"class":84},[74,1222,1223,1225,1227,1229,1232,1234,1236,1239],{"class":76,"line":396},[74,1224,81],{"class":80},[74,1226,85],{"class":84},[74,1228,351],{"class":88},[74,1230,1231],{"class":92},"y =",[74,1233,351],{"class":88},[74,1235,115],{"class":84},[74,1237,1238],{"class":118}," y",[74,1240,98],{"class":84},[74,1242,1243,1245,1247,1249,1252,1254,1256,1259,1262,1264],{"class":76,"line":829},[74,1244,81],{"class":80},[74,1246,85],{"class":84},[74,1248,351],{"class":88},[74,1250,1251],{"class":92},"x \u002F y =",[74,1253,351],{"class":88},[74,1255,115],{"class":84},[74,1257,1258],{"class":118}," x ",[74,1260,1261],{"class":283},"\u002F",[74,1263,1238],{"class":118},[74,1265,98],{"class":84},[14,1267,1268],{},"Than this:",[65,1270,1272],{"className":67,"code":1271,"language":69,"meta":70,"style":70},"x = 7\ny = 2\nprint(x)\nprint(y)\nprint(x \u002F y)\n",[39,1273,1274,1282,1290,1300,1311],{"__ignoreMap":70},[74,1275,1276,1278,1280],{"class":76,"line":77},[74,1277,1186],{"class":279},[74,1279,284],{"class":283},[74,1281,1191],{"class":290},[74,1283,1284,1286,1288],{"class":76,"line":101},[74,1285,1196],{"class":279},[74,1287,284],{"class":283},[74,1289,1201],{"class":290},[74,1291,1292,1294,1296,1298],{"class":76,"line":124},[74,1293,81],{"class":80},[74,1295,85],{"class":84},[74,1297,146],{"class":118},[74,1299,98],{"class":84},[74,1301,1302,1304,1306,1309],{"class":76,"line":396},[74,1303,81],{"class":80},[74,1305,85],{"class":84},[74,1307,1308],{"class":118},"y",[74,1310,98],{"class":84},[74,1312,1313,1315,1317,1319,1321,1323],{"class":76,"line":829},[74,1314,81],{"class":80},[74,1316,85],{"class":84},[74,1318,1186],{"class":118},[74,1320,1261],{"class":283},[74,1322,1238],{"class":118},[74,1324,98],{"class":84},[14,1326,1327],{},"Labels make debugging output much easier to understand.",[54,1329,1331],{"id":1330},"check-common-beginner-problems","Check common beginner problems",[14,1333,1334],{},"Many Python bugs come from a few common mistakes.",[260,1336,1338],{"id":1337},"wrong-indentation","Wrong indentation",[14,1340,1341],{},"Python uses indentation to define blocks of code.",[65,1343,1345],{"className":67,"code":1344,"language":69,"meta":70,"style":70},"age = 20\n\nif age > 18:\nprint(\"Adult\")\n",[39,1346,1347,1355,1359,1371],{"__ignoreMap":70},[74,1348,1349,1351,1353],{"class":76,"line":77},[74,1350,806],{"class":279},[74,1352,284],{"class":283},[74,1354,811],{"class":290},[74,1356,1357],{"class":76,"line":101},[74,1358,801],{"emptyLinePlaceholder":800},[74,1360,1361,1363,1365,1367,1369],{"class":76,"line":124},[74,1362,837],{"class":576},[74,1364,840],{"class":279},[74,1366,843],{"class":283},[74,1368,846],{"class":290},[74,1370,849],{"class":84},[74,1372,1373,1375,1377,1379,1382,1384],{"class":76,"line":396},[74,1374,81],{"class":80},[74,1376,85],{"class":84},[74,1378,351],{"class":88},[74,1380,1381],{"class":92},"Adult",[74,1383,351],{"class":88},[74,1385,98],{"class":84},[14,1387,1388,1389,1391],{},"This causes an indentation-related error because the ",[39,1390,41],{}," line should be indented.",[14,1393,1394],{},"Correct version:",[65,1396,1398],{"className":67,"code":1397,"language":69,"meta":70,"style":70},"age = 20\n\nif age > 18:\n    print(\"Adult\")\n",[39,1399,1400,1408,1412,1424],{"__ignoreMap":70},[74,1401,1402,1404,1406],{"class":76,"line":77},[74,1403,806],{"class":279},[74,1405,284],{"class":283},[74,1407,811],{"class":290},[74,1409,1410],{"class":76,"line":101},[74,1411,801],{"emptyLinePlaceholder":800},[74,1413,1414,1416,1418,1420,1422],{"class":76,"line":124},[74,1415,837],{"class":576},[74,1417,840],{"class":279},[74,1419,843],{"class":283},[74,1421,846],{"class":290},[74,1423,849],{"class":84},[74,1425,1426,1428,1430,1432,1434,1436],{"class":76,"line":396},[74,1427,383],{"class":80},[74,1429,85],{"class":84},[74,1431,351],{"class":88},[74,1433,1381],{"class":92},[74,1435,351],{"class":88},[74,1437,98],{"class":84},[260,1439,1441],{"id":1440},"using-a-variable-before-creating-it","Using a variable before creating it",[65,1443,1445],{"className":67,"code":1444,"language":69,"meta":70,"style":70},"print(score)\nscore = 100\n",[39,1446,1447,1458],{"__ignoreMap":70},[74,1448,1449,1451,1453,1456],{"class":76,"line":77},[74,1450,81],{"class":80},[74,1452,85],{"class":84},[74,1454,1455],{"class":118},"score",[74,1457,98],{"class":84},[74,1459,1460,1463,1465],{"class":76,"line":101},[74,1461,1462],{"class":279},"score ",[74,1464,284],{"class":283},[74,1466,1467],{"class":290}," 100\n",[14,1469,1470,1471,1474,1475,1477],{},"This causes a ",[39,1472,1473],{},"NameError"," because ",[39,1476,1455],{}," does not exist yet.",[14,1479,1394],{},[65,1481,1483],{"className":67,"code":1482,"language":69,"meta":70,"style":70},"score = 100\nprint(score)\n",[39,1484,1485,1493],{"__ignoreMap":70},[74,1486,1487,1489,1491],{"class":76,"line":77},[74,1488,1462],{"class":279},[74,1490,284],{"class":283},[74,1492,1467],{"class":290},[74,1494,1495,1497,1499,1501],{"class":76,"line":101},[74,1496,81],{"class":80},[74,1498,85],{"class":84},[74,1500,1455],{"class":118},[74,1502,98],{"class":84},[14,1504,1505,1506,181],{},"If you see this error, read ",[168,1507,441,1509],{"href":1508},"\u002Ferrors\u002Fnameerror-name-is-not-defined-fix",[39,1510,1511],{},"NameError: name is not defined",[260,1513,1515],{"id":1514},"mixing-strings-and-numbers","Mixing strings and numbers",[65,1517,1519],{"className":67,"code":1518,"language":69,"meta":70,"style":70},"age = \"25\"\nnext_year = age + 1\nprint(next_year)\n",[39,1520,1521,1534,1548],{"__ignoreMap":70},[74,1522,1523,1525,1527,1529,1532],{"class":76,"line":77},[74,1524,806],{"class":279},[74,1526,284],{"class":283},[74,1528,580],{"class":88},[74,1530,1531],{"class":92},"25",[74,1533,947],{"class":88},[74,1535,1536,1539,1541,1543,1545],{"class":76,"line":101},[74,1537,1538],{"class":279},"next_year ",[74,1540,284],{"class":283},[74,1542,840],{"class":279},[74,1544,536],{"class":283},[74,1546,1547],{"class":290}," 1\n",[74,1549,1550,1552,1554,1557],{"class":76,"line":124},[74,1551,81],{"class":80},[74,1553,85],{"class":84},[74,1555,1556],{"class":118},"next_year",[74,1558,98],{"class":84},[14,1560,1561,1562,1565],{},"This fails because ",[39,1563,1564],{},"\"25\""," is a string.",[14,1567,1394],{},[65,1569,1571],{"className":67,"code":1570,"language":69,"meta":70,"style":70},"age = \"25\"\nnext_year = int(age) + 1\nprint(next_year)\n",[39,1572,1573,1585,1606],{"__ignoreMap":70},[74,1574,1575,1577,1579,1581,1583],{"class":76,"line":77},[74,1576,806],{"class":279},[74,1578,284],{"class":283},[74,1580,580],{"class":88},[74,1582,1531],{"class":92},[74,1584,947],{"class":88},[74,1586,1587,1589,1591,1594,1596,1599,1601,1604],{"class":76,"line":101},[74,1588,1538],{"class":279},[74,1590,284],{"class":283},[74,1592,1593],{"class":140}," int",[74,1595,85],{"class":84},[74,1597,1598],{"class":118},"age",[74,1600,588],{"class":84},[74,1602,1603],{"class":283}," +",[74,1605,1547],{"class":290},[74,1607,1608,1610,1612,1614],{"class":76,"line":124},[74,1609,81],{"class":80},[74,1611,85],{"class":84},[74,1613,1556],{"class":118},[74,1615,98],{"class":84},[14,1617,325],{},[65,1619,1621],{"className":67,"code":1620,"language":69,"meta":70,"style":70},"26\n",[39,1622,1623],{"__ignoreMap":70},[74,1624,1625],{"class":76,"line":77},[74,1626,1620],{"class":290},[260,1628,1630],{"id":1629},"using-the-wrong-list-index","Using the wrong list index",[65,1632,1634],{"className":67,"code":1633,"language":69,"meta":70,"style":70},"colors = [\"red\", \"green\", \"blue\"]\nprint(colors[3])\n",[39,1635,1636,1672],{"__ignoreMap":70},[74,1637,1638,1641,1643,1645,1647,1650,1652,1654,1656,1659,1661,1663,1665,1668,1670],{"class":76,"line":77},[74,1639,1640],{"class":279},"colors ",[74,1642,284],{"class":283},[74,1644,287],{"class":84},[74,1646,351],{"class":88},[74,1648,1649],{"class":92},"red",[74,1651,351],{"class":88},[74,1653,115],{"class":84},[74,1655,580],{"class":88},[74,1657,1658],{"class":92},"green",[74,1660,351],{"class":88},[74,1662,115],{"class":84},[74,1664,580],{"class":88},[74,1666,1667],{"class":92},"blue",[74,1669,351],{"class":88},[74,1671,304],{"class":84},[74,1673,1674,1676,1678,1681,1683,1686],{"class":76,"line":101},[74,1675,81],{"class":80},[74,1677,85],{"class":84},[74,1679,1680],{"class":118},"colors",[74,1682,316],{"class":84},[74,1684,1685],{"class":290},"3",[74,1687,322],{"class":84},[14,1689,1690,1691,1694,1695,1698,1699,181],{},"This fails because valid indexes are ",[39,1692,1693],{},"0",", ",[39,1696,1697],{},"1",", and ",[39,1700,364],{},[14,1702,1394],{},[65,1704,1706],{"className":67,"code":1705,"language":69,"meta":70,"style":70},"colors = [\"red\", \"green\", \"blue\"]\nprint(colors[2])\n",[39,1707,1708,1740],{"__ignoreMap":70},[74,1709,1710,1712,1714,1716,1718,1720,1722,1724,1726,1728,1730,1732,1734,1736,1738],{"class":76,"line":77},[74,1711,1640],{"class":279},[74,1713,284],{"class":283},[74,1715,287],{"class":84},[74,1717,351],{"class":88},[74,1719,1649],{"class":92},[74,1721,351],{"class":88},[74,1723,115],{"class":84},[74,1725,580],{"class":88},[74,1727,1658],{"class":92},[74,1729,351],{"class":88},[74,1731,115],{"class":84},[74,1733,580],{"class":88},[74,1735,1667],{"class":92},[74,1737,351],{"class":88},[74,1739,304],{"class":84},[74,1741,1742,1744,1746,1748,1750,1752],{"class":76,"line":101},[74,1743,81],{"class":80},[74,1745,85],{"class":84},[74,1747,1680],{"class":118},[74,1749,316],{"class":84},[74,1751,364],{"class":290},[74,1753,322],{"class":84},[14,1755,325],{},[65,1757,1759],{"className":67,"code":1758,"language":69,"meta":70,"style":70},"blue\n",[39,1760,1761],{"__ignoreMap":70},[74,1762,1763],{"class":76,"line":77},[74,1764,1758],{"class":279},[260,1766,1768],{"id":1767},"misspelling-variable-or-function-names","Misspelling variable or function names",[65,1770,1772],{"className":67,"code":1771,"language":69,"meta":70,"style":70},"message = \"Hello\"\nprint(mesage)\n",[39,1773,1774,1788],{"__ignoreMap":70},[74,1775,1776,1779,1781,1783,1786],{"class":76,"line":77},[74,1777,1778],{"class":279},"message ",[74,1780,284],{"class":283},[74,1782,580],{"class":88},[74,1784,1785],{"class":92},"Hello",[74,1787,947],{"class":88},[74,1789,1790,1792,1794,1797],{"class":76,"line":101},[74,1791,81],{"class":80},[74,1793,85],{"class":84},[74,1795,1796],{"class":118},"mesage",[74,1798,98],{"class":84},[14,1800,1801,1803,1804,1807],{},[39,1802,1796],{}," and ",[39,1805,1806],{},"message"," are different names.",[260,1809,1811,1812],{"id":1810},"forgetting-to-convert-input","Forgetting to convert ",[39,1813,645],{},[65,1815,1817],{"className":67,"code":1816,"language":69,"meta":70,"style":70},"age = input(\"Enter your age: \")\nprint(age + 1)\n",[39,1818,1819,1837],{"__ignoreMap":70},[74,1820,1821,1823,1825,1827,1829,1831,1833,1835],{"class":76,"line":77},[74,1822,806],{"class":279},[74,1824,284],{"class":283},[74,1826,512],{"class":80},[74,1828,85],{"class":84},[74,1830,351],{"class":88},[74,1832,519],{"class":92},[74,1834,351],{"class":88},[74,1836,98],{"class":84},[74,1838,1839,1841,1843,1845,1847,1850],{"class":76,"line":101},[74,1840,81],{"class":80},[74,1842,85],{"class":84},[74,1844,806],{"class":118},[74,1846,536],{"class":283},[74,1848,1849],{"class":290}," 1",[74,1851,98],{"class":84},[14,1853,1561,1854,1856],{},[39,1855,645],{}," returns a string.",[14,1858,1394],{},[65,1860,1862],{"className":67,"code":1861,"language":69,"meta":70,"style":70},"age = int(input(\"Enter your age: \"))\nprint(age + 1)\n",[39,1863,1864,1887],{"__ignoreMap":70},[74,1865,1866,1868,1870,1872,1874,1877,1879,1881,1883,1885],{"class":76,"line":77},[74,1867,806],{"class":279},[74,1869,284],{"class":283},[74,1871,1593],{"class":140},[74,1873,85],{"class":84},[74,1875,1876],{"class":80},"input",[74,1878,85],{"class":84},[74,1880,351],{"class":88},[74,1882,519],{"class":92},[74,1884,351],{"class":88},[74,1886,149],{"class":84},[74,1888,1889,1891,1893,1895,1897,1899],{"class":76,"line":101},[74,1890,81],{"class":80},[74,1892,85],{"class":84},[74,1894,806],{"class":118},[74,1896,536],{"class":283},[74,1898,1849],{"class":290},[74,1900,98],{"class":84},[14,1902,1903,1904,181],{},"If you want to handle bad user input safely, see ",[168,1905,1907,1908,1261,1911,1914],{"href":1906},"\u002Fhow-to\u002Fhow-to-use-try-except-blocks-in-python\u002F","how to use ",[39,1909,1910],{},"try",[39,1912,1913],{},"except"," blocks in Python",[54,1916,1918],{"id":1917},"when-there-is-no-error-but-the-result-is-wrong","When there is no error but the result is wrong",[14,1920,1921,1922,181],{},"Sometimes your code runs without crashing, but the answer is still wrong. This is called a ",[18,1923,1924],{},"logic bug",[260,1926,1928],{"id":1927},"print-intermediate-values","Print intermediate values",[14,1930,1931],{},"Check what happens step by step.",[65,1933,1935],{"className":67,"code":1934,"language":69,"meta":70,"style":70},"numbers = [1, 2, 3, 4]\ntotal = 0\n\nfor number in numbers:\n    total = number\n    print(\"number =\", number, \"total =\", total)\n\nprint(\"final total =\", total)\n",[39,1936,1937,1964,1973,1977,1993,2003,2037,2041],{"__ignoreMap":70},[74,1938,1939,1941,1943,1945,1947,1949,1952,1954,1957,1959,1962],{"class":76,"line":77},[74,1940,280],{"class":279},[74,1942,284],{"class":283},[74,1944,287],{"class":84},[74,1946,1697],{"class":290},[74,1948,115],{"class":84},[74,1950,1951],{"class":290}," 2",[74,1953,115],{"class":84},[74,1955,1956],{"class":290}," 3",[74,1958,115],{"class":84},[74,1960,1961],{"class":290}," 4",[74,1963,304],{"class":84},[74,1965,1966,1968,1970],{"class":76,"line":101},[74,1967,1058],{"class":279},[74,1969,284],{"class":283},[74,1971,1972],{"class":290}," 0\n",[74,1974,1975],{"class":76,"line":124},[74,1976,801],{"emptyLinePlaceholder":800},[74,1978,1979,1982,1985,1988,1991],{"class":76,"line":396},[74,1980,1981],{"class":576},"for",[74,1983,1984],{"class":279}," number ",[74,1986,1987],{"class":576},"in",[74,1989,1990],{"class":279}," numbers",[74,1992,849],{"class":84},[74,1994,1995,1998,2000],{"class":76,"line":829},[74,1996,1997],{"class":279},"    total ",[74,1999,284],{"class":283},[74,2001,2002],{"class":279}," number\n",[74,2004,2005,2007,2009,2011,2014,2016,2018,2021,2023,2025,2028,2030,2032,2035],{"class":76,"line":834},[74,2006,383],{"class":80},[74,2008,85],{"class":84},[74,2010,351],{"class":88},[74,2012,2013],{"class":92},"number =",[74,2015,351],{"class":88},[74,2017,115],{"class":84},[74,2019,2020],{"class":118}," number",[74,2022,115],{"class":84},[74,2024,580],{"class":88},[74,2026,2027],{"class":92},"total =",[74,2029,351],{"class":88},[74,2031,115],{"class":84},[74,2033,2034],{"class":118}," total",[74,2036,98],{"class":84},[74,2038,2039],{"class":76,"line":852},[74,2040,801],{"emptyLinePlaceholder":800},[74,2042,2043,2045,2047,2049,2052,2054,2056,2058],{"class":76,"line":868},[74,2044,81],{"class":80},[74,2046,85],{"class":84},[74,2048,351],{"class":88},[74,2050,2051],{"class":92},"final total =",[74,2053,351],{"class":88},[74,2055,115],{"class":84},[74,2057,2034],{"class":118},[74,2059,98],{"class":84},[14,2061,325],{},[65,2063,2065],{"className":67,"code":2064,"language":69,"meta":70,"style":70},"number = 1 total = 1\nnumber = 2 total = 2\nnumber = 3 total = 3\nnumber = 4 total = 4\nfinal total = 4\n",[39,2066,2067,2083,2097,2111,2126],{"__ignoreMap":70},[74,2068,2069,2072,2074,2076,2079,2081],{"class":76,"line":77},[74,2070,2071],{"class":279},"number ",[74,2073,284],{"class":283},[74,2075,1849],{"class":290},[74,2077,2078],{"class":279}," total ",[74,2080,284],{"class":283},[74,2082,1547],{"class":290},[74,2084,2085,2087,2089,2091,2093,2095],{"class":76,"line":101},[74,2086,2071],{"class":279},[74,2088,284],{"class":283},[74,2090,1951],{"class":290},[74,2092,2078],{"class":279},[74,2094,284],{"class":283},[74,2096,1201],{"class":290},[74,2098,2099,2101,2103,2105,2107,2109],{"class":76,"line":124},[74,2100,2071],{"class":279},[74,2102,284],{"class":283},[74,2104,1956],{"class":290},[74,2106,2078],{"class":279},[74,2108,284],{"class":283},[74,2110,957],{"class":290},[74,2112,2113,2115,2117,2119,2121,2123],{"class":76,"line":396},[74,2114,2071],{"class":279},[74,2116,284],{"class":283},[74,2118,1961],{"class":290},[74,2120,2078],{"class":279},[74,2122,284],{"class":283},[74,2124,2125],{"class":290}," 4\n",[74,2127,2128,2131,2133],{"class":76,"line":829},[74,2129,2130],{"class":279},"final total ",[74,2132,284],{"class":283},[74,2134,2125],{"class":290},[14,2136,2137,2138,2141],{},"If your goal was to add all numbers, the problem becomes clear: ",[39,2139,2140],{},"total = number"," replaces the total each time.",[14,2143,1394],{},[65,2145,2147],{"className":67,"code":2146,"language":69,"meta":70,"style":70},"numbers = [1, 2, 3, 4]\ntotal = 0\n\nfor number in numbers:\n    total = total + number\n    print(\"number =\", number, \"total =\", total)\n\nprint(\"final total =\", total)\n",[39,2148,2149,2173,2181,2185,2197,2209,2239,2243],{"__ignoreMap":70},[74,2150,2151,2153,2155,2157,2159,2161,2163,2165,2167,2169,2171],{"class":76,"line":77},[74,2152,280],{"class":279},[74,2154,284],{"class":283},[74,2156,287],{"class":84},[74,2158,1697],{"class":290},[74,2160,115],{"class":84},[74,2162,1951],{"class":290},[74,2164,115],{"class":84},[74,2166,1956],{"class":290},[74,2168,115],{"class":84},[74,2170,1961],{"class":290},[74,2172,304],{"class":84},[74,2174,2175,2177,2179],{"class":76,"line":101},[74,2176,1058],{"class":279},[74,2178,284],{"class":283},[74,2180,1972],{"class":290},[74,2182,2183],{"class":76,"line":124},[74,2184,801],{"emptyLinePlaceholder":800},[74,2186,2187,2189,2191,2193,2195],{"class":76,"line":396},[74,2188,1981],{"class":576},[74,2190,1984],{"class":279},[74,2192,1987],{"class":576},[74,2194,1990],{"class":279},[74,2196,849],{"class":84},[74,2198,2199,2201,2203,2205,2207],{"class":76,"line":829},[74,2200,1997],{"class":279},[74,2202,284],{"class":283},[74,2204,2078],{"class":279},[74,2206,536],{"class":283},[74,2208,2002],{"class":279},[74,2210,2211,2213,2215,2217,2219,2221,2223,2225,2227,2229,2231,2233,2235,2237],{"class":76,"line":834},[74,2212,383],{"class":80},[74,2214,85],{"class":84},[74,2216,351],{"class":88},[74,2218,2013],{"class":92},[74,2220,351],{"class":88},[74,2222,115],{"class":84},[74,2224,2020],{"class":118},[74,2226,115],{"class":84},[74,2228,580],{"class":88},[74,2230,2027],{"class":92},[74,2232,351],{"class":88},[74,2234,115],{"class":84},[74,2236,2034],{"class":118},[74,2238,98],{"class":84},[74,2240,2241],{"class":76,"line":852},[74,2242,801],{"emptyLinePlaceholder":800},[74,2244,2245,2247,2249,2251,2253,2255,2257,2259],{"class":76,"line":868},[74,2246,81],{"class":80},[74,2248,85],{"class":84},[74,2250,351],{"class":88},[74,2252,2051],{"class":92},[74,2254,351],{"class":88},[74,2256,115],{"class":84},[74,2258,2034],{"class":118},[74,2260,98],{"class":84},[14,2262,325],{},[65,2264,2266],{"className":67,"code":2265,"language":69,"meta":70,"style":70},"number = 1 total = 1\nnumber = 2 total = 3\nnumber = 3 total = 6\nnumber = 4 total = 10\nfinal total = 10\n",[39,2267,2268,2282,2296,2311,2325],{"__ignoreMap":70},[74,2269,2270,2272,2274,2276,2278,2280],{"class":76,"line":77},[74,2271,2071],{"class":279},[74,2273,284],{"class":283},[74,2275,1849],{"class":290},[74,2277,2078],{"class":279},[74,2279,284],{"class":283},[74,2281,1547],{"class":290},[74,2283,2284,2286,2288,2290,2292,2294],{"class":76,"line":101},[74,2285,2071],{"class":279},[74,2287,284],{"class":283},[74,2289,1951],{"class":290},[74,2291,2078],{"class":279},[74,2293,284],{"class":283},[74,2295,957],{"class":290},[74,2297,2298,2300,2302,2304,2306,2308],{"class":76,"line":124},[74,2299,2071],{"class":279},[74,2301,284],{"class":283},[74,2303,1956],{"class":290},[74,2305,2078],{"class":279},[74,2307,284],{"class":283},[74,2309,2310],{"class":290}," 6\n",[74,2312,2313,2315,2317,2319,2321,2323],{"class":76,"line":396},[74,2314,2071],{"class":279},[74,2316,284],{"class":283},[74,2318,1961],{"class":290},[74,2320,2078],{"class":279},[74,2322,284],{"class":283},[74,2324,1097],{"class":290},[74,2326,2327,2329,2331],{"class":76,"line":829},[74,2328,2130],{"class":279},[74,2330,284],{"class":283},[74,2332,1097],{"class":290},[260,2334,2336,2337,2339],{"id":2335},"check-loop-conditions-and-if-conditions","Check loop conditions and ",[39,2338,837],{}," conditions",[14,2341,2342],{},"If a block never runs, print the values being tested.",[65,2344,2346],{"className":67,"code":2345,"language":69,"meta":70,"style":70},"age = 17\nprint(\"age =\", age)\n\nif age > 18:\n    print(\"Adult\")\n",[39,2347,2348,2357,2377,2381,2393],{"__ignoreMap":70},[74,2349,2350,2352,2354],{"class":76,"line":77},[74,2351,806],{"class":279},[74,2353,284],{"class":283},[74,2355,2356],{"class":290}," 17\n",[74,2358,2359,2361,2363,2365,2368,2370,2372,2375],{"class":76,"line":101},[74,2360,81],{"class":80},[74,2362,85],{"class":84},[74,2364,351],{"class":88},[74,2366,2367],{"class":92},"age =",[74,2369,351],{"class":88},[74,2371,115],{"class":84},[74,2373,2374],{"class":118}," age",[74,2376,98],{"class":84},[74,2378,2379],{"class":76,"line":124},[74,2380,801],{"emptyLinePlaceholder":800},[74,2382,2383,2385,2387,2389,2391],{"class":76,"line":396},[74,2384,837],{"class":576},[74,2386,840],{"class":279},[74,2388,843],{"class":283},[74,2390,846],{"class":290},[74,2392,849],{"class":84},[74,2394,2395,2397,2399,2401,2403,2405],{"class":76,"line":829},[74,2396,383],{"class":80},[74,2398,85],{"class":84},[74,2400,351],{"class":88},[74,2402,1381],{"class":92},[74,2404,351],{"class":88},[74,2406,98],{"class":84},[14,2408,2409,2410,2413],{},"Now you can clearly see why ",[39,2411,2412],{},"\"Adult\""," is not printed.",[260,2415,2417],{"id":2416},"test-with-small-sample-data","Test with small sample data",[14,2419,2420],{},"If your program is hard to follow, use a very small example first.",[14,2422,2423],{},"Instead of testing with 1,000 items, test with 2 or 3.",[14,2425,2426],{},"This makes it easier to see where the logic goes wrong.",[260,2428,2430],{"id":2429},"compare-expected-output-with-actual-output","Compare expected output with actual output",[14,2432,2433],{},"Ask yourself:",[26,2435,2436,2439,2442],{},[29,2437,2438],{},"What result did I expect?",[29,2440,2441],{},"What result did I get?",[29,2443,2444],{},"At which step do they become different?",[14,2446,2447],{},"That helps you focus on the real problem.",[54,2449,2451],{"id":2450},"how-to-make-bugs-easier-to-find","How to make bugs easier to find",[14,2453,2454],{},"You cannot avoid every bug, but you can make them easier to debug.",[260,2456,2458],{"id":2457},"write-small-functions","Write small functions",[14,2460,2461],{},"Small functions are easier to test than one large block of code.",[14,2463,2464],{},"Instead of writing everything together:",[65,2466,2468],{"className":67,"code":2467,"language":69,"meta":70,"style":70},"name = input(\"Enter your name: \")\nname = name.strip()\nname = name.title()\nprint(\"Hello\", name)\n",[39,2469,2470,2489,2506,2521],{"__ignoreMap":70},[74,2471,2472,2474,2476,2478,2480,2482,2485,2487],{"class":76,"line":77},[74,2473,507],{"class":279},[74,2475,284],{"class":283},[74,2477,512],{"class":80},[74,2479,85],{"class":84},[74,2481,351],{"class":88},[74,2483,2484],{"class":92},"Enter your name: ",[74,2486,351],{"class":88},[74,2488,98],{"class":84},[74,2490,2491,2493,2495,2498,2500,2503],{"class":76,"line":101},[74,2492,507],{"class":279},[74,2494,284],{"class":283},[74,2496,2497],{"class":279}," name",[74,2499,181],{"class":84},[74,2501,2502],{"class":118},"strip",[74,2504,2505],{"class":84},"()\n",[74,2507,2508,2510,2512,2514,2516,2519],{"class":76,"line":124},[74,2509,507],{"class":279},[74,2511,284],{"class":283},[74,2513,2497],{"class":279},[74,2515,181],{"class":84},[74,2517,2518],{"class":118},"title",[74,2520,2505],{"class":84},[74,2522,2523,2525,2527,2529,2531,2533,2535,2537],{"class":76,"line":396},[74,2524,81],{"class":80},[74,2526,85],{"class":84},[74,2528,351],{"class":88},[74,2530,1785],{"class":92},[74,2532,351],{"class":88},[74,2534,115],{"class":84},[74,2536,2497],{"class":118},[74,2538,98],{"class":84},[14,2540,2541],{},"You can separate the work:",[65,2543,2545],{"className":67,"code":2544,"language":69,"meta":70,"style":70},"def clean_name(text):\n    return text.strip().title()\n\nname = input(\"Enter your name: \")\ncleaned = clean_name(name)\nprint(\"Hello\", cleaned)\n",[39,2546,2547,2564,2583,2587,2605,2621],{"__ignoreMap":70},[74,2548,2549,2552,2556,2558,2562],{"class":76,"line":77},[74,2550,2551],{"class":1120},"def",[74,2553,2555],{"class":2554},"sGLFI"," clean_name",[74,2557,85],{"class":84},[74,2559,2561],{"class":2560},"sFwrP","text",[74,2563,343],{"class":84},[74,2565,2566,2569,2572,2574,2576,2579,2581],{"class":76,"line":101},[74,2567,2568],{"class":576},"    return",[74,2570,2571],{"class":279}," text",[74,2573,181],{"class":84},[74,2575,2502],{"class":118},[74,2577,2578],{"class":84},"().",[74,2580,2518],{"class":118},[74,2582,2505],{"class":84},[74,2584,2585],{"class":76,"line":124},[74,2586,801],{"emptyLinePlaceholder":800},[74,2588,2589,2591,2593,2595,2597,2599,2601,2603],{"class":76,"line":396},[74,2590,507],{"class":279},[74,2592,284],{"class":283},[74,2594,512],{"class":80},[74,2596,85],{"class":84},[74,2598,351],{"class":88},[74,2600,2484],{"class":92},[74,2602,351],{"class":88},[74,2604,98],{"class":84},[74,2606,2607,2610,2612,2614,2616,2619],{"class":76,"line":829},[74,2608,2609],{"class":279},"cleaned ",[74,2611,284],{"class":283},[74,2613,2555],{"class":118},[74,2615,85],{"class":84},[74,2617,2618],{"class":118},"name",[74,2620,98],{"class":84},[74,2622,2623,2625,2627,2629,2631,2633,2635,2638],{"class":76,"line":834},[74,2624,81],{"class":80},[74,2626,85],{"class":84},[74,2628,351],{"class":88},[74,2630,1785],{"class":92},[74,2632,351],{"class":88},[74,2634,115],{"class":84},[74,2636,2637],{"class":118}," cleaned",[74,2639,98],{"class":84},[14,2641,2642,2643,2646],{},"Now, if something goes wrong, you can test ",[39,2644,2645],{},"clean_name()"," by itself.",[260,2648,2650],{"id":2649},"use-clear-variable-names","Use clear variable names",[14,2652,2653],{},"This is easier to debug:",[65,2655,2657],{"className":67,"code":2656,"language":69,"meta":70,"style":70},"student_age = 16\n",[39,2658,2659],{"__ignoreMap":70},[74,2660,2661,2664,2666],{"class":76,"line":77},[74,2662,2663],{"class":279},"student_age ",[74,2665,284],{"class":283},[74,2667,2668],{"class":290}," 16\n",[14,2670,1268],{},[65,2672,2674],{"className":67,"code":2673,"language":69,"meta":70,"style":70},"x = 16\n",[39,2675,2676],{"__ignoreMap":70},[74,2677,2678,2680,2682],{"class":76,"line":77},[74,2679,1186],{"class":279},[74,2681,284],{"class":283},[74,2683,2668],{"class":290},[14,2685,2686],{},"Clear names make your code easier to read and easier to fix.",[260,2688,2690],{"id":2689},"test-one-part-at-a-time","Test one part at a time",[14,2692,2693],{},"If your program reads a file, processes data, and prints a result, test each part separately.",[14,2695,2696],{},"That way you can find which part is failing.",[260,2698,2700],{"id":2699},"keep-code-simple-before-adding-features","Keep code simple before adding features",[14,2702,2703],{},"Start with a small working version first.",[14,2705,2706],{},"Then add one feature at a time and test after each change.",[54,2708,2710],{"id":2709},"when-to-use-a-debugger-tool-later","When to use a debugger tool later",[14,2712,2713],{},"Beginners do not need to start with advanced tools.",[14,2715,2716,2718],{},[39,2717,41],{}," debugging is enough for many problems because it helps you learn the core process:",[26,2720,2721,2724,2727,2730],{},[29,2722,2723],{},"observe the problem",[29,2725,2726],{},"inspect values",[29,2728,2729],{},"test a small change",[29,2731,2732],{},"run the code again",[14,2734,2735],{},"Later, you can learn debugger tools in an IDE. These tools let you:",[26,2737,2738,2741,2744],{},[29,2739,2740],{},"pause code while it runs",[29,2742,2743],{},"inspect variables",[29,2745,2746],{},"step through the program line by line",[14,2748,2749],{},"That can be very helpful, but it works best after you already understand basic debugging.",[54,2751,2753],{"id":2752},"common-mistakes-when-debugging","Common mistakes when debugging",[14,2755,2756],{},"These habits make debugging harder:",[26,2758,2759,2769,2779,2789,2802,2812],{},[29,2760,2761,2764],{},[18,2762,2763],{},"Not reading the full error message",[26,2765,2766],{},[29,2767,2768],{},"The traceback often tells you exactly where to look.",[29,2770,2771,2774],{},[18,2772,2773],{},"Changing many lines at once",[26,2775,2776],{},[29,2777,2778],{},"If the code starts working, you will not know what fixed it.",[29,2780,2781,2784],{},[18,2782,2783],{},"Assuming a variable has the value you expect",[26,2785,2786],{},[29,2787,2788],{},"Print it and check.",[29,2790,2791,2796],{},[18,2792,2793,2794],{},"Forgetting type conversion after ",[39,2795,645],{},[26,2797,2798],{},[29,2799,2800,1856],{},[39,2801,645],{},[29,2803,2804,2807],{},[18,2805,2806],{},"Using data from a file or API without checking its format",[26,2808,2809],{},[29,2810,2811],{},"Print the data and inspect it before using it.",[29,2813,2814,2817],{},[18,2815,2816],{},"Trying to fix code by guessing",[26,2818,2819],{},[29,2820,2821],{},"Use a process instead.",[54,2823,2825],{"id":2824},"useful-debugging-commands","Useful debugging commands",[14,2827,2828],{},"These simple commands are helpful when checking your code:",[65,2830,2832],{"className":67,"code":2831,"language":69,"meta":70,"style":70},"print(variable)\nprint(type(variable))\nprint('checkpoint')\nhelp(function_name)\ndir(object_name)\n",[39,2833,2834,2845,2859,2874,2886],{"__ignoreMap":70},[74,2835,2836,2838,2840,2843],{"class":76,"line":77},[74,2837,81],{"class":80},[74,2839,85],{"class":84},[74,2841,2842],{"class":118},"variable",[74,2844,98],{"class":84},[74,2846,2847,2849,2851,2853,2855,2857],{"class":76,"line":101},[74,2848,81],{"class":80},[74,2850,85],{"class":84},[74,2852,1110],{"class":140},[74,2854,85],{"class":84},[74,2856,2842],{"class":118},[74,2858,149],{"class":84},[74,2860,2861,2863,2865,2867,2870,2872],{"class":76,"line":124},[74,2862,81],{"class":80},[74,2864,85],{"class":84},[74,2866,89],{"class":88},[74,2868,2869],{"class":92},"checkpoint",[74,2871,89],{"class":88},[74,2873,98],{"class":84},[74,2875,2876,2879,2881,2884],{"class":76,"line":396},[74,2877,2878],{"class":80},"help",[74,2880,85],{"class":84},[74,2882,2883],{"class":118},"function_name",[74,2885,98],{"class":84},[74,2887,2888,2891,2893,2896],{"class":76,"line":829},[74,2889,2890],{"class":80},"dir",[74,2892,85],{"class":84},[74,2894,2895],{"class":118},"object_name",[74,2897,98],{"class":84},[14,2899,2900],{},"What they do:",[26,2902,2903,2909,2915,2921,2927],{},[29,2904,2905,2908],{},[39,2906,2907],{},"print(variable)"," shows the current value",[29,2910,2911,2914],{},[39,2912,2913],{},"print(type(variable))"," shows the data type",[29,2916,2917,2920],{},[39,2918,2919],{},"print('checkpoint')"," confirms a line ran",[29,2922,2923,2926],{},[39,2924,2925],{},"help(function_name)"," shows built-in help for a function",[29,2928,2929,2932],{},[39,2930,2931],{},"dir(object_name)"," shows available attributes and methods",[14,2934,497],{},[65,2936,2938],{"className":67,"code":2937,"language":69,"meta":70,"style":70},"text = \"hello\"\n\nprint(text)\nprint(type(text))\nprint(dir(text))\n",[39,2939,2940,2954,2958,2968,2982],{"__ignoreMap":70},[74,2941,2942,2945,2947,2949,2952],{"class":76,"line":77},[74,2943,2944],{"class":279},"text ",[74,2946,284],{"class":283},[74,2948,580],{"class":88},[74,2950,2951],{"class":92},"hello",[74,2953,947],{"class":88},[74,2955,2956],{"class":76,"line":101},[74,2957,801],{"emptyLinePlaceholder":800},[74,2959,2960,2962,2964,2966],{"class":76,"line":124},[74,2961,81],{"class":80},[74,2963,85],{"class":84},[74,2965,2561],{"class":118},[74,2967,98],{"class":84},[74,2969,2970,2972,2974,2976,2978,2980],{"class":76,"line":396},[74,2971,81],{"class":80},[74,2973,85],{"class":84},[74,2975,1110],{"class":140},[74,2977,85],{"class":84},[74,2979,2561],{"class":118},[74,2981,149],{"class":84},[74,2983,2984,2986,2988,2990,2992,2994],{"class":76,"line":829},[74,2985,81],{"class":80},[74,2987,85],{"class":84},[74,2989,2890],{"class":80},[74,2991,85],{"class":84},[74,2993,2561],{"class":118},[74,2995,149],{"class":84},[54,2997,2999],{"id":2998},"faq","FAQ",[260,3001,3003],{"id":3002},"what-is-the-easiest-way-to-debug-python-code","What is the easiest way to debug Python code?",[14,3005,3006,3007,3009],{},"Start by reading the error message, then use ",[39,3008,41],{}," to check which lines run and what values your variables have.",[260,3011,3013],{"id":3012},"why-is-my-python-code-wrong-even-without-an-error","Why is my Python code wrong even without an error?",[14,3015,3016],{},"Your code may have a logic bug. Print intermediate values and compare the actual result with the result you expected.",[260,3018,3020,3021,3023],{"id":3019},"should-beginners-use-a-debugger-or-print","Should beginners use a debugger or ",[39,3022,41],{},"?",[14,3025,3026,3027,3029],{},"Start with ",[39,3028,41],{}," because it is simple and works everywhere. Later, you can learn an IDE debugger.",[260,3031,3033],{"id":3032},"what-should-i-check-first-in-a-traceback","What should I check first in a traceback?",[14,3035,3036],{},"Check the last line for the error type, then look at the line number and the code around that line.",[54,3038,3040],{"id":3039},"see-also","See also",[26,3042,3043,3047,3056,3062,3068,3077,3083],{},[29,3044,3045],{},[168,3046,251],{"href":250},[29,3048,3049],{},[168,3050,3051,3052,1261,3054,1914],{"href":1906},"How to use ",[39,3053,1910],{},[39,3055,1913],{},[29,3057,3058],{},[168,3059,3060,173],{"href":170},[39,3061,41],{},[29,3063,3064],{},[168,3065,3066,173],{"href":177},[39,3067,180],{},[29,3069,3070],{},[168,3071,3073,3074],{"href":3072},"\u002Ferrors\u002Fsyntaxerror-invalid-syntax-fix","Fix ",[39,3075,3076],{},"SyntaxError: invalid syntax",[29,3078,3079],{},[168,3080,3073,3081],{"href":1508},[39,3082,1511],{},[29,3084,3085],{},[168,3086,3073,3087],{"href":440},[39,3088,444],{},[3090,3091,3092],"style",{},"html pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sVHd0, html code.shiki .sVHd0{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#D73A49;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit}html pre.shiki code .sbsja, html code.shiki .sbsja{--shiki-light:#9C3EDA;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sGLFI, html code.shiki .sGLFI{--shiki-light:#6182B8;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sFwrP, html code.shiki .sFwrP{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#24292E;--shiki-default-font-style:inherit;--shiki-dark:#E1E4E8;--shiki-dark-font-style:inherit}",{"title":70,"searchDepth":101,"depth":101,"links":3094},[3095,3096,3097,3098,3103,3104,3110,3119,3126,3132,3133,3134,3135,3142],{"id":56,"depth":101,"text":57},{"id":184,"depth":101,"text":185},{"id":207,"depth":101,"text":208},{"id":254,"depth":101,"text":255,"children":3099},[3100,3101,3102],{"id":262,"depth":124,"text":263},{"id":447,"depth":124,"text":448},{"id":490,"depth":124,"text":491},{"id":655,"depth":101,"text":656},{"id":745,"depth":101,"text":3105,"children":3106},"Use print() to inspect your code",[3107,3108,3109],{"id":774,"depth":124,"text":775},{"id":927,"depth":124,"text":928},{"id":1172,"depth":124,"text":1173},{"id":1330,"depth":101,"text":1331,"children":3111},[3112,3113,3114,3115,3116,3117],{"id":1337,"depth":124,"text":1338},{"id":1440,"depth":124,"text":1441},{"id":1514,"depth":124,"text":1515},{"id":1629,"depth":124,"text":1630},{"id":1767,"depth":124,"text":1768},{"id":1810,"depth":124,"text":3118},"Forgetting to convert input()",{"id":1917,"depth":101,"text":1918,"children":3120},[3121,3122,3124,3125],{"id":1927,"depth":124,"text":1928},{"id":2335,"depth":124,"text":3123},"Check loop conditions and if conditions",{"id":2416,"depth":124,"text":2417},{"id":2429,"depth":124,"text":2430},{"id":2450,"depth":101,"text":2451,"children":3127},[3128,3129,3130,3131],{"id":2457,"depth":124,"text":2458},{"id":2649,"depth":124,"text":2650},{"id":2689,"depth":124,"text":2690},{"id":2699,"depth":124,"text":2700},{"id":2709,"depth":101,"text":2710},{"id":2752,"depth":101,"text":2753},{"id":2824,"depth":101,"text":2825},{"id":2998,"depth":101,"text":2999,"children":3136},[3137,3138,3139,3141],{"id":3002,"depth":124,"text":3003},{"id":3012,"depth":124,"text":3013},{"id":3019,"depth":124,"text":3140},"Should beginners use a debugger or print()?",{"id":3032,"depth":124,"text":3033},{"id":3039,"depth":101,"text":3040},"Master how to debug python code beginner guide in our comprehensive Python beginner guide.","md",{},"\u002Fhow-to\u002Fhow-to-debug-python-code-beginner-guide",{"title":5,"description":3143},"how-to\u002Fhow-to-debug-python-code-beginner-guide","gbux2Ns-4LZj2EOKnA8qlk-30lk8_QJsNZxuxYEVSmI",1777585503279]