{"id":135533,"date":"2026-08-08T23:50:15","date_gmt":"2026-08-08T17:50:15","guid":{"rendered":"https:\/\/rcl-radio.ru\/?p=135533"},"modified":"2026-08-08T23:50:15","modified_gmt":"2026-08-08T17:50:15","slug":"%d0%be%d0%b1%d1%80%d0%b0%d0%b1%d0%be%d1%82%d0%ba%d0%b0-%d0%b8%d1%81%d0%ba%d0%bb%d1%8e%d1%87%d0%b5%d0%bd%d0%b8%d0%b9-%d0%b2-python-try-except-finally-%d0%bd%d0%b0-%d0%bf%d0%be%d0%bd%d1%8f","status":"publish","type":"post","link":"https:\/\/rcl-radio.ru\/?p=135533","title":{"rendered":"\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0432 Python: try, except, finally \u2014 \u043d\u0430 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445"},"content":{"rendered":"<p>\u041a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0434\u0435\u043b\u0430\u0435\u0442 \u0447\u0442\u043e-\u0442\u043e \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 (\u0447\u0438\u0442\u0430\u0435\u0442 \u0444\u0430\u0439\u043b, \u0434\u0435\u043b\u0438\u0442 \u0447\u0438\u0441\u043b\u0430, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0432\u0432\u043e\u0434 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f), \u0432\u0441\u0435\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u0440\u0438\u0441\u043a, \u0447\u0442\u043e \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0439\u0434\u0451\u0442 \u043d\u0435 \u0442\u0430\u043a: \u0444\u0430\u0439\u043b \u043d\u0435 \u043d\u0430\u0439\u0434\u0451\u0442\u0441\u044f, \u043d\u0430 \u043d\u043e\u043b\u044c \u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f, \u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u043c\u0435\u0441\u0442\u043e \u0447\u0438\u0441\u043b\u0430 \u0432\u0432\u0435\u0434\u0451\u0442 \u0431\u0443\u043a\u0432\u044b. \u0412 Python \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <code class=\"CodeInlined\">try\/except\/finally<\/code>. \u0415\u0451 \u0437\u0430\u0434\u0430\u0447\u0430 \u2014 \u043d\u0435 \u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u0443\u043f\u0430\u0441\u0442\u044c \u0441 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u043e\u0439, \u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e \u0438, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e, \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443.<\/p>\n<hr \/>\n<h2>\u041a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f<\/h2>\n<p>\u0411\u0430\u0437\u043e\u0432\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #ff7700; font-weight: bold;\">try<\/span>:\r\n    <span style=\"color: #808080; font-style: italic;\"># \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443<\/span>\r\n<span style=\"color: #ff7700; font-weight: bold;\">except<\/span> SomeException:\r\n    <span style=\"color: #808080; font-style: italic;\"># \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0430 \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0441\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c<\/span>\r\n<span style=\"color: #ff7700; font-weight: bold;\">else<\/span>:\r\n    <span style=\"color: #808080; font-style: italic;\"># \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0435 \u0431\u044b\u043b\u043e (\u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e)<\/span>\r\n<span style=\"color: #ff7700; font-weight: bold;\">finally<\/span>:\r\n    <span style=\"color: #808080; font-style: italic;\"># \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432\u0441\u0435\u0433\u0434\u0430 (\u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e)<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<ul>\n<li data-value=\"\" data-shift=\"0\"><code class=\"CodeInlined\">try<\/code>: \u0431\u043b\u043e\u043a, \u0433\u0434\u0435 \u043c\u044b \u00ab\u043f\u0440\u043e\u0431\u0443\u0435\u043c\u00bb \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043a\u043e\u0434.<\/li>\n<li data-value=\"\" data-shift=\"0\"><code class=\"CodeInlined\">except<\/code>: \u0440\u0435\u0430\u043a\u0446\u0438\u044f \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0442\u0438\u043f \u043e\u0448\u0438\u0431\u043a\u0438. \u041c\u043e\u0436\u043d\u043e \u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e <code class=\"CodeInlined\">except<\/code> \u043f\u043e\u0434\u0440\u044f\u0434 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432.<\/li>\n<li data-value=\"\" data-shift=\"0\"><code class=\"CodeInlined\">else<\/code>: \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0432 <code class=\"CodeInlined\">try<\/code> \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439. \u0423\u0434\u043e\u0431\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u00ab\u043e\u043f\u0430\u0441\u043d\u044b\u0439\u00bb \u043a\u043e\u0434 \u043e\u0442 \u00ab\u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e\u00bb.<\/li>\n<li data-value=\"\" data-shift=\"0\"><code class=\"CodeInlined\">finally<\/code>: \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 \u0438 \u043f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0435, \u0438 \u0431\u0435\u0437 \u043d\u0435\u0451. \u0427\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u044e\u0434\u0430 \u0441\u0442\u0430\u0432\u044f\u0442 \u043e\u0447\u0438\u0441\u0442\u043a\u0443 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432: \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u0432, \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0438 \u0442. \u043f.<\/li>\n<\/ul>\n<hr \/>\n<h2>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440: \u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u043d\u043e\u043b\u044c<\/h2>\n<p>\u0421\u0430\u043c\u0430\u044f \u0447\u0430\u0441\u0442\u0430\u044f \u0443\u0447\u0435\u0431\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u2014 \u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u043d\u043e\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <code class=\"CodeInlined\">ZeroDivisionError<\/code>.<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\">a <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #ff4500;\">10<\/span>\r\nb <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #ff4500;\">0<\/span>\r\n\u00a0\r\n<span style=\"color: #ff7700; font-weight: bold;\">try<\/span>:\r\n    result <span style=\"color: #66cc66;\">=<\/span> a \/ b\r\n    <span style=\"color: #ff7700; font-weight: bold;\">print<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:\"<\/span><span style=\"color: #66cc66;\">,<\/span> result<span style=\"color: black;\">)<\/span>\r\n<span style=\"color: #ff7700; font-weight: bold;\">except<\/span> <span style=\"color: #008000;\">ZeroDivisionError<\/span>:\r\n    <span style=\"color: #ff7700; font-weight: bold;\">print<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"\u041d\u0435\u043b\u044c\u0437\u044f \u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u043d\u043e\u043b\u044c!\"<\/span><span style=\"color: black;\">)<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043d\u0435 \u043f\u0430\u0434\u0430\u0435\u0442, \u0430 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435. \u042d\u0442\u043e \u0443\u0436\u0435 \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u0441\u0442\u0440\u0430\u0448\u043d\u0430\u044f \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0430 \u0441\u0442\u0435\u043a\u0430 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c.<\/p>\n<hr \/>\n<h2>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a: \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e except<\/h2>\n<p>\u0427\u0430\u0441\u0442\u043e \u0431\u044b\u0432\u0430\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u0432\u043e\u0434\u0438\u0442 \u0434\u0430\u043d\u043d\u044b\u0435, \u0438 \u0442\u0430\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u0438\u0431\u043e \u043d\u0435 \u0447\u0438\u0441\u043b\u043e, \u043b\u0438\u0431\u043e \u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u043d\u043e\u043b\u044c.<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\">num_str <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #008000;\">input<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c: \"<\/span><span style=\"color: black;\">)<\/span>\r\nden_str <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #008000;\">input<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0437\u043d\u0430\u043c\u0435\u043d\u0430\u0442\u0435\u043b\u044c: \"<\/span><span style=\"color: black;\">)<\/span>\r\n\u00a0\r\n<span style=\"color: #ff7700; font-weight: bold;\">try<\/span>:\r\n    numerator <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #008000;\">int<\/span><span style=\"color: black;\">(<\/span>num_str<span style=\"color: black;\">)<\/span>\r\n    denominator <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #008000;\">int<\/span><span style=\"color: black;\">(<\/span>den_str<span style=\"color: black;\">)<\/span>\r\n    result <span style=\"color: #66cc66;\">=<\/span> numerator \/ denominator\r\n    <span style=\"color: #ff7700; font-weight: bold;\">print<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f:\"<\/span><span style=\"color: #66cc66;\">,<\/span> result<span style=\"color: black;\">)<\/span>\r\n<span style=\"color: #ff7700; font-weight: bold;\">except<\/span> <span style=\"color: #008000;\">ValueError<\/span>:\r\n    <span style=\"color: #ff7700; font-weight: bold;\">print<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0432\u0432\u043e\u0434\u0438\u0442\u0435 \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430.\"<\/span><span style=\"color: black;\">)<\/span>\r\n<span style=\"color: #ff7700; font-weight: bold;\">except<\/span> <span style=\"color: #008000;\">ZeroDivisionError<\/span>:\r\n    <span style=\"color: #ff7700; font-weight: bold;\">print<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"\u0417\u043d\u0430\u043c\u0435\u043d\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0443\u043b\u0451\u043c.\"<\/span><span style=\"color: black;\">)<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0417\u0434\u0435\u0441\u044c <code class=\"CodeInlined\">ValueError<\/code> \u043b\u043e\u0432\u0438\u0442 \u0441\u043b\u0443\u0447\u0430\u0438, \u043a\u043e\u0433\u0434\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 \u043d\u0435 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0447\u0438\u0441\u043b\u043e, \u0430 <code class=\"CodeInlined\">ZeroDivisionError<\/code> \u2014 \u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u043d\u043e\u043b\u044c. \u041f\u043e\u0440\u044f\u0434\u043e\u043a \u0432\u0430\u0436\u0435\u043d: \u0431\u043e\u043b\u0435\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043f\u0438\u0448\u0443\u0442 \u0440\u0430\u043d\u044c\u0448\u0435, \u043e\u0431\u0449\u0438\u0435 \u2014 \u043f\u043e\u0437\u0436\u0435.<\/p>\n<hr \/>\n<h2>else: \u043a\u043e\u0433\u0434\u0430 \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0435\u0442<\/h2>\n<p>\u0411\u043b\u043e\u043a <code class=\"CodeInlined\">else<\/code> \u043f\u043e\u043b\u0435\u0437\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u00ab\u0440\u0438\u0441\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0439\u00bb \u043a\u043e\u0434 \u0438 \u00ab\u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u00bb, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0443\u0441\u043f\u0435\u0445\u0435.<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\">x <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #ff4500;\">5<\/span>\r\ny <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #ff4500;\">2<\/span>\r\n\u00a0\r\n<span style=\"color: #ff7700; font-weight: bold;\">try<\/span>:\r\n    z <span style=\"color: #66cc66;\">=<\/span> x \/ y\r\n<span style=\"color: #ff7700; font-weight: bold;\">except<\/span> <span style=\"color: #008000;\">ZeroDivisionError<\/span>:\r\n    <span style=\"color: #ff7700; font-weight: bold;\">print<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"\u041e\u0448\u0438\u0431\u043a\u0430 \u0434\u0435\u043b\u0435\u043d\u0438\u044f\"<\/span><span style=\"color: black;\">)<\/span>\r\n<span style=\"color: #ff7700; font-weight: bold;\">else<\/span>:\r\n    <span style=\"color: #808080; font-style: italic;\"># \u042d\u0442\u043e\u0442 \u0431\u043b\u043e\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0435 \u0432\u044b\u0437\u0432\u0430\u043b\u043e \u043e\u0448\u0438\u0431\u043a\u0443<\/span>\r\n    <span style=\"color: #ff7700; font-weight: bold;\">print<\/span><span style=\"color: black;\">(<\/span>f<span style=\"color: #483d8b;\">\"{x} \/ {y} = {z}\"<\/span><span style=\"color: black;\">)<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0415\u0441\u043b\u0438 \u0431\u044b \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430, <code class=\"CodeInlined\">else<\/code> \u0431\u044b \u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0441\u044f. \u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0439: \u00ab\u0435\u0441\u043b\u0438 \u0432\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e \u2014 \u0434\u0435\u043b\u0430\u0435\u043c \u0432\u043e\u0442 \u044d\u0442\u043e\u00bb.<\/p>\n<hr \/>\n<h2>finally: \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0435\u0433\u0434\u0430<\/h2>\n<p><code class=\"CodeInlined\">finally<\/code> \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043e\u0447\u0438\u0441\u0442\u043a\u0438. \u0421\u0430\u043c\u044b\u0439 \u0447\u0430\u0441\u0442\u044b\u0439 \u043a\u0435\u0439\u0441 \u2014 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0444\u0430\u0439\u043b\u0430.<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\">filename <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #483d8b;\">\"data.txt\"<\/span>\r\n\u00a0\r\n<span style=\"color: #ff7700; font-weight: bold;\">try<\/span>:\r\n    f <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #008000;\">open<\/span><span style=\"color: black;\">(<\/span>filename<span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"r\"<\/span><span style=\"color: black;\">)<\/span>\r\n    data <span style=\"color: #66cc66;\">=<\/span> f.<span style=\"color: black;\">read<\/span><span style=\"color: black;\">(<\/span><span style=\"color: black;\">)<\/span>\r\n    <span style=\"color: #ff7700; font-weight: bold;\">print<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"\u0414\u0430\u043d\u043d\u044b\u0435:\"<\/span><span style=\"color: #66cc66;\">,<\/span> data<span style=\"color: black;\">)<\/span>\r\n<span style=\"color: #ff7700; font-weight: bold;\">except<\/span> FileNotFoundError:\r\n    <span style=\"color: #ff7700; font-weight: bold;\">print<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"\u0424\u0430\u0439\u043b \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d.\"<\/span><span style=\"color: black;\">)<\/span>\r\n<span style=\"color: #ff7700; font-weight: bold;\">finally<\/span>:\r\n    <span style=\"color: #808080; font-style: italic;\"># \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u0438 \u043f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0435, \u0438 \u043f\u0440\u0438 \u0443\u0441\u043f\u0435\u0445\u0435<\/span>\r\n    <span style=\"color: #ff7700; font-weight: bold;\">try<\/span>:\r\n        f.<span style=\"color: black;\">close<\/span><span style=\"color: black;\">(<\/span><span style=\"color: black;\">)<\/span>\r\n    <span style=\"color: #ff7700; font-weight: bold;\">except<\/span> <span style=\"color: #008000;\">NameError<\/span>:\r\n        <span style=\"color: #808080; font-style: italic;\"># \u0415\u0441\u043b\u0438 f \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u043b\u0441\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0448\u0438\u0431\u043a\u0430 \u0432 open)<\/span>\r\n        <span style=\"color: #ff7700; font-weight: bold;\">pass<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0439 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 <code class=\"CodeInlined\">with<\/code>, \u043d\u043e \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0448\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f: <code class=\"CodeInlined\">finally<\/code> \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0440\u0435\u0441\u0443\u0440\u0441 \u0431\u0443\u0434\u0435\u0442 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0451\u043d.<\/p>\n<p>\u0411\u043e\u043b\u0435\u0435 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 \u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442:<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\">filename <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #483d8b;\">\"data.txt\"<\/span>\r\n\u00a0\r\n<span style=\"color: #ff7700; font-weight: bold;\">try<\/span>:\r\n    <span style=\"color: #ff7700; font-weight: bold;\">with<\/span> <span style=\"color: #008000;\">open<\/span><span style=\"color: black;\">(<\/span>filename<span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"r\"<\/span><span style=\"color: black;\">)<\/span> <span style=\"color: #ff7700; font-weight: bold;\">as<\/span> f:\r\n        data <span style=\"color: #66cc66;\">=<\/span> f.<span style=\"color: black;\">read<\/span><span style=\"color: black;\">(<\/span><span style=\"color: black;\">)<\/span>\r\n        <span style=\"color: #ff7700; font-weight: bold;\">print<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"\u0414\u0430\u043d\u043d\u044b\u0435:\"<\/span><span style=\"color: #66cc66;\">,<\/span> data<span style=\"color: black;\">)<\/span>\r\n<span style=\"color: #ff7700; font-weight: bold;\">except<\/span> FileNotFoundError:\r\n    <span style=\"color: #ff7700; font-weight: bold;\">print<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"\u0424\u0430\u0439\u043b \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d.\"<\/span><span style=\"color: black;\">)<\/span>\r\n<span style=\"color: #808080; font-style: italic;\"># finally \u0442\u0443\u0442 \u043d\u0435 \u043d\u0443\u0436\u0435\u043d: with \u0441\u0430\u043c \u0437\u0430\u043a\u0440\u043e\u0435\u0442 \u0444\u0430\u0439\u043b<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<hr \/>\n<h2>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435<\/h2>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u00ab\u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0448\u043b\u043e \u043d\u0435 \u0442\u0430\u043a\u00bb. \u041f\u043e\u043b\u0435\u0437\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0434\u0435\u0442\u0430\u043b\u0438.<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\">value <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #483d8b;\">\"abc\"<\/span>\r\n\u00a0\r\n<span style=\"color: #ff7700; font-weight: bold;\">try<\/span>:\r\n    number <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #008000;\">int<\/span><span style=\"color: black;\">(<\/span>value<span style=\"color: black;\">)<\/span>\r\n<span style=\"color: #ff7700; font-weight: bold;\">except<\/span> <span style=\"color: #008000;\">ValueError<\/span> <span style=\"color: #ff7700; font-weight: bold;\">as<\/span> e:\r\n    <span style=\"color: #ff7700; font-weight: bold;\">print<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"\u041f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f:\"<\/span><span style=\"color: #66cc66;\">,<\/span> e<span style=\"color: black;\">)<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p><code class=\"CodeInlined\">as e<\/code> \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code class=\"CodeInlined\">e<\/code>, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0435\u0441\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435. \u042d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<hr \/>\n<h2>\u041b\u043e\u0432\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f\u043e\u0432 \u043e\u0448\u0438\u0431\u043e\u043a \u043e\u0434\u043d\u0438\u043c except<\/h2>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f\u043e\u0432 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439:<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #ff7700; font-weight: bold;\">try<\/span>:\r\n    x <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #008000;\">int<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #008000;\">input<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0447\u0438\u0441\u043b\u043e: \"<\/span><span style=\"color: black;\">)<\/span><span style=\"color: black;\">)<\/span>\r\n    y <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #ff4500;\">10<\/span> \/ x\r\n<span style=\"color: #ff7700; font-weight: bold;\">except<\/span> <span style=\"color: black;\">(<\/span><span style=\"color: #008000;\">ValueError<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #008000;\">ZeroDivisionError<\/span><span style=\"color: black;\">)<\/span> <span style=\"color: #ff7700; font-weight: bold;\">as<\/span> e:\r\n    <span style=\"color: #ff7700; font-weight: bold;\">print<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441 \u0432\u0432\u043e\u0434\u043e\u043c \u0438\u043b\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435\u043c:\"<\/span><span style=\"color: #66cc66;\">,<\/span> e<span style=\"color: black;\">)<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u042d\u0442\u043e \u0441\u043e\u043a\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u0434, \u043a\u043e\u0433\u0434\u0430 \u0440\u0435\u0430\u043a\u0446\u0438\u044f \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0430\u044f.<\/p>\n<hr \/>\n<h2>\u041e\u0431\u0449\u0438\u0439 except: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u043e<\/h2>\n<p>\u041c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c <code class=\"CodeInlined\">except Exception:<\/code> \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 <code class=\"CodeInlined\">except:<\/code> \u2014 \u044d\u0442\u043e \u043f\u043e\u0439\u043c\u0430\u0435\u0442 \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0451. \u041d\u043e \u0437\u043b\u043e\u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0442\u044c \u044d\u0442\u0438\u043c \u043d\u0435 \u0441\u0442\u043e\u0438\u0442: \u0442\u0430\u043a \u043b\u0435\u0433\u043a\u043e \u0441\u043a\u0440\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b (\u043e\u043f\u0435\u0447\u0430\u0442\u043a\u0438, \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438).<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #ff7700; font-weight: bold;\">try<\/span>:\r\n    do_something<span style=\"color: black;\">(<\/span><span style=\"color: black;\">)<\/span>\r\n<span style=\"color: #ff7700; font-weight: bold;\">except<\/span> <span style=\"color: #008000;\">Exception<\/span> <span style=\"color: #ff7700; font-weight: bold;\">as<\/span> e:\r\n    <span style=\"color: #ff7700; font-weight: bold;\">print<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"\u0427\u0442\u043e-\u0442\u043e \u043f\u043e\u0448\u043b\u043e \u043d\u0435 \u0442\u0430\u043a:\"<\/span><span style=\"color: #66cc66;\">,<\/span> e<span style=\"color: black;\">)<\/span>\r\n    <span style=\"color: #808080; font-style: italic;\"># \u0422\u0443\u0442 \u043e\u0431\u044b\u0447\u043d\u043e \u043b\u043e\u0433\u0438\u0440\u0443\u044e\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u0430 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0447\u0430\u0442\u0430\u044e\u0442<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043e\u0431\u0449\u0438\u0439 <code class=\"CodeInlined\">except<\/code> \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0433\u0434\u0430 \u0442\u043e\u0447\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0435, \u0437\u0430\u0447\u0435\u043c \u043e\u043d \u043d\u0443\u0436\u0435\u043d, \u0438 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u043e\u0433\u0438\u0440\u0443\u0439\u0442\u0435 \u043e\u0448\u0438\u0431\u043a\u0443, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0442\u043e\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f.<\/p>\n<hr \/>\n<h2>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440: \u0447\u0442\u0435\u043d\u0438\u0435 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0444\u0430\u0439\u043b\u0430 \u0441 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0435\u0439<\/h2>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0444\u0430\u0439\u043b \u0441 \u0447\u0438\u0441\u043b\u0430\u043c\u0438, \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435. \u041d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432 <code class=\"CodeInlined\">int<\/code>, \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #ff7700; font-weight: bold;\">def<\/span> read_and_average<span style=\"color: black;\">(<\/span>filename<span style=\"color: black;\">)<\/span>:\r\n    total <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #ff4500;\">0<\/span>\r\n    count <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #ff4500;\">0<\/span>\r\n\u00a0\r\n    <span style=\"color: #ff7700; font-weight: bold;\">try<\/span>:\r\n        <span style=\"color: #ff7700; font-weight: bold;\">with<\/span> <span style=\"color: #008000;\">open<\/span><span style=\"color: black;\">(<\/span>filename<span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"r\"<\/span><span style=\"color: #66cc66;\">,<\/span> encoding<span style=\"color: #66cc66;\">=<\/span><span style=\"color: #483d8b;\">\"utf-8\"<\/span><span style=\"color: black;\">)<\/span> <span style=\"color: #ff7700; font-weight: bold;\">as<\/span> f:\r\n            <span style=\"color: #ff7700; font-weight: bold;\">for<\/span> line_no<span style=\"color: #66cc66;\">,<\/span> line <span style=\"color: #ff7700; font-weight: bold;\">in<\/span> <span style=\"color: #008000;\">enumerate<\/span><span style=\"color: black;\">(<\/span>f<span style=\"color: #66cc66;\">,<\/span> start<span style=\"color: #66cc66;\">=<\/span><span style=\"color: #ff4500;\">1<\/span><span style=\"color: black;\">)<\/span>:\r\n                line <span style=\"color: #66cc66;\">=<\/span> line.<span style=\"color: black;\">strip<\/span><span style=\"color: black;\">(<\/span><span style=\"color: black;\">)<\/span>\r\n                <span style=\"color: #ff7700; font-weight: bold;\">if<\/span> <span style=\"color: #ff7700; font-weight: bold;\">not<\/span> line:\r\n                    <span style=\"color: #ff7700; font-weight: bold;\">continue<\/span>\r\n                <span style=\"color: #ff7700; font-weight: bold;\">try<\/span>:\r\n                    value <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #008000;\">int<\/span><span style=\"color: black;\">(<\/span>line<span style=\"color: black;\">)<\/span>\r\n                    total +<span style=\"color: #66cc66;\">=<\/span> value\r\n                    count +<span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #ff4500;\">1<\/span>\r\n                <span style=\"color: #ff7700; font-weight: bold;\">except<\/span> <span style=\"color: #008000;\">ValueError<\/span>:\r\n                    <span style=\"color: #ff7700; font-weight: bold;\">print<\/span><span style=\"color: black;\">(<\/span>f<span style=\"color: #483d8b;\">\"\u0421\u0442\u0440\u043e\u043a\u0430 {line_no}: \u043d\u0435 \u0447\u0438\u0441\u043b\u043e \u2014 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c: '{line}'\"<\/span><span style=\"color: black;\">)<\/span>\r\n\u00a0\r\n        <span style=\"color: #ff7700; font-weight: bold;\">if<\/span> count <span style=\"color: #66cc66;\">==<\/span> <span style=\"color: #ff4500;\">0<\/span>:\r\n            <span style=\"color: #ff7700; font-weight: bold;\">return<\/span> <span style=\"color: #008000;\">None<\/span>\r\n\u00a0\r\n        <span style=\"color: #ff7700; font-weight: bold;\">return<\/span> total \/ count\r\n\u00a0\r\n    <span style=\"color: #ff7700; font-weight: bold;\">except<\/span> FileNotFoundError:\r\n        <span style=\"color: #ff7700; font-weight: bold;\">print<\/span><span style=\"color: black;\">(<\/span>f<span style=\"color: #483d8b;\">\"\u0424\u0430\u0439\u043b '{filename}' \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d.\"<\/span><span style=\"color: black;\">)<\/span>\r\n        <span style=\"color: #ff7700; font-weight: bold;\">return<\/span> <span style=\"color: #008000;\">None<\/span>\r\n    <span style=\"color: #ff7700; font-weight: bold;\">except<\/span> PermissionError:\r\n        <span style=\"color: #ff7700; font-weight: bold;\">print<\/span><span style=\"color: black;\">(<\/span>f<span style=\"color: #483d8b;\">\"\u041d\u0435\u0442 \u043f\u0440\u0430\u0432 \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 '{filename}'.\"<\/span><span style=\"color: black;\">)<\/span>\r\n        <span style=\"color: #ff7700; font-weight: bold;\">return<\/span> <span style=\"color: #008000;\">None<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0427\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442:<\/p>\n<ul>\n<li data-value=\"\" data-shift=\"0\">\u0412\u043d\u0435\u0448\u043d\u0438\u0439 <code class=\"CodeInlined\">try<\/code> \u043b\u043e\u0432\u0438\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0441\u0430\u043c\u0438\u043c \u0444\u0430\u0439\u043b\u043e\u043c: \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d, \u043d\u0435\u0442 \u043f\u0440\u0430\u0432.<\/li>\n<li data-value=\"\" data-shift=\"0\">\u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 <code class=\"CodeInlined\">try<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 \u0446\u0438\u043a\u043b\u0430 \u043b\u043e\u0432\u0438\u0442 \u0441\u0442\u0440\u043e\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0447\u0438\u0441\u043b\u0430\u043c\u0438, \u0438 \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e \u0438\u0445 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442, \u0432\u044b\u0432\u043e\u0434\u044f \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435.<\/li>\n<li data-value=\"\" data-shift=\"0\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code class=\"CodeInlined\">None<\/code>, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0441\u043c\u043e\u0433\u043b\u0430 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u0440\u0435\u0434\u043d\u0435\u0435 (\u043d\u0435\u0442 \u0447\u0438\u0441\u0435\u043b \u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430).<\/li>\n<\/ul>\n<hr \/>\n<h2>\u0427\u0430\u0441\u0442\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u0441\u043e\u0432\u0435\u0442\u044b<\/h2>\n<ul>\n<li data-value=\"\" data-shift=\"0\"><strong>\u041d\u0435 \u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u043f\u0443\u0441\u0442\u043e\u0439 <code class=\"CodeInlined\">except:<\/code><\/strong>. \u042d\u0442\u043e \u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0451 \u043f\u043e\u0434\u0440\u044f\u0434 \u0438 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u043e\u0442\u043b\u0430\u0434\u043a\u0443.<\/li>\n<li data-value=\"\" data-shift=\"0\"><strong>\u041b\u043e\u0432\u0438\u0442\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f<\/strong>, \u043a\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e.<\/li>\n<li data-value=\"\" data-shift=\"0\"><strong>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <code class=\"CodeInlined\">finally<\/code> \u0438\u043b\u0438 <code class=\"CodeInlined\">with<\/code><\/strong> \u0434\u043b\u044f \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.<\/li>\n<li data-value=\"\" data-shift=\"0\"><strong>\u041b\u043e\u0433\u0438\u0440\u0443\u0439\u0442\u0435 \u043e\u0448\u0438\u0431\u043a\u0438<\/strong>, \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0447\u0430\u0442\u0430\u0439\u0442\u0435 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u2014 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u044d\u0442\u043e \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e.<\/li>\n<li data-value=\"\" data-shift=\"0\"><strong>\u041d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438<\/strong> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0435 \u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u0447\u0435\u0440\u0435\u0437 <code class=\"CodeInlined\">FileNotFoundError<\/code>). \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u0440\u043e\u0434\u0435 <code class=\"CodeInlined\">os.path.exists()<\/code>.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u041a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0434\u0435\u043b\u0430\u0435\u0442 \u0447\u0442\u043e-\u0442\u043e \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 (\u0447\u0438\u0442\u0430\u0435\u0442 \u0444\u0430\u0439\u043b, \u0434\u0435\u043b\u0438\u0442 \u0447\u0438\u0441\u043b\u0430, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0432\u0432\u043e\u0434 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f), \u0432\u0441\u0435\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u0440\u0438\u0441\u043a, \u0447\u0442\u043e \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0439\u0434\u0451\u0442 \u043d\u0435 \u0442\u0430\u043a: \u0444\u0430\u0439\u043b \u043d\u0435 \u043d\u0430\u0439\u0434\u0451\u0442\u0441\u044f, \u043d\u0430 \u043d\u043e\u043b\u044c \u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f, \u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u043c\u0435\u0441\u0442\u043e \u0447\u0438\u0441\u043b\u0430 \u0432\u0432\u0435\u0434\u0451\u0442 \u0431\u0443\u043a\u0432\u044b. \u0412 Python \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e try\/except\/finally. \u0415\u0451 \u0437\u0430\u0434\u0430\u0447\u0430 \u2014 \u043d\u0435 \u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u0443\u043f\u0430\u0441\u0442\u044c \u0441 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0439 [&hellip;]<\/p>\n","protected":false},"author":9194254,"featured_media":135498,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[556],"tags":[],"class_list":["post-135533","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"views":8,"_links":{"self":[{"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts\/135533","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/users\/9194254"}],"replies":[{"embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=135533"}],"version-history":[{"count":1,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts\/135533\/revisions"}],"predecessor-version":[{"id":135534,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts\/135533\/revisions\/135534"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/media\/135498"}],"wp:attachment":[{"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=135533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=135533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=135533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}