[{"data":1,"prerenderedAt":2114},["ShallowReactive",2],{"doc-\u002Ferrors\u002Fvalueerror-when-parsing-input-in-python-fix":3},{"id":4,"title":5,"body":6,"description":2107,"extension":2108,"meta":2109,"navigation":115,"path":2110,"seo":2111,"stem":2112,"__hash__":2113},"content\u002Ferrors\u002Fvalueerror-when-parsing-input-in-python-fix.md","ValueError when parsing input in Python (Fix)",{"type":7,"value":8,"toc":2078},"minimark",[9,13,25,36,39,55,60,197,213,217,222,225,244,247,270,279,283,286,345,348,355,382,385,394,397,439,454,458,461,467,557,560,581,586,676,683,687,692,699,800,803,820,828,848,856,860,863,868,953,956,973,976,1098,1101,1112,1115,1119,1122,1241,1244,1255,1265,1269,1275,1282,1307,1317,1323,1347,1352,1371,1376,1379,1387,1393,1442,1445,1448,1469,1475,1489,1493,1496,1499,1569,1576,1587,1589,1641,1647,1696,1699,1703,1706,1711,1728,1733,1750,1752,1821,1827,1829,1920,1928,1932,1935,1960,1964,1972,1989,1996,2003,2013,2021,2028,2034,2038,2074],[10,11,5],"h1",{"id":12},"valueerror-when-parsing-input-in-python-fix",[14,15,16,20,21,24],"p",{},[17,18,19],"code",{},"ValueError"," often happens when your program reads text with ",[17,22,23],{},"input()"," and then tries to convert that text into a number.",[14,26,27,28,31,32,35],{},"This usually affects code that uses ",[17,29,30],{},"int()"," or ",[17,33,34],{},"float()",". For example, the user might type letters instead of digits, leave the input blank, or enter a decimal when your code expects a whole number.",[14,37,38],{},"This page shows:",[40,41,42,46,49,52],"ul",{},[43,44,45],"li",{},"what the error means",[43,47,48],{},"how to reproduce it",[43,50,51],{},"simple ways to fix it",[43,53,54],{},"how to prevent it in beginner-friendly code",[56,57,59],"h2",{"id":58},"quick-fix","Quick fix",[61,62,67],"pre",{"className":63,"code":64,"language":65,"meta":66,"style":66},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","user_text = input(\"Enter a number: \").strip()\n\ntry:\n    number = int(user_text)\n    print(\"You entered:\", number)\nexcept ValueError:\n    print(\"Please enter a whole number only.\")\n","python","",[17,68,69,110,117,127,147,170,181],{"__ignoreMap":66},[70,71,74,78,82,86,90,94,98,100,103,107],"span",{"class":72,"line":73},"line",1,[70,75,77],{"class":76},"su5hD","user_text ",[70,79,81],{"class":80},"smGrS","=",[70,83,85],{"class":84},"sptTA"," input",[70,87,89],{"class":88},"sP7_E","(",[70,91,93],{"class":92},"sjJ54","\"",[70,95,97],{"class":96},"s_sjI","Enter a number: ",[70,99,93],{"class":92},[70,101,102],{"class":88},").",[70,104,106],{"class":105},"slqww","strip",[70,108,109],{"class":88},"()\n",[70,111,113],{"class":72,"line":112},2,[70,114,116],{"emptyLinePlaceholder":115},true,"\n",[70,118,120,124],{"class":72,"line":119},3,[70,121,123],{"class":122},"sVHd0","try",[70,125,126],{"class":88},":\n",[70,128,130,133,135,139,141,144],{"class":72,"line":129},4,[70,131,132],{"class":76},"    number ",[70,134,81],{"class":80},[70,136,138],{"class":137},"sZMiF"," int",[70,140,89],{"class":88},[70,142,143],{"class":105},"user_text",[70,145,146],{"class":88},")\n",[70,148,150,153,155,157,160,162,165,168],{"class":72,"line":149},5,[70,151,152],{"class":84},"    print",[70,154,89],{"class":88},[70,156,93],{"class":92},[70,158,159],{"class":96},"You entered:",[70,161,93],{"class":92},[70,163,164],{"class":88},",",[70,166,167],{"class":105}," number",[70,169,146],{"class":88},[70,171,173,176,179],{"class":72,"line":172},6,[70,174,175],{"class":122},"except",[70,177,178],{"class":137}," ValueError",[70,180,126],{"class":88},[70,182,184,186,188,190,193,195],{"class":72,"line":183},7,[70,185,152],{"class":84},[70,187,89],{"class":88},[70,189,93],{"class":92},[70,191,192],{"class":96},"Please enter a whole number only.",[70,194,93],{"class":92},[70,196,146],{"class":88},[14,198,199,200,203,204,31,206,208,209,212],{},"Use ",[17,201,202],{},"try-except"," when converting input with ",[17,205,30],{},[17,207,34],{},". ",[17,210,211],{},"strip()"," also helps remove accidental spaces.",[56,214,216],{"id":215},"what-this-error-means","What this error means",[14,218,219,221],{},[17,220,19],{}," means Python received a value of the correct general type, but the content is not valid for the operation.",[14,223,224],{},"When parsing input, this often happens when you try to:",[40,226,227,232,237],{},[43,228,229,230],{},"convert text to an integer with ",[17,231,30],{},[43,233,234,235],{},"convert text to a decimal number with ",[17,236,34],{},[43,238,239,240,243],{},"unpack values from ",[17,241,242],{},"split()"," and the number of parts is wrong",[14,245,246],{},"Common examples:",[40,248,249,254,259,264],{},[43,250,251],{},[17,252,253],{},"int(\"abc\")",[43,255,256],{},[17,257,258],{},"int(\"\")",[43,260,261],{},[17,262,263],{},"float(\"\")",[43,265,266,269],{},[17,267,268],{},"a, b = input().split()"," when the input does not contain exactly two parts",[14,271,272,273,278],{},"If you are new to exceptions, see ",[274,275,277],"a",{"href":276},"\u002Flearn\u002Fpython-errors-and-exceptions-explained\u002F","Python errors and exceptions explained",".",[56,280,282],{"id":281},"common-example-that-causes-the-error","Common example that causes the error",[14,284,285],{},"A very common beginner pattern is this:",[61,287,289],{"className":63,"code":288,"language":65,"meta":66,"style":66},"age = int(input(\"Enter your age: \"))\nprint(\"Next year you will be\", age + 1)\n",[17,290,291,317],{"__ignoreMap":66},[70,292,293,296,298,300,302,305,307,309,312,314],{"class":72,"line":73},[70,294,295],{"class":76},"age ",[70,297,81],{"class":80},[70,299,138],{"class":137},[70,301,89],{"class":88},[70,303,304],{"class":84},"input",[70,306,89],{"class":88},[70,308,93],{"class":92},[70,310,311],{"class":96},"Enter your age: ",[70,313,93],{"class":92},[70,315,316],{"class":88},"))\n",[70,318,319,322,324,326,329,331,333,336,339,343],{"class":72,"line":112},[70,320,321],{"class":84},"print",[70,323,89],{"class":88},[70,325,93],{"class":92},[70,327,328],{"class":96},"Next year you will be",[70,330,93],{"class":92},[70,332,164],{"class":88},[70,334,335],{"class":105}," age ",[70,337,338],{"class":80},"+",[70,340,342],{"class":341},"srdBf"," 1",[70,344,146],{"class":88},[14,346,347],{},"This works only if the user enters a valid whole number.",[14,349,350,351,354],{},"If the user types ",[17,352,353],{},"hello",", Python raises an error:",[61,356,358],{"className":63,"code":357,"language":65,"meta":66,"style":66},"age = int(input(\"Enter your age: \"))\n",[17,359,360],{"__ignoreMap":66},[70,361,362,364,366,368,370,372,374,376,378,380],{"class":72,"line":73},[70,363,295],{"class":76},[70,365,81],{"class":80},[70,367,138],{"class":137},[70,369,89],{"class":88},[70,371,304],{"class":84},[70,373,89],{"class":88},[70,375,93],{"class":92},[70,377,311],{"class":96},[70,379,93],{"class":92},[70,381,316],{"class":88},[14,383,384],{},"Example input:",[61,386,388],{"className":63,"code":387,"language":65,"meta":66,"style":66},"hello\n",[17,389,390],{"__ignoreMap":66},[70,391,392],{"class":72,"line":73},[70,393,387],{"class":76},[14,395,396],{},"Typical error message:",[61,398,400],{"className":63,"code":399,"language":65,"meta":66,"style":66},"ValueError: invalid literal for int() with base 10: 'hello'\n",[17,401,402],{"__ignoreMap":66},[70,403,404,406,409,412,415,417,420,423,426,429,431,434,436],{"class":72,"line":73},[70,405,19],{"class":137},[70,407,408],{"class":88},":",[70,410,411],{"class":76}," invalid literal ",[70,413,414],{"class":122},"for",[70,416,138],{"class":137},[70,418,419],{"class":88},"()",[70,421,422],{"class":122}," with",[70,424,425],{"class":76}," base ",[70,427,428],{"class":341},"10",[70,430,408],{"class":88},[70,432,433],{"class":92}," '",[70,435,353],{"class":96},[70,437,438],{"class":92},"'\n",[14,440,441,442,444,445,449,450,278],{},"That happens because ",[17,443,23],{}," always returns a string. If you want to learn more about that, see ",[274,446,448],{"href":447},"\u002Freference\u002Fpython-input-function-explained\u002F","Python input() function explained"," and ",[274,451,453],{"href":452},"\u002Freference\u002Fpython-int-function-explained\u002F","Python int() function explained",[56,455,457],{"id":456},"fix-1-use-try-except-around-the-conversion","Fix 1: Use try-except around the conversion",[14,459,460],{},"This is the best fix when input comes from a real user.",[14,462,463,464,466],{},"Wrap the conversion in a ",[17,465,202],{}," block so your program does not crash.",[61,468,470],{"className":63,"code":469,"language":65,"meta":66,"style":66},"user_text = input(\"Enter a whole number: \")\n\ntry:\n    number = int(user_text)\n    print(\"Valid number:\", number)\nexcept ValueError:\n    print(\"That was not a valid whole number.\")\n",[17,471,472,491,495,501,515,534,542],{"__ignoreMap":66},[70,473,474,476,478,480,482,484,487,489],{"class":72,"line":73},[70,475,77],{"class":76},[70,477,81],{"class":80},[70,479,85],{"class":84},[70,481,89],{"class":88},[70,483,93],{"class":92},[70,485,486],{"class":96},"Enter a whole number: ",[70,488,93],{"class":92},[70,490,146],{"class":88},[70,492,493],{"class":72,"line":112},[70,494,116],{"emptyLinePlaceholder":115},[70,496,497,499],{"class":72,"line":119},[70,498,123],{"class":122},[70,500,126],{"class":88},[70,502,503,505,507,509,511,513],{"class":72,"line":129},[70,504,132],{"class":76},[70,506,81],{"class":80},[70,508,138],{"class":137},[70,510,89],{"class":88},[70,512,143],{"class":105},[70,514,146],{"class":88},[70,516,517,519,521,523,526,528,530,532],{"class":72,"line":149},[70,518,152],{"class":84},[70,520,89],{"class":88},[70,522,93],{"class":92},[70,524,525],{"class":96},"Valid number:",[70,527,93],{"class":92},[70,529,164],{"class":88},[70,531,167],{"class":105},[70,533,146],{"class":88},[70,535,536,538,540],{"class":72,"line":172},[70,537,175],{"class":122},[70,539,178],{"class":137},[70,541,126],{"class":88},[70,543,544,546,548,550,553,555],{"class":72,"line":183},[70,545,152],{"class":84},[70,547,89],{"class":88},[70,549,93],{"class":92},[70,551,552],{"class":96},"That was not a valid whole number.",[70,554,93],{"class":92},[70,556,146],{"class":88},[14,558,559],{},"What this does:",[40,561,562,568,578],{},[43,563,564,567],{},[17,565,566],{},"try:"," runs the risky code",[43,569,570,571,574,575],{},"if ",[17,572,573],{},"int(user_text)"," fails, Python jumps to ",[17,576,577],{},"except ValueError:",[43,579,580],{},"your program prints a helpful message instead of stopping",[14,582,583,584,408],{},"You can do the same with ",[17,585,34],{},[61,587,589],{"className":63,"code":588,"language":65,"meta":66,"style":66},"user_text = input(\"Enter a decimal number: \")\n\ntry:\n    number = float(user_text)\n    print(\"Valid number:\", number)\nexcept ValueError:\n    print(\"Please enter a valid number.\")\n",[17,590,591,610,614,620,635,653,661],{"__ignoreMap":66},[70,592,593,595,597,599,601,603,606,608],{"class":72,"line":73},[70,594,77],{"class":76},[70,596,81],{"class":80},[70,598,85],{"class":84},[70,600,89],{"class":88},[70,602,93],{"class":92},[70,604,605],{"class":96},"Enter a decimal number: ",[70,607,93],{"class":92},[70,609,146],{"class":88},[70,611,612],{"class":72,"line":112},[70,613,116],{"emptyLinePlaceholder":115},[70,615,616,618],{"class":72,"line":119},[70,617,123],{"class":122},[70,619,126],{"class":88},[70,621,622,624,626,629,631,633],{"class":72,"line":129},[70,623,132],{"class":76},[70,625,81],{"class":80},[70,627,628],{"class":137}," float",[70,630,89],{"class":88},[70,632,143],{"class":105},[70,634,146],{"class":88},[70,636,637,639,641,643,645,647,649,651],{"class":72,"line":149},[70,638,152],{"class":84},[70,640,89],{"class":88},[70,642,93],{"class":92},[70,644,525],{"class":96},[70,646,93],{"class":92},[70,648,164],{"class":88},[70,650,167],{"class":105},[70,652,146],{"class":88},[70,654,655,657,659],{"class":72,"line":172},[70,656,175],{"class":122},[70,658,178],{"class":137},[70,660,126],{"class":88},[70,662,663,665,667,669,672,674],{"class":72,"line":183},[70,664,152],{"class":84},[70,666,89],{"class":88},[70,668,93],{"class":92},[70,670,671],{"class":96},"Please enter a valid number.",[70,673,93],{"class":92},[70,675,146],{"class":88},[14,677,678,679,278],{},"If you want more practice with this pattern, see ",[274,680,682],{"href":681},"\u002Fhow-to\u002Fhow-to-use-try-except-blocks-in-python\u002F","how to use try-except blocks in Python",[56,684,686],{"id":685},"fix-2-validate-input-before-converting","Fix 2: Validate input before converting",[14,688,689,690,278],{},"Sometimes you want to reject bad input before calling ",[17,691,30],{},[14,693,694,695,698],{},"For simple positive integers, ",[17,696,697],{},"isdigit()"," can help:",[61,700,702],{"className":63,"code":701,"language":65,"meta":66,"style":66},"user_text = input(\"Enter a whole number: \").strip()\n\nif user_text.isdigit():\n    number = int(user_text)\n    print(\"Valid number:\", number)\nelse:\n    print(\"Please enter digits only.\")\n",[17,703,704,726,730,746,760,778,785],{"__ignoreMap":66},[70,705,706,708,710,712,714,716,718,720,722,724],{"class":72,"line":73},[70,707,77],{"class":76},[70,709,81],{"class":80},[70,711,85],{"class":84},[70,713,89],{"class":88},[70,715,93],{"class":92},[70,717,486],{"class":96},[70,719,93],{"class":92},[70,721,102],{"class":88},[70,723,106],{"class":105},[70,725,109],{"class":88},[70,727,728],{"class":72,"line":112},[70,729,116],{"emptyLinePlaceholder":115},[70,731,732,735,738,740,743],{"class":72,"line":119},[70,733,734],{"class":122},"if",[70,736,737],{"class":76}," user_text",[70,739,278],{"class":88},[70,741,742],{"class":105},"isdigit",[70,744,745],{"class":88},"():\n",[70,747,748,750,752,754,756,758],{"class":72,"line":129},[70,749,132],{"class":76},[70,751,81],{"class":80},[70,753,138],{"class":137},[70,755,89],{"class":88},[70,757,143],{"class":105},[70,759,146],{"class":88},[70,761,762,764,766,768,770,772,774,776],{"class":72,"line":149},[70,763,152],{"class":84},[70,765,89],{"class":88},[70,767,93],{"class":92},[70,769,525],{"class":96},[70,771,93],{"class":92},[70,773,164],{"class":88},[70,775,167],{"class":105},[70,777,146],{"class":88},[70,779,780,783],{"class":72,"line":172},[70,781,782],{"class":122},"else",[70,784,126],{"class":88},[70,786,787,789,791,793,796,798],{"class":72,"line":183},[70,788,152],{"class":84},[70,790,89],{"class":88},[70,792,93],{"class":92},[70,794,795],{"class":96},"Please enter digits only.",[70,797,93],{"class":92},[70,799,146],{"class":88},[14,801,802],{},"This works for values like:",[40,804,805,810,815],{},[43,806,807],{},[17,808,809],{},"\"5\"",[43,811,812],{},[17,813,814],{},"\"42\"",[43,816,817],{},[17,818,819],{},"\"123\"",[14,821,822,823,827],{},"But it does ",[824,825,826],"strong",{},"not"," work for:",[40,829,830,836,842],{},[43,831,832,833],{},"negative numbers like ",[17,834,835],{},"\"-5\"",[43,837,838,839],{},"decimals like ",[17,840,841],{},"\"3.14\"",[43,843,844,845],{},"empty strings like ",[17,846,847],{},"\"\"",[14,849,850,851,853,854,278],{},"So ",[17,852,697],{}," is useful for simple checks, but it is not a complete replacement for ",[17,855,202],{},[56,857,859],{"id":858},"fix-3-clean-the-input-first","Fix 3: Clean the input first",[14,861,862],{},"Sometimes the text is almost correct, but it contains spaces or formatting that causes problems.",[14,864,199,865,867],{},[17,866,211],{}," to remove spaces at the start and end:",[61,869,871],{"className":63,"code":870,"language":65,"meta":66,"style":66},"user_text = input(\"Enter a number: \").strip()\n\ntry:\n    number = int(user_text)\n    print(number)\nexcept ValueError:\n    print(\"Invalid input\")\n",[17,872,873,895,899,905,919,930,938],{"__ignoreMap":66},[70,874,875,877,879,881,883,885,887,889,891,893],{"class":72,"line":73},[70,876,77],{"class":76},[70,878,81],{"class":80},[70,880,85],{"class":84},[70,882,89],{"class":88},[70,884,93],{"class":92},[70,886,97],{"class":96},[70,888,93],{"class":92},[70,890,102],{"class":88},[70,892,106],{"class":105},[70,894,109],{"class":88},[70,896,897],{"class":72,"line":112},[70,898,116],{"emptyLinePlaceholder":115},[70,900,901,903],{"class":72,"line":119},[70,902,123],{"class":122},[70,904,126],{"class":88},[70,906,907,909,911,913,915,917],{"class":72,"line":129},[70,908,132],{"class":76},[70,910,81],{"class":80},[70,912,138],{"class":137},[70,914,89],{"class":88},[70,916,143],{"class":105},[70,918,146],{"class":88},[70,920,921,923,925,928],{"class":72,"line":149},[70,922,152],{"class":84},[70,924,89],{"class":88},[70,926,927],{"class":105},"number",[70,929,146],{"class":88},[70,931,932,934,936],{"class":72,"line":172},[70,933,175],{"class":122},[70,935,178],{"class":137},[70,937,126],{"class":88},[70,939,940,942,944,946,949,951],{"class":72,"line":183},[70,941,152],{"class":84},[70,943,89],{"class":88},[70,945,93],{"class":92},[70,947,948],{"class":96},"Invalid input",[70,950,93],{"class":92},[70,952,146],{"class":88},[14,954,955],{},"This helps with input like:",[61,957,959],{"className":63,"code":958,"language":65,"meta":66,"style":66},"\"  25  \"\n",[17,960,961],{"__ignoreMap":66},[70,962,963,966,970],{"class":72,"line":73},[70,964,93],{"class":965},"s2W-s",[70,967,969],{"class":968},"sithA","  25  ",[70,971,972],{"class":965},"\"\n",[14,974,975],{},"You can also clean other formatting if needed. For example, some users may paste numbers with commas:",[61,977,979],{"className":63,"code":978,"language":65,"meta":66,"style":66},"user_text = input(\"Enter a number: \").strip()\nuser_text = user_text.replace(\",\", \"\")\n\ntry:\n    number = int(user_text)\n    print(\"Parsed number:\", number)\nexcept ValueError:\n    print(\"Please enter a valid whole number.\")\n",[17,980,981,1003,1031,1035,1041,1055,1074,1082],{"__ignoreMap":66},[70,982,983,985,987,989,991,993,995,997,999,1001],{"class":72,"line":73},[70,984,77],{"class":76},[70,986,81],{"class":80},[70,988,85],{"class":84},[70,990,89],{"class":88},[70,992,93],{"class":92},[70,994,97],{"class":96},[70,996,93],{"class":92},[70,998,102],{"class":88},[70,1000,106],{"class":105},[70,1002,109],{"class":88},[70,1004,1005,1007,1009,1011,1013,1016,1018,1020,1022,1024,1026,1029],{"class":72,"line":112},[70,1006,77],{"class":76},[70,1008,81],{"class":80},[70,1010,737],{"class":76},[70,1012,278],{"class":88},[70,1014,1015],{"class":105},"replace",[70,1017,89],{"class":88},[70,1019,93],{"class":92},[70,1021,164],{"class":96},[70,1023,93],{"class":92},[70,1025,164],{"class":88},[70,1027,1028],{"class":92}," \"\"",[70,1030,146],{"class":88},[70,1032,1033],{"class":72,"line":119},[70,1034,116],{"emptyLinePlaceholder":115},[70,1036,1037,1039],{"class":72,"line":129},[70,1038,123],{"class":122},[70,1040,126],{"class":88},[70,1042,1043,1045,1047,1049,1051,1053],{"class":72,"line":149},[70,1044,132],{"class":76},[70,1046,81],{"class":80},[70,1048,138],{"class":137},[70,1050,89],{"class":88},[70,1052,143],{"class":105},[70,1054,146],{"class":88},[70,1056,1057,1059,1061,1063,1066,1068,1070,1072],{"class":72,"line":172},[70,1058,152],{"class":84},[70,1060,89],{"class":88},[70,1062,93],{"class":92},[70,1064,1065],{"class":96},"Parsed number:",[70,1067,93],{"class":92},[70,1069,164],{"class":88},[70,1071,167],{"class":105},[70,1073,146],{"class":88},[70,1075,1076,1078,1080],{"class":72,"line":183},[70,1077,175],{"class":122},[70,1079,178],{"class":137},[70,1081,126],{"class":88},[70,1083,1085,1087,1089,1091,1094,1096],{"class":72,"line":1084},8,[70,1086,152],{"class":84},[70,1088,89],{"class":88},[70,1090,93],{"class":92},[70,1092,1093],{"class":96},"Please enter a valid whole number.",[70,1095,93],{"class":92},[70,1097,146],{"class":88},[14,1099,1100],{},"Example:",[40,1102,1103],{},[43,1104,1105,1108,1109],{},[17,1106,1107],{},"\"1,000\""," becomes ",[17,1110,1111],{},"\"1000\"",[14,1113,1114],{},"Be careful with replacements. Only clean the formats you actually expect.",[56,1116,1118],{"id":1117},"fix-4-ask-again-until-the-input-is-valid","Fix 4: Ask again until the input is valid",[14,1120,1121],{},"For many beginner programs, the best user experience is to keep asking until the user enters valid input.",[61,1123,1125],{"className":63,"code":1124,"language":65,"meta":66,"style":66},"while True:\n    user_text = input(\"Enter a whole number: \").strip()\n\n    try:\n        number = int(user_text)\n        break\n    except ValueError:\n        print(\"That was not a valid whole number. Try again.\")\n\nprint(\"You entered:\", number)\n",[17,1126,1127,1138,1161,1165,1172,1187,1192,1201,1217,1222],{"__ignoreMap":66},[70,1128,1129,1132,1136],{"class":72,"line":73},[70,1130,1131],{"class":122},"while",[70,1133,1135],{"class":1134},"s39Yj"," True",[70,1137,126],{"class":88},[70,1139,1140,1143,1145,1147,1149,1151,1153,1155,1157,1159],{"class":72,"line":112},[70,1141,1142],{"class":76},"    user_text ",[70,1144,81],{"class":80},[70,1146,85],{"class":84},[70,1148,89],{"class":88},[70,1150,93],{"class":92},[70,1152,486],{"class":96},[70,1154,93],{"class":92},[70,1156,102],{"class":88},[70,1158,106],{"class":105},[70,1160,109],{"class":88},[70,1162,1163],{"class":72,"line":119},[70,1164,116],{"emptyLinePlaceholder":115},[70,1166,1167,1170],{"class":72,"line":129},[70,1168,1169],{"class":122},"    try",[70,1171,126],{"class":88},[70,1173,1174,1177,1179,1181,1183,1185],{"class":72,"line":149},[70,1175,1176],{"class":76},"        number ",[70,1178,81],{"class":80},[70,1180,138],{"class":137},[70,1182,89],{"class":88},[70,1184,143],{"class":105},[70,1186,146],{"class":88},[70,1188,1189],{"class":72,"line":172},[70,1190,1191],{"class":122},"        break\n",[70,1193,1194,1197,1199],{"class":72,"line":183},[70,1195,1196],{"class":122},"    except",[70,1198,178],{"class":137},[70,1200,126],{"class":88},[70,1202,1203,1206,1208,1210,1213,1215],{"class":72,"line":1084},[70,1204,1205],{"class":84},"        print",[70,1207,89],{"class":88},[70,1209,93],{"class":92},[70,1211,1212],{"class":96},"That was not a valid whole number. Try again.",[70,1214,93],{"class":92},[70,1216,146],{"class":88},[70,1218,1220],{"class":72,"line":1219},9,[70,1221,116],{"emptyLinePlaceholder":115},[70,1223,1225,1227,1229,1231,1233,1235,1237,1239],{"class":72,"line":1224},10,[70,1226,321],{"class":84},[70,1228,89],{"class":88},[70,1230,93],{"class":92},[70,1232,159],{"class":96},[70,1234,93],{"class":92},[70,1236,164],{"class":88},[70,1238,167],{"class":105},[70,1240,146],{"class":88},[14,1242,1243],{},"Why this is useful:",[40,1245,1246,1249,1252],{},[43,1247,1248],{},"the program does not crash",[43,1250,1251],{},"the user gets another chance",[43,1253,1254],{},"your code stays simple and focused",[14,1256,1257,1258,1260,1261,278],{},"You can use the same pattern with ",[17,1259,34],{}," if you expect decimal input. For a full walkthrough, see ",[274,1262,1264],{"href":1263},"\u002Fhow-to\u002Fhow-to-convert-user-input-to-numbers-in-python\u002F","how to convert user input to numbers in Python",[56,1266,1268],{"id":1267},"special-cases-beginners-hit","Special cases beginners hit",[14,1270,1271,1272,1274],{},"Some ",[17,1273,19],{}," cases are confusing at first. Here are a few common ones.",[1276,1277,1279],"h3",{"id":1278},"int35",[17,1280,1281],{},"int('3.5')",[61,1283,1285],{"className":63,"code":1284,"language":65,"meta":66,"style":66},"print(int(\"3.5\"))\n",[17,1286,1287],{"__ignoreMap":66},[70,1288,1289,1291,1293,1296,1298,1300,1303,1305],{"class":72,"line":73},[70,1290,321],{"class":84},[70,1292,89],{"class":88},[70,1294,1295],{"class":137},"int",[70,1297,89],{"class":88},[70,1299,93],{"class":92},[70,1301,1302],{"class":96},"3.5",[70,1304,93],{"class":92},[70,1306,316],{"class":88},[14,1308,1309,1310,1312,1313,1316],{},"This raises ",[17,1311,19],{}," because ",[17,1314,1315],{},"\"3.5\""," is a decimal string, not a whole number string.",[14,1318,1319,1320,1322],{},"If you expect decimal input, use ",[17,1321,34],{}," instead:",[61,1324,1326],{"className":63,"code":1325,"language":65,"meta":66,"style":66},"print(float(\"3.5\"))\n",[17,1327,1328],{"__ignoreMap":66},[70,1329,1330,1332,1334,1337,1339,1341,1343,1345],{"class":72,"line":73},[70,1331,321],{"class":84},[70,1333,89],{"class":88},[70,1335,1336],{"class":137},"float",[70,1338,89],{"class":88},[70,1340,93],{"class":92},[70,1342,1302],{"class":96},[70,1344,93],{"class":92},[70,1346,316],{"class":88},[1276,1348,1349],{"id":1336},[17,1350,1351],{},"float('')",[61,1353,1355],{"className":63,"code":1354,"language":65,"meta":66,"style":66},"print(float(\"\"))\n",[17,1356,1357],{"__ignoreMap":66},[70,1358,1359,1361,1363,1365,1367,1369],{"class":72,"line":73},[70,1360,321],{"class":84},[70,1362,89],{"class":88},[70,1364,1336],{"class":137},[70,1366,89],{"class":88},[70,1368,847],{"class":92},[70,1370,316],{"class":88},[14,1372,1309,1373,1375],{},[17,1374,19],{}," because an empty string is not a number.",[14,1377,1378],{},"This often happens when:",[40,1380,1381,1384],{},[43,1382,1383],{},"the user just presses Enter",[43,1385,1386],{},"you forgot to check for empty input",[1276,1388,1390,1391],{"id":1389},"unpacking-from-split","Unpacking from ",[17,1392,242],{},[61,1394,1396],{"className":63,"code":1395,"language":65,"meta":66,"style":66},"a, b = input(\"Enter two values: \").split()\nprint(a, b)\n",[17,1397,1398,1427],{"__ignoreMap":66},[70,1399,1400,1402,1404,1407,1409,1411,1413,1415,1418,1420,1422,1425],{"class":72,"line":73},[70,1401,274],{"class":76},[70,1403,164],{"class":88},[70,1405,1406],{"class":76}," b ",[70,1408,81],{"class":80},[70,1410,85],{"class":84},[70,1412,89],{"class":88},[70,1414,93],{"class":92},[70,1416,1417],{"class":96},"Enter two values: ",[70,1419,93],{"class":92},[70,1421,102],{"class":88},[70,1423,1424],{"class":105},"split",[70,1426,109],{"class":88},[70,1428,1429,1431,1433,1435,1437,1440],{"class":72,"line":112},[70,1430,321],{"class":84},[70,1432,89],{"class":88},[70,1434,274],{"class":105},[70,1436,164],{"class":88},[70,1438,1439],{"class":105}," b",[70,1441,146],{"class":88},[14,1443,1444],{},"This works only if the input has exactly two parts.",[14,1446,1447],{},"For example:",[40,1449,1450,1457,1463],{},[43,1451,1452,1453,1456],{},"input: ",[17,1454,1455],{},"\"10 20\""," → works",[43,1458,1452,1459,1462],{},[17,1460,1461],{},"\"10\""," → not enough values",[43,1464,1452,1465,1468],{},[17,1466,1467],{},"\"10 20 30\""," → too many values",[14,1470,1471,1472,1474],{},"These cases can raise different ",[17,1473,19],{}," messages. See:",[40,1476,1477,1483],{},[43,1478,1479],{},[274,1480,1482],{"href":1481},"\u002Ferrors\u002Fvalueerror-not-enough-values-to-unpack-fix\u002F","ValueError: not enough values to unpack (fix)",[43,1484,1485],{},[274,1486,1488],{"href":1487},"\u002Ferrors\u002Fvalueerror-too-many-values-to-unpack-fix\u002F","ValueError: too many values to unpack (fix)",[56,1490,1492],{"id":1491},"how-to-debug-the-input-value","How to debug the input value",[14,1494,1495],{},"If the error does not make sense, inspect the actual input.",[14,1497,1498],{},"Useful debugging lines:",[61,1500,1502],{"className":63,"code":1501,"language":65,"meta":66,"style":66},"user_input = input(\"Enter something: \")\n\nprint(user_input)\nprint(repr(user_input))\nprint(type(user_input))\n",[17,1503,1504,1524,1528,1539,1554],{"__ignoreMap":66},[70,1505,1506,1509,1511,1513,1515,1517,1520,1522],{"class":72,"line":73},[70,1507,1508],{"class":76},"user_input ",[70,1510,81],{"class":80},[70,1512,85],{"class":84},[70,1514,89],{"class":88},[70,1516,93],{"class":92},[70,1518,1519],{"class":96},"Enter something: ",[70,1521,93],{"class":92},[70,1523,146],{"class":88},[70,1525,1526],{"class":72,"line":112},[70,1527,116],{"emptyLinePlaceholder":115},[70,1529,1530,1532,1534,1537],{"class":72,"line":119},[70,1531,321],{"class":84},[70,1533,89],{"class":88},[70,1535,1536],{"class":105},"user_input",[70,1538,146],{"class":88},[70,1540,1541,1543,1545,1548,1550,1552],{"class":72,"line":129},[70,1542,321],{"class":84},[70,1544,89],{"class":88},[70,1546,1547],{"class":84},"repr",[70,1549,89],{"class":88},[70,1551,1536],{"class":105},[70,1553,316],{"class":88},[70,1555,1556,1558,1560,1563,1565,1567],{"class":72,"line":149},[70,1557,321],{"class":84},[70,1559,89],{"class":88},[70,1561,1562],{"class":137},"type",[70,1564,89],{"class":88},[70,1566,1536],{"class":105},[70,1568,316],{"class":88},[14,1570,1571,1572,1575],{},"Why ",[17,1573,1574],{},"repr()"," helps:",[40,1577,1578,1581,1584],{},[43,1579,1580],{},"it shows hidden spaces",[43,1582,1583],{},"it makes empty strings easier to see",[43,1585,1586],{},"it can reveal unexpected characters",[14,1588,1100],{},[61,1590,1592],{"className":63,"code":1591,"language":65,"meta":66,"style":66},"user_input = \" 42 \"\nprint(user_input)        # looks like:  42\nprint(repr(user_input))  # shows: ' 42 '\n",[17,1593,1594,1608,1623],{"__ignoreMap":66},[70,1595,1596,1598,1600,1603,1606],{"class":72,"line":73},[70,1597,1508],{"class":76},[70,1599,81],{"class":80},[70,1601,1602],{"class":92}," \"",[70,1604,1605],{"class":96}," 42 ",[70,1607,972],{"class":92},[70,1609,1610,1612,1614,1616,1619],{"class":72,"line":112},[70,1611,321],{"class":84},[70,1613,89],{"class":88},[70,1615,1536],{"class":105},[70,1617,1618],{"class":88},")",[70,1620,1622],{"class":1621},"sutJx","        # looks like:  42\n",[70,1624,1625,1627,1629,1631,1633,1635,1638],{"class":72,"line":119},[70,1626,321],{"class":84},[70,1628,89],{"class":88},[70,1630,1547],{"class":84},[70,1632,89],{"class":88},[70,1634,1536],{"class":105},[70,1636,1637],{"class":88},"))",[70,1639,1640],{"class":1621},"  # shows: ' 42 '\n",[14,1642,1643,1644,1646],{},"For ",[17,1645,242],{}," problems, inspect the list of parts:",[61,1648,1650],{"className":63,"code":1649,"language":65,"meta":66,"style":66},"parts = input(\"Enter values: \").split()\nprint(parts, len(parts))\n",[17,1651,1652,1676],{"__ignoreMap":66},[70,1653,1654,1657,1659,1661,1663,1665,1668,1670,1672,1674],{"class":72,"line":73},[70,1655,1656],{"class":76},"parts ",[70,1658,81],{"class":80},[70,1660,85],{"class":84},[70,1662,89],{"class":88},[70,1664,93],{"class":92},[70,1666,1667],{"class":96},"Enter values: ",[70,1669,93],{"class":92},[70,1671,102],{"class":88},[70,1673,1424],{"class":105},[70,1675,109],{"class":88},[70,1677,1678,1680,1682,1685,1687,1690,1692,1694],{"class":72,"line":112},[70,1679,321],{"class":84},[70,1681,89],{"class":88},[70,1683,1684],{"class":105},"parts",[70,1686,164],{"class":88},[70,1688,1689],{"class":84}," len",[70,1691,89],{"class":88},[70,1693,1684],{"class":105},[70,1695,316],{"class":88},[14,1697,1698],{},"This helps you see whether you got the number of values you expected.",[56,1700,1702],{"id":1701},"when-to-use-int-vs-float","When to use int() vs float()",[14,1704,1705],{},"Choose the conversion based on the kind of number you expect.",[14,1707,199,1708,1710],{},[17,1709,30],{}," for whole numbers:",[40,1712,1713,1718,1723],{},[43,1714,1715],{},[17,1716,1717],{},"5",[43,1719,1720],{},[17,1721,1722],{},"42",[43,1724,1725],{},[17,1726,1727],{},"100",[14,1729,199,1730,1732],{},[17,1731,34],{}," for decimal numbers:",[40,1734,1735,1740,1745],{},[43,1736,1737],{},[17,1738,1739],{},"3.14",[43,1741,1742],{},[17,1743,1744],{},"2.0",[43,1746,1747],{},[17,1748,1749],{},"0.5",[14,1751,1100],{},[61,1753,1755],{"className":63,"code":1754,"language":65,"meta":66,"style":66},"whole = int(\"5\")\ndecimal = float(\"3.14\")\n\nprint(whole)\nprint(decimal)\n",[17,1756,1757,1776,1795,1799,1810],{"__ignoreMap":66},[70,1758,1759,1762,1764,1766,1768,1770,1772,1774],{"class":72,"line":73},[70,1760,1761],{"class":76},"whole ",[70,1763,81],{"class":80},[70,1765,138],{"class":137},[70,1767,89],{"class":88},[70,1769,93],{"class":92},[70,1771,1717],{"class":96},[70,1773,93],{"class":92},[70,1775,146],{"class":88},[70,1777,1778,1781,1783,1785,1787,1789,1791,1793],{"class":72,"line":112},[70,1779,1780],{"class":76},"decimal ",[70,1782,81],{"class":80},[70,1784,628],{"class":137},[70,1786,89],{"class":88},[70,1788,93],{"class":92},[70,1790,1739],{"class":96},[70,1792,93],{"class":92},[70,1794,146],{"class":88},[70,1796,1797],{"class":72,"line":119},[70,1798,116],{"emptyLinePlaceholder":115},[70,1800,1801,1803,1805,1808],{"class":72,"line":129},[70,1802,321],{"class":84},[70,1804,89],{"class":88},[70,1806,1807],{"class":105},"whole",[70,1809,146],{"class":88},[70,1811,1812,1814,1816,1819],{"class":72,"line":149},[70,1813,321],{"class":84},[70,1815,89],{"class":88},[70,1817,1818],{"class":105},"decimal",[70,1820,146],{"class":88},[14,1822,1823,1824,1826],{},"If your program may receive either whole numbers or decimals, ",[17,1825,34],{}," is often the better choice.",[14,1828,1447],{},[61,1830,1832],{"className":63,"code":1831,"language":65,"meta":66,"style":66},"user_text = input(\"Enter a number: \").strip()\n\ntry:\n    number = float(user_text)\n    print(\"Valid number:\", number)\nexcept ValueError:\n    print(\"Please enter a valid number.\")\n",[17,1833,1834,1856,1860,1866,1880,1898,1906],{"__ignoreMap":66},[70,1835,1836,1838,1840,1842,1844,1846,1848,1850,1852,1854],{"class":72,"line":73},[70,1837,77],{"class":76},[70,1839,81],{"class":80},[70,1841,85],{"class":84},[70,1843,89],{"class":88},[70,1845,93],{"class":92},[70,1847,97],{"class":96},[70,1849,93],{"class":92},[70,1851,102],{"class":88},[70,1853,106],{"class":105},[70,1855,109],{"class":88},[70,1857,1858],{"class":72,"line":112},[70,1859,116],{"emptyLinePlaceholder":115},[70,1861,1862,1864],{"class":72,"line":119},[70,1863,123],{"class":122},[70,1865,126],{"class":88},[70,1867,1868,1870,1872,1874,1876,1878],{"class":72,"line":129},[70,1869,132],{"class":76},[70,1871,81],{"class":80},[70,1873,628],{"class":137},[70,1875,89],{"class":88},[70,1877,143],{"class":105},[70,1879,146],{"class":88},[70,1881,1882,1884,1886,1888,1890,1892,1894,1896],{"class":72,"line":149},[70,1883,152],{"class":84},[70,1885,89],{"class":88},[70,1887,93],{"class":92},[70,1889,525],{"class":96},[70,1891,93],{"class":92},[70,1893,164],{"class":88},[70,1895,167],{"class":105},[70,1897,146],{"class":88},[70,1899,1900,1902,1904],{"class":72,"line":172},[70,1901,175],{"class":122},[70,1903,178],{"class":137},[70,1905,126],{"class":88},[70,1907,1908,1910,1912,1914,1916,1918],{"class":72,"line":183},[70,1909,152],{"class":84},[70,1911,89],{"class":88},[70,1913,93],{"class":92},[70,1915,671],{"class":96},[70,1917,93],{"class":92},[70,1919,146],{"class":88},[14,1921,1922,1923,1927],{},"If needed, you can later convert a valid float to an integer, but only if that makes sense for your program. See ",[274,1924,1926],{"href":1925},"\u002Freference\u002Fpython-float-function-explained\u002F","Python float() function explained"," for more details.",[56,1929,1931],{"id":1930},"common-causes","Common causes",[14,1933,1934],{},"This error often happens because:",[40,1936,1937,1940,1946,1949,1952,1957],{},[43,1938,1939],{},"user entered letters instead of digits",[43,1941,1942,1943,1945],{},"user entered a decimal when ",[17,1944,30],{}," was used",[43,1947,1948],{},"input was empty",[43,1950,1951],{},"input had extra spaces or formatting",[43,1953,1954,1955],{},"code unpacked the wrong number of values from ",[17,1956,242],{},[43,1958,1959],{},"program assumed input was always valid",[56,1961,1963],{"id":1962},"faq","FAQ",[1276,1965,1967,1968,1971],{"id":1966},"why-does-int30-raise-valueerror","Why does ",[17,1969,1970],{},"int('3.0')"," raise ValueError?",[14,1973,1974,1975,1977,1978,1981,1982,1985,1986,1988],{},"Because ",[17,1976,30],{}," expects a whole number string like ",[17,1979,1980],{},"\"3\"",", not a decimal string like ",[17,1983,1984],{},"\"3.0\"",". Convert with ",[17,1987,34],{}," first if needed.",[1276,1990,1992,1993,1995],{"id":1991},"does-strip-fix-valueerror-by-itself","Does ",[17,1994,211],{}," fix ValueError by itself?",[14,1997,1998,1999,2002],{},"Only sometimes. It removes spaces at the start and end, but it does not turn invalid text like ",[17,2000,2001],{},"\"abc\""," into a number.",[1276,2004,2006,2007,2009,2010,2012],{"id":2005},"should-i-use-isdigit-instead-of-try-except","Should I use ",[17,2008,697],{}," instead of ",[17,2011,202],{},"?",[14,2014,2015,2017,2018,2020],{},[17,2016,697],{}," is useful for simple cases, but ",[17,2019,202],{}," is more flexible and handles more real input situations.",[1276,2022,2024,2025,2027],{"id":2023},"can-input-return-an-int-automatically","Can ",[17,2026,23],{}," return an int automatically?",[14,2029,2030,2031,2033],{},"No. ",[17,2032,23],{}," always returns a string, so you must convert it yourself.",[56,2035,2037],{"id":2036},"see-also","See also",[40,2039,2040,2044,2048,2052,2057,2062,2068],{},[43,2041,2042],{},[274,2043,448],{"href":447},[43,2045,2046],{},[274,2047,453],{"href":452},[43,2049,2050],{},[274,2051,1926],{"href":1925},[43,2053,2054],{},[274,2055,2056],{"href":1263},"How to convert user input to numbers in Python",[43,2058,2059],{},[274,2060,2061],{"href":681},"How to use try-except blocks in Python",[43,2063,2064],{},[274,2065,2067],{"href":2066},"\u002Ferrors\u002Fvalueerror-invalid-literal-for-int-with-base-10-fix\u002F","ValueError: invalid literal for int() with base 10 (fix)",[43,2069,2070],{},[274,2071,2073],{"href":2072},"\u002Ferrors\u002Fvalueerror-could-not-convert-string-to-float-fix\u002F","ValueError: could not convert string to float (fix)",[2075,2076,2077],"style",{},"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 .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 .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 .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 .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .s2W-s, html code.shiki .s2W-s{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#032F62;--shiki-default-font-style:inherit;--shiki-dark:#9ECBFF;--shiki-dark-font-style:inherit}html pre.shiki code .sithA, html code.shiki .sithA{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#032F62;--shiki-default-font-style:inherit;--shiki-dark:#9ECBFF;--shiki-dark-font-style:inherit}html pre.shiki code .s39Yj, html code.shiki .s39Yj{--shiki-light:#39ADB5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sutJx, html code.shiki .sutJx{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#6A737D;--shiki-default-font-style:inherit;--shiki-dark:#6A737D;--shiki-dark-font-style:inherit}",{"title":66,"searchDepth":112,"depth":112,"links":2079},[2080,2081,2082,2083,2084,2085,2086,2087,2093,2094,2095,2096,2106],{"id":58,"depth":112,"text":59},{"id":215,"depth":112,"text":216},{"id":281,"depth":112,"text":282},{"id":456,"depth":112,"text":457},{"id":685,"depth":112,"text":686},{"id":858,"depth":112,"text":859},{"id":1117,"depth":112,"text":1118},{"id":1267,"depth":112,"text":1268,"children":2088},[2089,2090,2091],{"id":1278,"depth":119,"text":1281},{"id":1336,"depth":119,"text":1351},{"id":1389,"depth":119,"text":2092},"Unpacking from split()",{"id":1491,"depth":112,"text":1492},{"id":1701,"depth":112,"text":1702},{"id":1930,"depth":112,"text":1931},{"id":1962,"depth":112,"text":1963,"children":2097},[2098,2100,2102,2104],{"id":1966,"depth":119,"text":2099},"Why does int('3.0') raise ValueError?",{"id":1991,"depth":119,"text":2101},"Does strip() fix ValueError by itself?",{"id":2005,"depth":119,"text":2103},"Should I use isdigit() instead of try-except?",{"id":2023,"depth":119,"text":2105},"Can input() return an int automatically?",{"id":2036,"depth":112,"text":2037},"Master valueerror when parsing input in python fix in our comprehensive Python beginner guide.","md",{},"\u002Ferrors\u002Fvalueerror-when-parsing-input-in-python-fix",{"title":5,"description":2107},"errors\u002Fvalueerror-when-parsing-input-in-python-fix","OL-ETwUlqtel3W-vZKKvFk_MvBkSBHY3BYGRkvyAtOE",1777585483353]