{"id":555,"date":"2023-08-27T14:55:50","date_gmt":"2023-08-27T09:25:50","guid":{"rendered":"https:\/\/moodle.sit.ac.in\/blog\/?p=555"},"modified":"2023-10-18T18:58:25","modified_gmt":"2023-10-18T13:28:25","slug":"python-programming-laboratory-21csl46","status":"publish","type":"post","link":"https:\/\/moodle.sit.ac.in\/blog\/python-programming-laboratory-21csl46\/","title":{"rendered":"PYTHON PROGRAMMING LABORATORY &#8211; 21CSL46"},"content":{"rendered":"\n<p>In this blog post, you will find solutions for the <strong>PYTHON PROGRAMMING LABORATORY (21CSL46)<\/strong> course work for the IV semester of <strong>VTU<\/strong> university. To follow along, you will need to set up a Python programming environment. We recommend using the Anaconda Python Distribution with Spyder as the integrated development environment (IDE). You can find the lab syllabus on the university&#8217;s website or click <a style=\"pointer-events: none;\" title=\"PPL_21CSL46 Syllabus\" href=\"https:\/\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2023\/03\/PPL_21CSL46.pdf\" target=\"_blank\" rel=\"noopener\"><strong>here<\/strong><\/a>.<\/p>\n\n\n\n<div class=\"group w-full text-gray-800 dark:text-gray-100 border-b border-black\/10 dark:border-gray-900\/50 bg-gray-50 dark:bg-[#444654]\">\n<div class=\"flex p-4 gap-4 text-base md:gap-6 md:max-w-2xl lg:max-w-[38rem] xl:max-w-3xl md:py-6 lg:px-0 m-auto\">\n<div class=\"relative flex w-[calc(100%-50px)] flex-col gap-1 md:gap-3 lg:w-[calc(100%-115px)]\">\n<div class=\"flex flex-grow flex-col gap-3\">\n<div class=\"min-h-[20px] flex items-start overflow-x-auto whitespace-pre-wrap break-words flex-col gap-4\">\n<div class=\"markdown prose w-full break-words dark:prose-invert light\">\n<p>For detailed instructions on setting up the Python programming environment on Ubuntu, please refer to my previous blog, which can be found below.<\/p>\n<p><blockquote class=\"wp-embedded-content\" data-secret=\"vUKr30FPG2\"><a href=\"https:\/\/moodle.sit.ac.in\/blog\/setting-up-anaconda-python-programming-environment\/\">Setting up Anaconda Python Programming Environment on Ubuntu<\/a><\/blockquote><iframe class=\"wp-embedded-content lazyload\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Setting up Anaconda Python Programming Environment on Ubuntu&#8221; &#8212; MyBlogosphere\" data-src=\"https:\/\/moodle.sit.ac.in\/blog\/setting-up-anaconda-python-programming-environment\/embed\/#?secret=zLd0tHqudE#?secret=vUKr30FPG2\" data-secret=\"vUKr30FPG2\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" data-load-mode=\"1\"><\/iframe><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<p>If you are looking for step-by-step instructions on how to set up the Python programming environment on a Windows system, I have provided detailed guidance in my previous blog. You can access the blog below for all the information you need.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-myblogosphere wp-block-embed-myblogosphere\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"ysxPrQeDQC\"><a href=\"https:\/\/moodle.sit.ac.in\/blog\/a-step-by-step-guide-to-setting-up-anaconda-python-distribution-on-windows\/\">A Step-by-Step Guide to Setting up Anaconda Python Distribution on Windows<\/a><\/blockquote><iframe class=\"wp-embedded-content lazyload\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;A Step-by-Step Guide to Setting up Anaconda Python Distribution on Windows&#8221; &#8212; MyBlogosphere\" data-src=\"https:\/\/moodle.sit.ac.in\/blog\/a-step-by-step-guide-to-setting-up-anaconda-python-distribution-on-windows\/embed\/#?secret=TJ5D0PQLtI#?secret=ysxPrQeDQC\" data-secret=\"ysxPrQeDQC\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" data-load-mode=\"1\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>All these solutions have been maintained at the following git repository shown below. If you want to contribute send me a PR.<\/p>\n\n\n\n<p><a href=\"https:\/\/gitlab.com\/lab_manuals\/21csl46pyprlab_vtu\" title=\"\">https:\/\/gitlab.com\/lab_manuals\/21csl46pyprlab_vtu<\/a><\/p>\n\n\n\n<p>After getting the necessary development environment setup, Now lets focus on the solutions.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><span style=\"color: #ff0000;\">Question 1<\/span>\n<ol class=\"wp-block-list\" type=\"a\">\n<li><a href=\"#01a\"><span style=\"color: #ff0000;\">Test Average<\/span><\/a><\/li>\n\n\n\n<li><a href=\"#01b\"><span style=\"color: #ff0000;\">Palindrome<\/span><\/a><\/li>\n<\/ol>\n<\/li>\n\n\n\n<li><span style=\"color: #ff0000;\">Question 2<\/span>\n<ol class=\"wp-block-list\" type=\"a\">\n<li><a href=\"#02a\"><span style=\"color: #ff0000;\">Fibonacci Sequence<\/span><\/a><\/li>\n\n\n\n<li><a href=\"#02b\"><span style=\"color: #ff0000;\">Base Conversion<\/span><\/a><\/li>\n<\/ol>\n<\/li>\n\n\n\n<li><span style=\"color: #ff0000;\">Question 3<\/span>\n<ol class=\"wp-block-list\" type=\"a\">\n<li><a href=\"#03a\"><span style=\"color: #ff0000;\">Sentence statistics<\/span><\/a><\/li>\n\n\n\n<li><a href=\"#03b\"><span style=\"color: #ff0000;\">String Similarity<\/span><\/a><\/li>\n<\/ol>\n<\/li>\n\n\n\n<li><span style=\"color: #ff0000;\">Question 4<\/span>\n<ol class=\"wp-block-list\" type=\"a\">\n<li><a href=\"#04a\"><span style=\"color: #ff0000;\">Insertion Sort &amp; Merge Sort<\/span><\/a><\/li>\n\n\n\n<li><a href=\"#04b\"><span style=\"color: #ff0000;\">Convert Roman numbers in to Integer<\/span><\/a><\/li>\n<\/ol>\n<\/li>\n\n\n\n<li><span style=\"color: #ff0000;\">Question 5<\/span>\n<ol class=\"wp-block-list\" type=\"a\">\n<li><a href=\"#05a\"><span style=\"color: #ff0000;\">Check Phone Number<\/span><\/a><\/li>\n\n\n\n<li><a href=\"#05b\"><span style=\"color: #ff0000;\">Search Phone Number &amp; Email<\/span><\/a><\/li>\n<\/ol>\n<\/li>\n\n\n\n<li><span style=\"color: #ff0000;\">Question 6<\/span>\n<ol class=\"wp-block-list\" type=\"a\">\n<li><a href=\"#06a\"><span style=\"color: #ff0000;\">File Operations<\/span><\/a><\/li>\n\n\n\n<li><a href=\"#06b\"><span style=\"color: #ff0000;\">Zip operation on a folder<\/span><\/a><\/li>\n<\/ol>\n<\/li>\n\n\n\n<li><span style=\"color: #ff0000;\">Question 7<\/span>\n<ol class=\"wp-block-list\" type=\"a\">\n<li><a href=\"#07a\"><span style=\"color: #ff0000;\">Inheritance<\/span><\/a><\/li>\n\n\n\n<li><a href=\"#07b\"><span style=\"color: #ff0000;\">Employee Details<\/span><\/a><\/li>\n<\/ol>\n<\/li>\n\n\n\n<li><span style=\"color: #ff0000;\">Question 8<\/span>\n<ol class=\"wp-block-list\" type=\"a\">\n<li><a href=\"#08a\"><span style=\"color: #ff0000;\">Polymorphism and Inheritance<\/span><\/a><\/li>\n<\/ol>\n<\/li>\n\n\n\n<li><span style=\"color: #ff0000;\">Question 9<\/span>\n<ol class=\"wp-block-list\" type=\"a\">\n<li><a href=\"#09a\"><span style=\"color: #ff0000;\">Download XKCD comics<\/span><\/a><\/li>\n\n\n\n<li><a href=\"#09b\"><span style=\"color: #ff0000;\">Spreadsheet Operations<\/span><\/a><\/li>\n<\/ol>\n<\/li>\n\n\n\n<li><span style=\"color: #ff0000;\">Question 10<\/span>\n<ol class=\"wp-block-list\" type=\"a\">\n<li><a href=\"#10a\"><span style=\"color: #ff0000;\">Merge selected pages from Multiple PDFs to a new PDF<\/span><\/a><\/li>\n\n\n\n<li><a href=\"#10b\"><span style=\"color: #ff0000;\">Fetch weather data from the JSON<\/span><\/a><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" decoding=\"async\" data-src=\"https:\/\/i0.wp.com\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2023\/10\/CodingAd.png?ssl=1\" alt=\"\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Question 1 <\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"01a\">Calculation of Test Average<\/h3>\n\n\n\n<p class=\"has-text-align-justify\">Write a python program to find the best of two test average marks out of three test\u2019s marks accepted from the user.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Python Code<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n&quot;&quot;&quot;\nCreated on Tue Feb 21 16:27:47 2023\n\n@author: Prabodh C P\n&quot;&quot;&quot;\n\nm1 = int(input(&quot;Enter marks for test1 : &quot;))\nm2 = int(input(&quot;Enter marks for test2 : &quot;))\nm3 = int(input(&quot;Enter marks for test3 : &quot;))\n\n# if m1 &lt;= m2 and m1 &lt;= m3:\n#     avgMarks = (m2+m3)\/2\n# elif m2 &lt;= m1 and m2 &lt;= m3:\n#     avgMarks = (m1+m3)\/2\n# elif m3 &lt;= m1 and m2 &lt;= m2:\n#     avgMarks = (m1+m2)\/2    \n\nbest_of_two = sorted([m1, m2, m3], reverse=True)[:2]\naverage_best_of_two = sum(best_of_two)\/2\n    \nprint(&quot;Average of best two test marks out of three test\u2019s marks is&quot;, average_best_of_two);\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">#!\/usr\/bin\/env python3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">-*-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">coding<\/span><span style=\"color: #E1E4E8\">: utf<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">8<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">-*-<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">Created on Tue Feb 21 16:27:47 202<\/span><span style=\"color: #FDAEB7; font-style: italic\">3<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">@author: Prabodh <\/span><span style=\"color: #79B8FF\">C<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">P<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">m1 = int(input(&quot;<\/span><span style=\"color: #E1E4E8\">Enter marks for <\/span><span style=\"color: #B392F0\">test1<\/span><span style=\"color: #E1E4E8\"> : <\/span><span style=\"color: #9ECBFF\">&quot;)<\/span><span style=\"color: #FDAEB7; font-style: italic\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">m2 <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">int<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">input<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Enter marks for test2 : &quot;<\/span><span style=\"color: #E1E4E8\">))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">m3 <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">int<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">input<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Enter marks for test3 : &quot;<\/span><span style=\"color: #E1E4E8\">))<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> m1 <\/span><span style=\"color: #F97583\">&lt;=<\/span><span style=\"color: #E1E4E8\"> m2 and m1 <\/span><span style=\"color: #F97583\">&lt;=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">m3<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">#     avgMarks <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> (m2<\/span><span style=\"color: #F97583\">+<\/span><span style=\"color: #E1E4E8\">m3)<\/span><span style=\"color: #F97583\">\/<\/span><span style=\"color: #79B8FF\">2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># elif m2 <\/span><span style=\"color: #F97583\">&lt;=<\/span><span style=\"color: #E1E4E8\"> m1 and m2 <\/span><span style=\"color: #F97583\">&lt;=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">m3<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">#     avgMarks <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> (m1<\/span><span style=\"color: #F97583\">+<\/span><span style=\"color: #E1E4E8\">m3)<\/span><span style=\"color: #F97583\">\/<\/span><span style=\"color: #79B8FF\">2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># elif m3 <\/span><span style=\"color: #F97583\">&lt;=<\/span><span style=\"color: #E1E4E8\"> m1 and m2 <\/span><span style=\"color: #F97583\">&lt;=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">m2<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">#     avgMarks <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> (m1<\/span><span style=\"color: #F97583\">+<\/span><span style=\"color: #E1E4E8\">m2)<\/span><span style=\"color: #F97583\">\/<\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\">    <\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">best_of_two <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">sorted<\/span><span style=\"color: #E1E4E8\">([m1, m2, m3], reverse<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\">True)[:<\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">average_best_of_two <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">sum<\/span><span style=\"color: #E1E4E8\">(best_of_two)<\/span><span style=\"color: #F97583\">\/<\/span><span style=\"color: #79B8FF\">2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Average of best two test marks out of three test\u2019s marks is&quot;<\/span><span style=\"color: #E1E4E8\">, average_best_of_two);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>The provided Python program is designed to calculate the average of the best two test marks out of three. The user is prompted to input the marks for three tests (test1, test2, and test3). The program then identifies the two highest test marks using the&nbsp;<strong>sorted<\/strong>&nbsp;function in descending order and selects the top two values. Finally, it calculates the average of these two highest marks and prints the result. This code is a concise way to determine the average performance based on the two best test scores out of three.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Enter marks for test1 : 45\nEnter marks for test2 : 39\nEnter marks for test3 : 48\nAverage of best two test marks  out of three test\u2019s marks is 46.5\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Enter marks for <\/span><span style=\"color: #B392F0\">test1<\/span><span style=\"color: #E1E4E8\"> : <\/span><span style=\"color: #79B8FF\">45<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter marks for <\/span><span style=\"color: #B392F0\">test2<\/span><span style=\"color: #E1E4E8\"> : <\/span><span style=\"color: #79B8FF\">39<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter marks for <\/span><span style=\"color: #B392F0\">test3<\/span><span style=\"color: #E1E4E8\"> : <\/span><span style=\"color: #79B8FF\">48<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Average <\/span><span style=\"color: #F97583\">of<\/span><span style=\"color: #E1E4E8\"> best two test marks  out <\/span><span style=\"color: #F97583\">of<\/span><span style=\"color: #E1E4E8\"> three test\u2019s marks is <\/span><span style=\"color: #79B8FF\">46.5<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"01b\">Palindrome Check &amp; Digit Occurrence Count<\/h3>\n\n\n\n<p class=\"has-text-align-justify\">Develop a Python program to check whether a given number is palindrome or not and also count the number of occurrences of each digit in the input number.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Python Code<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n&quot;&quot;&quot;\nCreated on Tue Feb 21 16:35:54 2023\n\n@author: Prabodh C P\n&quot;&quot;&quot;\n\nfrom collections import Counter\n\nvalue = input(&quot;Enter a value : &quot;)\nif value == value[::-1]:\n    print(&quot;Palindrome&quot;)\nelse:\n    print(&quot;Not Palindrome&quot;)\n    \ncounted_dict = Counter(value)\nfor key in sorted(counted_dict.keys()):\n    print(f'{key} appears {counted_dict[key]} times');\n\n&quot;&quot;&quot;\n#Alternate way to count appearances\nfor i in range(10):\n    if value.count(str(i)) &gt; 0:\n        print(f'{str(i)} appears {value.count(str(i))} times')\n&quot;&quot;&quot;\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">#!\/usr\/bin\/env python3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">-*-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">coding<\/span><span style=\"color: #E1E4E8\">: utf<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">8<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">-*-<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">Created on Tue Feb 21 16:35:54 202<\/span><span style=\"color: #FDAEB7; font-style: italic\">3<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">@author: Prabodh <\/span><span style=\"color: #79B8FF\">C<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">P<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">from collections import Counte<\/span><span style=\"color: #FDAEB7; font-style: italic\">r<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">value <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">input<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Enter a value : &quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> value <\/span><span style=\"color: #F97583\">==<\/span><span style=\"color: #E1E4E8\"> value[::<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">]:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Palindrome&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">else<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Not Palindrome&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">counted_dict <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Counter<\/span><span style=\"color: #E1E4E8\">(value)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">for key <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">sorted<\/span><span style=\"color: #E1E4E8\">(counted_dict.<\/span><span style=\"color: #B392F0\">keys<\/span><span style=\"color: #E1E4E8\">()):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(f<\/span><span style=\"color: #9ECBFF\">&#39;{key} appears {counted_dict[key]} times&#39;<\/span><span style=\"color: #E1E4E8\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">#Alternate way to count appearance<\/span><span style=\"color: #FDAEB7; font-style: italic\">s<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">for i <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">range<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #79B8FF\">10<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> value.<\/span><span style=\"color: #B392F0\">count<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">str<\/span><span style=\"color: #E1E4E8\">(i)) <\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">0<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(f<\/span><span style=\"color: #9ECBFF\">&#39;{str(i)} appears {value.count(str(i))} times&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>The provided Python script is a versatile program that performs two key tasks: palindrome checking and character counting.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Palindrome Check:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The user is prompted to input a value.<\/li>\n\n\n\n<li>The script determines whether the entered value is a palindrome, meaning it reads the same backward as forward.<\/li>\n\n\n\n<li>If the input is a palindrome, it prints \u201cPalindrome\u201d; otherwise, it prints \u201cNot Palindrome.\u201d<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Character Count:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The script utilizes the&nbsp;<code>Counter<\/code>&nbsp;class from the&nbsp;<code>collections<\/code>&nbsp;module to efficiently count the occurrences of each character in the input string.<\/li>\n\n\n\n<li>It then sorts the keys of the counted dictionary and prints each character along with the number of times it appears.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Alternate Character Count (commented-out):<\/strong>\n<ul class=\"wp-block-list\">\n<li>The script provides an alternative method using a loop to count the occurrences of each digit (0 to 9) in the input string.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>This script is not only a quick and effective way to check for palindromes but also serves as a handy tool for analyzing the frequency of characters in a given input. The inclusion of alternative methods showcases the flexibility of the script, making it a valuable resource for both palindrome detection and character frequency analysis.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Enter a value : 1234234\nNot Palindrome\n1 appears 1 times\n2 appears 2 times\n3 appears 2 times\n4 appears 2 times\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Enter a <\/span><span style=\"color: #B392F0\">value<\/span><span style=\"color: #E1E4E8\"> : <\/span><span style=\"color: #79B8FF\">1234234<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Not Palindrome<\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> appears <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> times<\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\"> appears <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\"> times<\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">3<\/span><span style=\"color: #E1E4E8\"> appears <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\"> times<\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">4<\/span><span style=\"color: #E1E4E8\"> appears <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\"> times<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Enter a value : 12321\nPalindrome\n1 appears 2 times\n2 appears 2 times\n3 appears 1 times\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Enter a <\/span><span style=\"color: #B392F0\">value<\/span><span style=\"color: #E1E4E8\"> : <\/span><span style=\"color: #79B8FF\">12321<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Palindrome<\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> appears <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\"> times<\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\"> appears <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\"> times<\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">3<\/span><span style=\"color: #E1E4E8\"> appears <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> times<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Question 2<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"02a\">Fibonacci Sequence<\/h3>\n\n\n\n<p class=\"has-text-align-justify\">Defined as a function F as Fn = Fn-1 + Fn-2. Write a Python program which accepts a value for N (where N &gt;0) as input and pass this value to the function. Display suitable error message if the condition for input value is not followed.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Python Code<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n&quot;&quot;&quot;\nCreated on Tue Feb 21 16:46:55 2023\n\n@author: Prabodh C P\n&quot;&quot;&quot;\n\ndef fn(n):\n    if n &lt;= 2:\n        return n - 1\n    else:\n        return fn(n-1) + fn(n-2)\n\ntry:\n    num = int(input(&quot;Enter a number : &quot;))\n    if num &gt; 0:\n        print(f' fn({num}) = {fn(num)}')\n    else:\n        print(&quot;Input should be greater than 0&quot;)\nexcept ValueError:\n    print(&quot;Try with numeric value&quot;)\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">#!\/usr\/bin\/env python3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">-*-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">coding<\/span><span style=\"color: #E1E4E8\">: utf<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">8<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">-*-<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">Created on Tue Feb 21 16:46:55 202<\/span><span style=\"color: #FDAEB7; font-style: italic\">3<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">@author: Prabodh <\/span><span style=\"color: #79B8FF\">C<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">P<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">def fn(n)<\/span><span style=\"color: #FDAEB7; font-style: italic\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> n <\/span><span style=\"color: #F97583\">&lt;=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #E1E4E8\"> n <\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">else<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">fn<\/span><span style=\"color: #E1E4E8\">(n<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">) <\/span><span style=\"color: #F97583\">+<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">fn<\/span><span style=\"color: #E1E4E8\">(n<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">try<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    num <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">int<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">input<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Enter a number : &quot;<\/span><span style=\"color: #E1E4E8\">))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> num <\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">0<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(f<\/span><span style=\"color: #9ECBFF\">&#39; fn({num}) = {fn(num)}&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">else<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Input should be greater than 0&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">except <\/span><span style=\"color: #B392F0\">ValueError<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Try with numeric value&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>The provided Python script introduces a recursive implementation to calculate terms in the Fibonacci sequence. Here\u2019s a concise overview:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Recursive Fibonacci Function:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The script defines a function&nbsp;<code>fn<\/code>&nbsp;that calculates the nth term in the Fibonacci sequence.<\/li>\n\n\n\n<li>If the input&nbsp;<code>n<\/code>&nbsp;is 1 or 2, the function returns&nbsp;<code>n - 1<\/code>.<\/li>\n\n\n\n<li>For&nbsp;<code>n<\/code>&nbsp;greater than 2, the function recursively calls itself with&nbsp;<code>n-1<\/code>&nbsp;and&nbsp;<code>n-2<\/code>&nbsp;and returns the sum of the results.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>User Input and Output:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The user is prompted to enter a number.<\/li>\n\n\n\n<li>If a positive integer is provided, the script prints the result of calling the&nbsp;<code>fn<\/code>&nbsp;function with that number, representing the nth term in the Fibonacci sequence.<\/li>\n\n\n\n<li>If the entered value is not a positive integer, it prompts the user to enter a value greater than 0.<\/li>\n\n\n\n<li>If a non-numeric value is entered, it catches the&nbsp;<code>ValueError<\/code>&nbsp;and suggests trying with a numeric value.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>This script serves as a simple yet illustrative example of a recursive function for computing Fibonacci sequence terms, offering insights into recursive algorithms and user input handling in Python.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Enter a number : 5\nfn(5) = 3\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Enter a <\/span><span style=\"color: #B392F0\">number<\/span><span style=\"color: #E1E4E8\"> : <\/span><span style=\"color: #79B8FF\">5<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">fn<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\">) <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">3<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Enter a number: -3\nInput should be greater than 0\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Enter a <\/span><span style=\"color: #B392F0\">number<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Input should be greater than <\/span><span style=\"color: #79B8FF\">0<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Enter a number: abc\nTry with numeric value\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Enter a <\/span><span style=\"color: #B392F0\">number<\/span><span style=\"color: #E1E4E8\">: abc<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Try <\/span><span style=\"color: #F97583\">with<\/span><span style=\"color: #E1E4E8\"> numeric value<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"02b\">Binary to Decimal &amp; Octal to Hexadecimal Conversion<\/h3>\n\n\n\n<p class=\"has-text-align-justify\">Develop a python program to convert binary to decimal, octal to hexadecimal using functions.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Python Code<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n&quot;&quot;&quot;\nCreated on Tue Feb 21 20:57:52 2023\n\n@author: Prabodh C P\n&quot;&quot;&quot;\n\n&quot;&quot;&quot;\ndef bin2Dec(val):\n    rev=val[::-1]\n    dec = 0\n    i = 0\n    for dig in rev:\n        dec += int(dig) * 2**i\n        i += 1\n    \n    return dec\n\n\ndef oct2Hex(val):\n    rev=val[::-1]\n    dec = 0\n    i = 0\n    for dig in rev:\n        dec += int(dig) * 8**i\n        i += 1\n    list=[]\n    while dec != 0:\n        list.append(dec%16)\n        dec = dec \/\/ 16\n        \n    nl=[]\n    for elem in list[::-1]:\n        if elem &lt;= 9:\n            nl.append(str(elem))\n        else:\n            nl.append(chr(ord('A') + (elem -10)))\n    hex = &quot;&quot;.join(nl)\n    \n    return hex\n\n\nbase = 2\nnum1 = input(&quot;Enter a binary number : &quot;)    \n# print(bin2Dec(num1))\nprint(int(num1, base))\n&quot;&quot;&quot;\n\n#A better implementation\ndef bin2Dec(val):\n    return int(val, 2)\n    \ndef oct2Hex(val):\n    return int(val, 8)\n\ntry:\n    num1 = input(&quot;Enter a binary number : &quot;)    \n    print(bin2Dec(num1))\nexcept ValueError:\n    print(&quot;Invalid literal in input with base 2&quot;)\n    \ntry:\n    num2 = input(&quot;Enter a octal number : &quot;)\n    print(oct2Hex(num2))\nexcept ValueError:\n    print(&quot;Invalid literal in input with base 8&quot;)\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">#!\/usr\/bin\/env python3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">-*-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">coding<\/span><span style=\"color: #E1E4E8\">: utf<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">8<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">-*-<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">Created on Tue Feb 21 20:57:52 202<\/span><span style=\"color: #FDAEB7; font-style: italic\">3<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">@author: Prabodh <\/span><span style=\"color: #79B8FF\">C<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">P<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">def <\/span><span style=\"color: #B392F0\">bin2Dec<\/span><span style=\"color: #E1E4E8\">(val):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    rev<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\">val[::<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    dec <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    i <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    for dig <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">rev<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        dec <\/span><span style=\"color: #F97583\">+=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">int<\/span><span style=\"color: #E1E4E8\">(dig) <\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #F97583\">**<\/span><span style=\"color: #E1E4E8\">i<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        i <\/span><span style=\"color: #F97583\">+=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #E1E4E8\"> dec<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">def <\/span><span style=\"color: #B392F0\">oct2Hex<\/span><span style=\"color: #E1E4E8\">(val):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    rev<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\">val[::<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    dec <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    i <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    for dig <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">rev<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        dec <\/span><span style=\"color: #F97583\">+=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">int<\/span><span style=\"color: #E1E4E8\">(dig) <\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">8<\/span><span style=\"color: #F97583\">**<\/span><span style=\"color: #E1E4E8\">i<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        i <\/span><span style=\"color: #F97583\">+=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    list<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\">[]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">while<\/span><span style=\"color: #E1E4E8\"> dec <\/span><span style=\"color: #F97583\">!=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">0<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        list.<\/span><span style=\"color: #B392F0\">append<\/span><span style=\"color: #E1E4E8\">(dec<\/span><span style=\"color: #F97583\">%<\/span><span style=\"color: #79B8FF\">16<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        dec <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> dec <\/span><span style=\"color: #6A737D\">\/\/ 16<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    nl<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\">[]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    for elem <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> list[::<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">]:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> elem <\/span><span style=\"color: #F97583\">&lt;=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">9<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            nl.<\/span><span style=\"color: #B392F0\">append<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">str<\/span><span style=\"color: #E1E4E8\">(elem))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #F97583\">else<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            nl.<\/span><span style=\"color: #B392F0\">append<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">chr<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">ord<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;A&#39;<\/span><span style=\"color: #E1E4E8\">) <\/span><span style=\"color: #F97583\">+<\/span><span style=\"color: #E1E4E8\"> (elem <\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">10<\/span><span style=\"color: #E1E4E8\">)))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    hex <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&quot;&quot;<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">join<\/span><span style=\"color: #E1E4E8\">(nl)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #E1E4E8\"> hex<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">base <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">num1 <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">input<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Enter a binary number : &quot;<\/span><span style=\"color: #E1E4E8\">)    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">bin2Dec<\/span><span style=\"color: #E1E4E8\">(num1))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">int<\/span><span style=\"color: #E1E4E8\">(num1, base))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">#A better implementatio<\/span><span style=\"color: #FDAEB7; font-style: italic\">n<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">def <\/span><span style=\"color: #B392F0\">bin2Dec<\/span><span style=\"color: #E1E4E8\">(val):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">int<\/span><span style=\"color: #E1E4E8\">(val, <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">def <\/span><span style=\"color: #B392F0\">oct2Hex<\/span><span style=\"color: #E1E4E8\">(val):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">int<\/span><span style=\"color: #E1E4E8\">(val, <\/span><span style=\"color: #79B8FF\">8<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">try<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    num1 <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">input<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Enter a binary number : &quot;<\/span><span style=\"color: #E1E4E8\">)    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">bin2Dec<\/span><span style=\"color: #E1E4E8\">(num1))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">except <\/span><span style=\"color: #B392F0\">ValueError<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Invalid literal in input with base 2&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">try<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    num2 <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">input<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Enter a octal number : &quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">oct2Hex<\/span><span style=\"color: #E1E4E8\">(num2))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">except <\/span><span style=\"color: #B392F0\">ValueError<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Invalid literal in input with base 8&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This Python script includes two functions&nbsp;<strong>bin2Dec<\/strong>&nbsp;and&nbsp;<strong>oct2Hex<\/strong>&nbsp;for converting binary to decimal and octal to hexadecimal, respectively. The script takes user input for binary and octal numbers and converts them using these functions. Here\u2019s a brief description:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Conversion Functions:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The&nbsp;<code>bin2Dec<\/code>&nbsp;function converts a binary number to decimal using the&nbsp;<code>int()<\/code>&nbsp;function with base 2.<\/li>\n\n\n\n<li>The&nbsp;<code>oct2Hex<\/code>&nbsp;function converts an octal number to hexadecimal using the&nbsp;<code>int()<\/code>&nbsp;function with base 8.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>User Input Handling:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The script includes&nbsp;<code>try-except<\/code>&nbsp;blocks to catch&nbsp;<code>ValueError<\/code>&nbsp;in case of invalid input.<\/li>\n\n\n\n<li>It prompts the user for a binary and an octal number, converts them, and prints the results.<\/li>\n\n\n\n<li>If an invalid input is detected, it prints an error message.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Enter a binary number: 101010\n42\n\nEnter an octal number: 755\n0x1FD\n\nEnter a binary number: 11011a\nInvalid literal in input with base 2\n\nEnter an octal number: 1298\nInvalid literal in input with base 8\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Enter a binary <\/span><span style=\"color: #B392F0\">number<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">101010<\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">42<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter an octal <\/span><span style=\"color: #B392F0\">number<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">755<\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">0x1FD<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter a binary <\/span><span style=\"color: #B392F0\">number<\/span><span style=\"color: #E1E4E8\">: 11011a<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Invalid literal <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> input <\/span><span style=\"color: #F97583\">with<\/span><span style=\"color: #E1E4E8\"> base <\/span><span style=\"color: #79B8FF\">2<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter an octal <\/span><span style=\"color: #B392F0\">number<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1298<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Invalid literal <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> input <\/span><span style=\"color: #F97583\">with<\/span><span style=\"color: #E1E4E8\"> base <\/span><span style=\"color: #79B8FF\">8<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Question 3<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"03a\">Sentence Statistics<\/h3>\n\n\n\n<p>Write a Python program that accepts a sentence and find the number of words, digits, uppercase letters and lowercase letters.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Python Code<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n&quot;&quot;&quot;\nCreated on Wed Feb 22 01:37:07 2023\n\n@author: Prabodh C P\n&quot;&quot;&quot;\n\nimport string\n\nsentence = input(&quot;Enter a sentence : &quot;)\n\nwordList = sentence.strip().split(&quot; &quot;)\nprint(f'This sentence has {len(wordList)} words', end='\\n\\n')\n\ndigit_count = uppercase_count = lowercase_count = 0\n\n&quot;&quot;&quot;\nfor ch in sentence:\n    if '0' &lt;= ch &lt;= '9':\n        digit_count += 1\n    elif 'A' &lt;= ch &lt;= 'Z':\n        uppercase_count += 1\n    elif 'a' &lt;= ch &lt;= 'z':\n        lowercase_count += 1\n&quot;&quot;&quot;\n\nfor character in sentence:\n    if character in string.digits: \n        digit_count += 1\n    elif character in string.ascii_uppercase: \n        uppercase_count += 1\n    elif character in string.ascii_lowercase:\n        lowercase_count += 1\n\nprint(f'This sentence has {digit_count} digits',\n      f' {uppercase_count} upper case letters',\n      f' {lowercase_count} lower case letters', sep='\\n')\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">#!\/usr\/bin\/env python3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">-*-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">coding<\/span><span style=\"color: #E1E4E8\">: utf<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">8<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">-*-<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">Created on Wed Feb 22 01:37:07 202<\/span><span style=\"color: #FDAEB7; font-style: italic\">3<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">@author: Prabodh <\/span><span style=\"color: #79B8FF\">C<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">P<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">import strin<\/span><span style=\"color: #FDAEB7; font-style: italic\">g<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">sentence <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">input<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Enter a sentence : &quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">wordList <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> sentence.<\/span><span style=\"color: #B392F0\">strip<\/span><span style=\"color: #E1E4E8\">().<\/span><span style=\"color: #B392F0\">split<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot; &quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(f<\/span><span style=\"color: #9ECBFF\">&#39;This sentence has {len(wordList)} words&#39;<\/span><span style=\"color: #E1E4E8\">, end<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #9ECBFF\">&#39;<\/span><span style=\"color: #79B8FF\">\\n\\n<\/span><span style=\"color: #9ECBFF\">&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">digit_count <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> uppercase_count <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> lowercase_count <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">0<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">for ch in sentence<\/span><span style=\"color: #FDAEB7; font-style: italic\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&#39;0&#39;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">&lt;=<\/span><span style=\"color: #E1E4E8\"> ch <\/span><span style=\"color: #F97583\">&lt;=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&#39;9&#39;<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        digit_count <\/span><span style=\"color: #F97583\">+=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    elif <\/span><span style=\"color: #9ECBFF\">&#39;A&#39;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">&lt;=<\/span><span style=\"color: #E1E4E8\"> ch <\/span><span style=\"color: #F97583\">&lt;=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&#39;Z&#39;<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        uppercase_count <\/span><span style=\"color: #F97583\">+=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    elif <\/span><span style=\"color: #9ECBFF\">&#39;a&#39;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">&lt;=<\/span><span style=\"color: #E1E4E8\"> ch <\/span><span style=\"color: #F97583\">&lt;=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&#39;z&#39;<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        lowercase_count <\/span><span style=\"color: #F97583\">+=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">for character in sentence<\/span><span style=\"color: #FDAEB7; font-style: italic\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> character <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> string.digits: <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        digit_count <\/span><span style=\"color: #F97583\">+=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    elif character <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> string.ascii_uppercase: <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        uppercase_count <\/span><span style=\"color: #F97583\">+=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    elif character <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> string.ascii_lowercase:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        lowercase_count <\/span><span style=\"color: #F97583\">+=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(f<\/span><span style=\"color: #9ECBFF\">&#39;This sentence has {digit_count} digits&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      f<\/span><span style=\"color: #9ECBFF\">&#39; {uppercase_count} upper case letters&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      f<\/span><span style=\"color: #9ECBFF\">&#39; {lowercase_count} lower case letters&#39;<\/span><span style=\"color: #E1E4E8\">, sep<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #9ECBFF\">&#39;<\/span><span style=\"color: #79B8FF\">\\n<\/span><span style=\"color: #9ECBFF\">&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>The above Python program is designed to analyse a user-inputted sentence, providing information on the number of words, digits, uppercase letters, and lowercase letters in the given text. Here\u2019s a concise overview:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Word Count:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The script splits the input sentence into words and prints the count of words in the sentence.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Character Analysis:<\/strong>\n<ul class=\"wp-block-list\">\n<li>It then iterates through each character in the sentence.<\/li>\n\n\n\n<li>The script counts the number of digits, uppercase letters, and lowercase letters using the&nbsp;<code>string<\/code>&nbsp;module.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Print Results:<\/strong>\n<ul class=\"wp-block-list\">\n<li>Finally, it prints the counts of digits, uppercase letters, and lowercase letters in the given sentence.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>This script serves as a versatile tool for quickly extracting key statistics from a user-provided sentence, offering insights into the composition of the text in terms of words and character types.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Enter a sentence : Rama went to Devaraja market to pick 2 kgs of vegetable\nThis sentence has 11 words\n\nThis sentence has 1 digits \n2 upper case letters \n42 lower case letters\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Enter a <\/span><span style=\"color: #B392F0\">sentence<\/span><span style=\"color: #E1E4E8\"> : Rama went to Devaraja market to pick <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\"> kgs <\/span><span style=\"color: #F97583\">of<\/span><span style=\"color: #E1E4E8\"> vegetable<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">This sentence has <\/span><span style=\"color: #79B8FF\">11<\/span><span style=\"color: #E1E4E8\"> words<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">This sentence has <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> digits <\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\"> upper <\/span><span style=\"color: #F97583\">case<\/span><span style=\"color: #E1E4E8\"> letters <\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">42<\/span><span style=\"color: #E1E4E8\"> lower <\/span><span style=\"color: #F97583\">case<\/span><span style=\"color: #E1E4E8\"> letters<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"03b\">String Similarity<\/h3>\n\n\n\n<p class=\"has-text-align-justify\">Write a Python program to find the string similarity between two given strings.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Python Code<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n&quot;&quot;&quot;\nCreated on Wed Feb 22 01:48:17 2023\n\n@author: Prabodh C P\n&quot;&quot;&quot;\n\n&quot;&quot;&quot;\nstr1 = input(&quot;Enter String 1 \\n&quot;).lower()\nstr2 = input(&quot;Enter String 2 \\n&quot;).lower()\n\n# if len(str2) &lt; len(str1):\n#     short = len(str2)\n#     long = len(str1)\n# else:\n#     short = len(str1)\n#     long = len(str2)\n\nstring_1_length = len(str1)\nstring_2_length = len(str2)\n\nshort_string_length, long_string_length = min(string_1_length, string_2_length), max(string_1_length, string_2_length) \n    \n\nmatch_count = 0\nfor i in range(short_string_length):\n    if str1[i] == str2[i]:\n        match_count += 1\n\nprint(&quot;Similarity between two said strings:&quot;)\nprint(match_count\/long_string_length)\n\n\n&quot;&quot;&quot;\n# An alternative solution to the same problem using Python libraries\n\nfrom difflib import SequenceMatcher\n\nstr1 = input(&quot;Enter String 1 : &quot;)\nstr2 = input(&quot;Enter String 2 : &quot;)\n\nsim = SequenceMatcher(None, str1, str2).ratio()\n\nprint(&quot;Similarity between strings \\&quot;&quot; + str1 + &quot;\\&quot; and \\&quot;&quot; + str2 + &quot;\\&quot; is : &quot;,sim)\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">#!\/usr\/bin\/env python3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">-*-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">coding<\/span><span style=\"color: #E1E4E8\">: utf<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">8<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">-*-<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">Created on Wed Feb 22 01:48:17 202<\/span><span style=\"color: #FDAEB7; font-style: italic\">3<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">@author: Prabodh <\/span><span style=\"color: #79B8FF\">C<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">P<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">str1 <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">input<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Enter String 1 <\/span><span style=\"color: #79B8FF\">\\n<\/span><span style=\"color: #9ECBFF\">&quot;<\/span><span style=\"color: #E1E4E8\">).<\/span><span style=\"color: #B392F0\">lower<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">str2 <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">input<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Enter String 2 <\/span><span style=\"color: #79B8FF\">\\n<\/span><span style=\"color: #9ECBFF\">&quot;<\/span><span style=\"color: #E1E4E8\">).<\/span><span style=\"color: #B392F0\">lower<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">len<\/span><span style=\"color: #E1E4E8\">(str2) <\/span><span style=\"color: #F97583\">&lt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">len<\/span><span style=\"color: #E1E4E8\">(str1):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">#     short <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">len<\/span><span style=\"color: #E1E4E8\">(str2)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">#     long <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">len<\/span><span style=\"color: #E1E4E8\">(str1)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">else<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">#     short <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">len<\/span><span style=\"color: #E1E4E8\">(str1)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">#     long <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">len<\/span><span style=\"color: #E1E4E8\">(str2)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">string_1_length <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">len<\/span><span style=\"color: #E1E4E8\">(str1)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">string_2_length <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">len<\/span><span style=\"color: #E1E4E8\">(str2)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">short_string_length, long_string_length <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">min<\/span><span style=\"color: #E1E4E8\">(string_1_length, string_2_length), <\/span><span style=\"color: #B392F0\">max<\/span><span style=\"color: #E1E4E8\">(string_1_length, string_2_length) <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">match_count <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">for i <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">range<\/span><span style=\"color: #E1E4E8\">(short_string_length):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> str1[i] <\/span><span style=\"color: #F97583\">==<\/span><span style=\"color: #E1E4E8\"> str2[i]:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        match_count <\/span><span style=\"color: #F97583\">+=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Similarity between two said strings:&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(match_count<\/span><span style=\"color: #F97583\">\/<\/span><span style=\"color: #E1E4E8\">long_string_length)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\"># An alternative solution to the same problem using Python librarie<\/span><span style=\"color: #FDAEB7; font-style: italic\">s<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">from difflib <\/span><span style=\"color: #F97583\">import<\/span><span style=\"color: #E1E4E8\"> SequenceMatcher<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">str1 = input(<\/span><span style=\"color: #9ECBFF\">&quot;Enter String 1 : &quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">str2 = input(<\/span><span style=\"color: #9ECBFF\">&quot;Enter String 2 : &quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">sim = SequenceMatcher(None, str1, str2).ratio()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">print(<\/span><span style=\"color: #9ECBFF\">&quot;Similarity between strings <\/span><span style=\"color: #79B8FF\">\\&quot;<\/span><span style=\"color: #9ECBFF\">&quot;<\/span><span style=\"color: #E1E4E8\"> + str1 + <\/span><span style=\"color: #9ECBFF\">&quot;<\/span><span style=\"color: #79B8FF\">\\&quot;<\/span><span style=\"color: #9ECBFF\"> and <\/span><span style=\"color: #79B8FF\">\\&quot;<\/span><span style=\"color: #9ECBFF\">&quot;<\/span><span style=\"color: #E1E4E8\"> + str2 + <\/span><span style=\"color: #9ECBFF\">&quot;<\/span><span style=\"color: #79B8FF\">\\&quot;<\/span><span style=\"color: #9ECBFF\"> is : &quot;<\/span><span style=\"color: #E1E4E8\">,sim)<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>The provided Python script is designed to compare the similarity between two user-inputted strings. The user is prompted to input two strings, and the script, after converting them to lowercase for case-insensitive comparison, calculates the similarity by counting the matching characters at corresponding positions. The similarity is then expressed as a ratio relative to the length of the longer string. Here\u2019s a brief overview:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>User Input:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The script prompts the user to enter two strings.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>String Comparison:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The script then iterates through characters at corresponding positions and counts the matches.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Similarity Ratio:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The similarity between the two strings is calculated as the ratio of the count of matching characters to the length of the longer string.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Alternative Solution :<\/strong>\n<ul class=\"wp-block-list\">\n<li>The script includes an alternative solution using the&nbsp;<code>SequenceMatcher<\/code>&nbsp;class from the&nbsp;<code>difflib<\/code>&nbsp;library, demonstrating a different approach to calculating string similarity.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>This script offers a straightforward way to measure the similarity between two strings and presents an alternative solution using Python libraries for a comparative understanding. It\u2019s a useful tool for users interested in comparing the likeness of textual data.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Enter String 1 : Python Exercises\nEnter String 2 : Python Exercise \nSimilarity between strings &quot;Python Exercises&quot; and &quot;Python Exercise&quot; is :  0.967741935483871\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Enter String <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> : Python Exercises<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter String <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\"> : Python Exercise <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Similarity between strings <\/span><span style=\"color: #9ECBFF\">&quot;Python Exercises&quot;<\/span><span style=\"color: #E1E4E8\"> and <\/span><span style=\"color: #9ECBFF\">&quot;Python Exercise&quot;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">is<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">0.967741935483871<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Enter String 1 : Python Exercises\nEnter String 2 : Python Exercises\nSimilarity between strings &quot;Python Exercises&quot; and &quot;Python Exercises&quot; is :  1.0\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Enter String <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> : Python Exercises<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter String <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\"> : Python Exercises<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Similarity between strings <\/span><span style=\"color: #9ECBFF\">&quot;Python Exercises&quot;<\/span><span style=\"color: #E1E4E8\"> and <\/span><span style=\"color: #9ECBFF\">&quot;Python Exercises&quot;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">is<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">1.0<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Question 4<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"04a\">Insertion Sort &amp; Merge Sort on lists<\/h3>\n\n\n\n<p class=\"has-text-align-justify\">Write a python program to implement insertion sort and merge sort using lists.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Python Code<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n&quot;&quot;&quot;\nCreated on Thu Mar  9 04:06:09 2023\n\n@author: Prabodh C P\n&quot;&quot;&quot;\n\nimport random\n\ndef merge_sort(lst):\n    if len(lst) &gt; 1:\n        mid = len(lst) \/\/ 2\n        left_half = lst[:mid]\n        right_half = lst[mid:]\n\n        merge_sort(left_half)\n        merge_sort(right_half)\n\n        i = j = k = 0\n\n        while i &lt; len(left_half) and j &lt; len(right_half):\n            if left_half[i] &lt; right_half[j]:\n                lst[k] = left_half[i]\n                i += 1\n            else:\n                lst[k] = right_half[j]\n                j += 1\n            k += 1\n\n        while i &lt; len(left_half):\n            lst[k] = left_half[i]\n            i += 1\n            k += 1\n\n        while j &lt; len(right_half):\n            lst[k] = right_half[j]\n            j += 1\n            k += 1\n\n    return lst\n\n\ndef insertion_sort(arr):\n    for i in range(1, len(arr)):\n        key = arr[i]\n        j = i - 1\n        while j &gt;= 0 and key &lt; arr[j]:\n            arr[j + 1] = arr[j]\n            j -= 1\n        arr[j + 1] = key\n\nmy_list = []\n\nfor i in range(10):\n    my_list.append(random.randint(0, 999))\n\nprint(&quot;\\nUnsorted List&quot;)\nprint(my_list)\nprint(&quot;Sorting using Insertion Sort&quot;)\ninsertion_sort(my_list)\nprint(my_list)\n\n\nmy_list = []\n\nfor i in range(10):\n    my_list.append(random.randint(0, 999))\n\nprint(&quot;\\nUnsorted List&quot;)\nprint(my_list)\nprint(&quot;Sorting using Merge Sort&quot;)\nmerge_sort(my_list)\nprint(my_list)\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">#!\/usr\/bin\/env python3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">-*-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">coding<\/span><span style=\"color: #E1E4E8\">: utf<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">8<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">-*-<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">Created on Thu Mar  9 04:06:09 202<\/span><span style=\"color: #FDAEB7; font-style: italic\">3<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">@author: Prabodh <\/span><span style=\"color: #79B8FF\">C<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">P<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">import rando<\/span><span style=\"color: #FDAEB7; font-style: italic\">m<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">def <\/span><span style=\"color: #B392F0\">merge_sort<\/span><span style=\"color: #E1E4E8\">(lst):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">len<\/span><span style=\"color: #E1E4E8\">(lst) <\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        mid <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">len<\/span><span style=\"color: #E1E4E8\">(lst) <\/span><span style=\"color: #6A737D\">\/\/ 2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        left_half <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> lst[:mid]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        right_half <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> lst[mid:]<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">merge_sort<\/span><span style=\"color: #E1E4E8\">(left_half)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">merge_sort<\/span><span style=\"color: #E1E4E8\">(right_half)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        i <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> j <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> k <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">0<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #F97583\">while<\/span><span style=\"color: #E1E4E8\"> i <\/span><span style=\"color: #F97583\">&lt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">len<\/span><span style=\"color: #E1E4E8\">(left_half) and j <\/span><span style=\"color: #F97583\">&lt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">len<\/span><span style=\"color: #E1E4E8\">(right_half):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> left_half[i] <\/span><span style=\"color: #F97583\">&lt;<\/span><span style=\"color: #E1E4E8\"> right_half[j]:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">                lst[k] <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> left_half[i]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">                i <\/span><span style=\"color: #F97583\">+=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            <\/span><span style=\"color: #F97583\">else<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">                lst[k] <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> right_half[j]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">                j <\/span><span style=\"color: #F97583\">+=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            k <\/span><span style=\"color: #F97583\">+=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #F97583\">while<\/span><span style=\"color: #E1E4E8\"> i <\/span><span style=\"color: #F97583\">&lt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">len<\/span><span style=\"color: #E1E4E8\">(left_half):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            lst[k] <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> left_half[i]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            i <\/span><span style=\"color: #F97583\">+=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            k <\/span><span style=\"color: #F97583\">+=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #F97583\">while<\/span><span style=\"color: #E1E4E8\"> j <\/span><span style=\"color: #F97583\">&lt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">len<\/span><span style=\"color: #E1E4E8\">(right_half):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            lst[k] <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> right_half[j]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            j <\/span><span style=\"color: #F97583\">+=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            k <\/span><span style=\"color: #F97583\">+=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #E1E4E8\"> lst<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">def <\/span><span style=\"color: #B392F0\">insertion_sort<\/span><span style=\"color: #E1E4E8\">(arr):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    for i <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">range<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #B392F0\">len<\/span><span style=\"color: #E1E4E8\">(arr)):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        key <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> arr[i]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        j <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> i <\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #F97583\">while<\/span><span style=\"color: #E1E4E8\"> j <\/span><span style=\"color: #F97583\">&gt;=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">0<\/span><span style=\"color: #E1E4E8\"> and key <\/span><span style=\"color: #F97583\">&lt;<\/span><span style=\"color: #E1E4E8\"> arr[j]:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            arr[j <\/span><span style=\"color: #F97583\">+<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">] <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> arr[j]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            j <\/span><span style=\"color: #F97583\">-=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        arr[j <\/span><span style=\"color: #F97583\">+<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">] <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> key<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">my_list <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> []<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">for i <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">range<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #79B8FF\">10<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    my_list.<\/span><span style=\"color: #B392F0\">append<\/span><span style=\"color: #E1E4E8\">(random.<\/span><span style=\"color: #B392F0\">randint<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #79B8FF\">0<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">999<\/span><span style=\"color: #E1E4E8\">))<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;<\/span><span style=\"color: #79B8FF\">\\n<\/span><span style=\"color: #9ECBFF\">Unsorted List&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(my_list)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Sorting using Insertion Sort&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">insertion_sort<\/span><span style=\"color: #E1E4E8\">(my_list)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(my_list)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">my_list <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> []<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">for i <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">range<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #79B8FF\">10<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    my_list.<\/span><span style=\"color: #B392F0\">append<\/span><span style=\"color: #E1E4E8\">(random.<\/span><span style=\"color: #B392F0\">randint<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #79B8FF\">0<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">999<\/span><span style=\"color: #E1E4E8\">))<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;<\/span><span style=\"color: #79B8FF\">\\n<\/span><span style=\"color: #9ECBFF\">Unsorted List&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(my_list)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Sorting using Merge Sort&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">merge_sort<\/span><span style=\"color: #E1E4E8\">(my_list)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(my_list)<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This Python program demonstrates two popular sorting algorithms: Insertion Sort and Merge Sort. The code begins by generating a random list of integers. First, it applies the Insertion Sort algorithm to sort the list in ascending order. Then, it generates a new random list and applies the Merge Sort algorithm to achieve the same result.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Insertion Sort:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The <code>insertion_sort<\/code> function implements the Insertion Sort algorithm, which iterates through the list and places each element in its correct position relative to the elements before it.<\/li>\n\n\n\n<li>The program generates a random list, prints the unsorted list, applies Insertion Sort, and prints the sorted list.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Merge Sort:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The <code>merge_sort<\/code> function implements the Merge Sort algorithm, a divide-and-conquer approach that recursively divides the list into halves until individual elements are reached, then merges them in a sorted manner.<\/li>\n\n\n\n<li>The program generates another random list, prints the unsorted list, applies Merge Sort, and prints the sorted list.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>The code showcases the functionality of these sorting algorithms and provides insights into their working mechanisms.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Unsorted List\n[932, 111, 226, 685, 543, 589, 918, 539, 294, 717]\nSorting using Insertion Sort\n[111, 226, 294, 539, 543, 589, 685, 717, 918, 932]\n\nUnsorted List\n[613, 176, 828, 265, 65, 326, 359, 919, 514, 868]\nSorting using Merge Sort\n[65, 176, 265, 326, 359, 514, 613, 828, 868, 919]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Unsorted List<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><span style=\"color: #79B8FF\">932<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">111<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">226<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">685<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">543<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">589<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">918<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">539<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">294<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">717<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Sorting <\/span><span style=\"color: #F97583\">using<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">Insertion<\/span><span style=\"color: #E1E4E8\"> Sort<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><span style=\"color: #79B8FF\">111<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">226<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">294<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">539<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">543<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">589<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">685<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">717<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">918<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">932<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Unsorted List<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><span style=\"color: #79B8FF\">613<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">176<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">828<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">265<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">65<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">326<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">359<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">919<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">514<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">868<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Sorting <\/span><span style=\"color: #F97583\">using<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">Merge<\/span><span style=\"color: #E1E4E8\"> Sort<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><span style=\"color: #79B8FF\">65<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">176<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">265<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">326<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">359<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">514<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">613<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">828<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">868<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">919<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"04b\">Roman to Integer Conversion<\/h3>\n\n\n\n<p class=\"has-text-align-justify\">Develop a Python program to check whether a given number is palindrome or not and also count the number of occurrences of each digit in the input number.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Python Code<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n&quot;&quot;&quot;\nCreated on Wed Feb 22 02:05:25 2023\n\n@author: Prabodh C P\n&quot;&quot;&quot;\n\n\ndef roman2Dec(romStr):\n    roman_dict ={'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}\n    # Analyze string backwards\n    romanBack = list(romStr)[::-1]\n    value = 0\n    # To keep track of order\n    rightVal = roman_dict[romanBack[0]]  \n    for numeral in romanBack:\n        leftVal = roman_dict[numeral]\n        # Check for subtraction\n        if leftVal &lt; rightVal:\n           value -= leftVal\n        else:\n            value += leftVal\n        rightVal = leftVal\n    return value\n\n\nromanStr = input(&quot;Enter a Roman Number : &quot;)\nprint(&quot;Equivalent Decimal number :&quot;,roman2Dec(romanStr))\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">#!\/usr\/bin\/env python3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">-*-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">coding<\/span><span style=\"color: #E1E4E8\">: utf<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">8<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">-*-<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">Created on Wed Feb 22 02:05:25 202<\/span><span style=\"color: #FDAEB7; font-style: italic\">3<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">@author: Prabodh <\/span><span style=\"color: #79B8FF\">C<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">P<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">def roman2Dec(romStr)<\/span><span style=\"color: #FDAEB7; font-style: italic\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    roman_dict <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\">{<\/span><span style=\"color: #9ECBFF\">&#39;I&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&#39;V&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&#39;X&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">10<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&#39;L&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">50<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&#39;C&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">100<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&#39;D&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">500<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&#39;M&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1000<\/span><span style=\"color: #E1E4E8\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    # Analyze string backwards<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    romanBack <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">list<\/span><span style=\"color: #E1E4E8\">(romStr)[::<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    value <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    # To keep track <\/span><span style=\"color: #F97583\">of<\/span><span style=\"color: #E1E4E8\"> order<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    rightVal <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> roman_dict[romanBack[<\/span><span style=\"color: #79B8FF\">0<\/span><span style=\"color: #E1E4E8\">]]  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    for numeral <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">romanBack<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        leftVal <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> roman_dict[numeral]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        # Check for subtraction<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> leftVal <\/span><span style=\"color: #F97583\">&lt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">rightVal<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">           value <\/span><span style=\"color: #F97583\">-=<\/span><span style=\"color: #E1E4E8\"> leftVal<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #F97583\">else<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            value <\/span><span style=\"color: #F97583\">+=<\/span><span style=\"color: #E1E4E8\"> leftVal<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        rightVal <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> leftVal<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #E1E4E8\"> value<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">romanStr <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">input<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Enter a Roman Number : &quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Equivalent Decimal number :&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><span style=\"color: #B392F0\">roman2Dec<\/span><span style=\"color: #E1E4E8\">(romanStr))<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This Python program, converts a Roman numeral string to its corresponding decimal value. The core function, <code>roman2Dec<\/code>, utilizes a dictionary to map Roman numerals to their decimal equivalents. The program prompts the user to input a Roman numeral, and it then applies the conversion function and prints the resulting decimal value.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Conversion Function:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The <code>roman2Dec<\/code> function takes a Roman numeral string as input and iterates through it in reverse order.<\/li>\n\n\n\n<li>It uses a dictionary, <code>roman_dict<\/code>, to map each Roman numeral to its corresponding decimal value.<\/li>\n\n\n\n<li>The function calculates the decimal value by comparing the current numeral with the one on its right, determining whether to add or subtract its value accordingly.This code provides a simple and effective way to convert Roman numerals to decimal form, demonstrating the use of dictionaries for efficient mapping.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>This code provides a simple and effective way to convert Roman numerals to decimal form, demonstrating the use of dictionaries for efficient mapping.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Enter a Roman Number : XVII\nEquivalent Decimal number : 17\n\nEnter a Roman Number : MLXVI\nEquivalent Decimal number : 1066\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Enter a Roman <\/span><span style=\"color: #B392F0\">Number<\/span><span style=\"color: #E1E4E8\"> : <\/span><span style=\"color: #79B8FF\">XVII<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Equivalent Decimal <\/span><span style=\"color: #B392F0\">number<\/span><span style=\"color: #E1E4E8\"> : <\/span><span style=\"color: #79B8FF\">17<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter a Roman <\/span><span style=\"color: #B392F0\">Number<\/span><span style=\"color: #E1E4E8\"> : <\/span><span style=\"color: #79B8FF\">MLXVI<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Equivalent Decimal <\/span><span style=\"color: #B392F0\">number<\/span><span style=\"color: #E1E4E8\"> : <\/span><span style=\"color: #79B8FF\">1066<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Question 5<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"05a\">Check Phone Number<\/h3>\n\n\n\n<p>Write a function called isphonenumber () to recognize a pattern 415-555-4242 without using regular expression and also write the code to recognize the same pattern using regular expression.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Python Code<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n&quot;&quot;&quot;\nCreated on Thu Mar  9 04:19:57 2023\n\n@author: Prabodh C P\n&quot;&quot;&quot;\nimport re\n\n\ndef isphonenumber(numStr):\n    if len(numStr) != 12:\n        return False\n    for i in range(len(numStr)):\n        if i==3 or i==7:\n            if numStr[i] != &quot;-&quot;:\n                return False\n        else:\n            if numStr[i].isdigit() == False:\n                return False\n    return True\n\n\ndef chkphonenumber(numStr):\n    ph_no_pattern = re.compile(r'^\\d{3}-\\d{3}-\\d{4}$')\n    if ph_no_pattern.match(numStr):\n        return True\n    else:\n        return False\n\nph_num = input(&quot;Enter a phone number : &quot;)\nprint(&quot;Without using Regular Expression&quot;)\nif isphonenumber(ph_num):\n    print(&quot;Valid phone number&quot;)\nelse:\n    print(&quot;Invalid phone number&quot;)\n\nprint(&quot;Using Regular Expression&quot;)\nif chkphonenumber(ph_num):\n    print(&quot;Valid phone number&quot;)\nelse:\n    print(&quot;Invalid phone number&quot;)\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">#!\/usr\/bin\/env python3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">-*-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">coding<\/span><span style=\"color: #E1E4E8\">: utf<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">8<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">-*-<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">Created on Thu Mar  9 04:19:57 202<\/span><span style=\"color: #FDAEB7; font-style: italic\">3<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">@author: Prabodh <\/span><span style=\"color: #79B8FF\">C<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">P<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">import r<\/span><span style=\"color: #FDAEB7; font-style: italic\">e<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">def <\/span><span style=\"color: #B392F0\">isphonenumber<\/span><span style=\"color: #E1E4E8\">(numStr):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">len<\/span><span style=\"color: #E1E4E8\">(numStr) <\/span><span style=\"color: #F97583\">!=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">12<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #E1E4E8\"> False<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    for i <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">range<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">len<\/span><span style=\"color: #E1E4E8\">(numStr)):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> i<\/span><span style=\"color: #F97583\">==<\/span><span style=\"color: #79B8FF\">3<\/span><span style=\"color: #E1E4E8\"> or i<\/span><span style=\"color: #F97583\">==<\/span><span style=\"color: #79B8FF\">7<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> numStr[i] <\/span><span style=\"color: #F97583\">!=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&quot;-&quot;<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">                <\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #E1E4E8\"> False<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #F97583\">else<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> numStr[i].<\/span><span style=\"color: #B392F0\">isdigit<\/span><span style=\"color: #E1E4E8\">() <\/span><span style=\"color: #F97583\">==<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">False<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">                <\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #E1E4E8\"> False<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #E1E4E8\"> True<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">def <\/span><span style=\"color: #B392F0\">chkphonenumber<\/span><span style=\"color: #E1E4E8\">(numStr):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    ph_no_pattern <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> re.<\/span><span style=\"color: #B392F0\">compile<\/span><span style=\"color: #E1E4E8\">(r<\/span><span style=\"color: #9ECBFF\">&#39;^<\/span><span style=\"color: #79B8FF\">\\d<\/span><span style=\"color: #9ECBFF\">{3}-<\/span><span style=\"color: #79B8FF\">\\d<\/span><span style=\"color: #9ECBFF\">{3}-<\/span><span style=\"color: #79B8FF\">\\d<\/span><span style=\"color: #9ECBFF\">{4}$&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> ph_no_pattern.<\/span><span style=\"color: #B392F0\">match<\/span><span style=\"color: #E1E4E8\">(numStr):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #E1E4E8\"> True<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">else<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #E1E4E8\"> False<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">ph_num <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">input<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Enter a phone number : &quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Without using Regular Expression&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">isphonenumber<\/span><span style=\"color: #E1E4E8\">(ph_num):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Valid phone number&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">else<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Invalid phone number&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Using Regular Expression&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">chkphonenumber<\/span><span style=\"color: #E1E4E8\">(ph_num):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Valid phone number&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">else<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Invalid phone number&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This Python program, designed to validate phone numbers, provides two different approaches: one without using regular expressions and another using regular expressions.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Non-Regular Expression Approach (<code>isphonenumber<\/code> function):<\/strong>\n<ul class=\"wp-block-list\">\n<li>The <code>isphonenumber<\/code> function checks if a given phone number string is valid without using regular expressions.<\/li>\n\n\n\n<li>It verifies that the length of the string is 12 characters and that the characters at positions 3 and 7 are hyphens.<\/li>\n\n\n\n<li>It further checks that the remaining characters are digits.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Regular Expression Approach (<code>chkphonenumber<\/code> function):<\/strong>\n<ul class=\"wp-block-list\">\n<li>The <code>chkphonenumber<\/code> function uses a regular expression to validate phone numbers.<\/li>\n\n\n\n<li>It employs the <code>re.compile<\/code> function to create a regular expression pattern (<code>^\\d{3}-\\d{3}-\\d{4}$<\/code>).<\/li>\n\n\n\n<li>The pattern ensures that the phone number follows the format of three digits, a hyphen, three digits, another hyphen, and four digits.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>User Input and Output:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The program prompts the user to input a phone number.<\/li>\n\n\n\n<li>It then calls both validation functions and prints whether the phone number is valid or invalid for each approach.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>This program demonstrates two distinct methods for validating phone numbers\u2014one based on manual character checks and the other utilizing the power of regular expressions for a more concise and flexible solution.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Enter a phone number : 444-654-5656\nWithout using Regular Expression\nValid phone number\nUsing Regular Expression\nValid phone number\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Enter a phone <\/span><span style=\"color: #B392F0\">number<\/span><span style=\"color: #E1E4E8\"> : <\/span><span style=\"color: #79B8FF\">444<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">654<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">5656<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Without <\/span><span style=\"color: #F97583\">using<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">Regular<\/span><span style=\"color: #E1E4E8\"> Expression<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Valid phone number<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Using Regular Expression<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Valid phone number<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Enter a phone number : 45A4-444-878\nWithout using Regular Expression\nInvalid phone number\nUsing Regular Expression\nInvalid phone number\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Enter a phone <\/span><span style=\"color: #B392F0\">number<\/span><span style=\"color: #E1E4E8\"> : 45<\/span><span style=\"color: #79B8FF\">A4<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">444<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">878<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Without <\/span><span style=\"color: #F97583\">using<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">Regular<\/span><span style=\"color: #E1E4E8\"> Expression<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Invalid phone number<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Using Regular Expression<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Invalid phone number<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"05b\">Search Phone Number &amp; Email<\/h3>\n\n\n\n<p class=\"has-text-align-justify\">Develop a python program that could search the text in a file for phone numbers (+919900889977) and email addresses (sample@gmail.com)<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Python Code<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n&quot;&quot;&quot;\nCreated on Thu Mar  9 04:40:10 2023\n\n@author: Prabodh C P\n&quot;&quot;&quot;\n\nimport re\n\n# Define the regular expression for phone numbers\nphone_regex = re.compile(r'\\+\\d{12}')\nemail_regex = re.compile(r'[A-Za-z0-9._]+@[A-Za-z0-9]+\\.[A-Z|a-z]{2,}')\n# Open the file for reading\nwith open('example.txt', 'r') as f:\n    # Loop through each line in the file\n    for line in f:\n        # Search for phone numbers in the line\n        matches = phone_regex.findall(line)\n        # Print any matches found\n        for match in matches:\n            print(match)\n\n        matches = email_regex.findall(line)\n        # Print any matches found\n        for match in matches:\n            print(match)            \" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">#!\/usr\/bin\/env python3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">-*-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">coding<\/span><span style=\"color: #E1E4E8\">: utf<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">8<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">-*-<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">Created on Thu Mar  9 04:40:10 202<\/span><span style=\"color: #FDAEB7; font-style: italic\">3<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">@author: Prabodh <\/span><span style=\"color: #79B8FF\">C<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">P<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">import r<\/span><span style=\"color: #FDAEB7; font-style: italic\">e<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># Define the regular expression for phone numbers<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">phone_regex <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> re.<\/span><span style=\"color: #B392F0\">compile<\/span><span style=\"color: #E1E4E8\">(r<\/span><span style=\"color: #9ECBFF\">&#39;<\/span><span style=\"color: #79B8FF\">\\+\\d<\/span><span style=\"color: #9ECBFF\">{12}&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">email_regex <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> re.<\/span><span style=\"color: #B392F0\">compile<\/span><span style=\"color: #E1E4E8\">(r<\/span><span style=\"color: #9ECBFF\">&#39;[A-Za-z0-9._]+@[A-Za-z0-9]+<\/span><span style=\"color: #79B8FF\">\\.<\/span><span style=\"color: #9ECBFF\">[A-Z|a-z]{2,}&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># Open the file for reading<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">with<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">open<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;example.txt&#39;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&#39;r&#39;<\/span><span style=\"color: #E1E4E8\">) <\/span><span style=\"color: #F97583\">as<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">f<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    # Loop through each line <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> the file<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    for line <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">f<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        # Search for phone numbers <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> the line<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        matches <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> phone_regex.<\/span><span style=\"color: #B392F0\">findall<\/span><span style=\"color: #E1E4E8\">(line)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        # Print any matches found<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        for match <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">matches<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(match)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        matches <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> email_regex.<\/span><span style=\"color: #B392F0\">findall<\/span><span style=\"color: #E1E4E8\">(line)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        # Print any matches found<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        for match <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">matches<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(match)            <\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This Python program employs regular expressions to extract and print phone numbers and email addresses from a given text file (<code>example.txt<\/code>). Here&#8217;s a brief description:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Regular Expressions:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The program uses two regular expressions:\n<ul class=\"wp-block-list\">\n<li><code>phone_regex<\/code>: Designed to match international phone numbers in the format &#8216;+XXXXXXXXXXXX&#8217; where &#8216;X&#8217; represents digits.<\/li>\n\n\n\n<li><code>email_regex<\/code>: Crafted to identify email addresses following the standard email format.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>File Reading:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The program opens the file &#8216;example.txt&#8217; for reading using a context manager (<code>with open('example.txt', 'r') as f<\/code>).<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Line Processing:<\/strong>\n<ul class=\"wp-block-list\">\n<li>It iterates through each line in the file (<code>for line in f:<\/code>).<\/li>\n\n\n\n<li>For each line, it searches for matches using both regular expressions.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Printing Matches:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The program prints any phone numbers and email addresses found in the file.<\/li>\n\n\n\n<li>Matches are printed line by line, providing a clear output.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Usage:<\/strong>\n<ul class=\"wp-block-list\">\n<li>Users can replace &#8216;example.txt&#8217; with the path to their desired text file containing phone numbers and email addresses.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>This program serves as a handy tool for extracting and analyzing phone numbers and email addresses from text files, demonstrating the efficiency and flexibility of regular expressions in text pattern matching.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"+918151894220\n+829392938876\n+918768456234\nprakash81.82@gmail.in\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F97583\">+<\/span><span style=\"color: #79B8FF\">918151894220<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">+<\/span><span style=\"color: #79B8FF\">829392938876<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">+<\/span><span style=\"color: #79B8FF\">918768456234<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">prakash81.<\/span><span style=\"color: #79B8FF\">82<\/span><span style=\"color: #E1E4E8\">@gmail.in<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Question 6<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"06a\">File Operations<\/h3>\n\n\n\n<p>Write a python program to accept a file name from the user and perform the following operations<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Display the first N line of the file<\/li>\n\n\n\n<li>Find the frequency of occurrence of the word accepted from the user in the file<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">Python Code<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n&quot;&quot;&quot;\nCreated on Thu Mar  9 05:26:33 2023\n\n@author: Prabodh C P\n&quot;&quot;&quot;\n\nimport os.path\nimport sys\n\nfname = input(&quot;Enter the filename : &quot;)      \n\nif not os.path.isfile(fname):\n    print(&quot;File&quot;, fname, &quot;doesn't exists&quot;)\n    sys.exit(0)\n\ninfile = open(fname, &quot;r&quot;)\n\nlineList = infile.readlines()\n\nlineCount = int(input(&quot;Enter the number of lines you want to display : &quot;))\nfor i in range(lineCount):\n    print(i+1, &quot;:&quot;, lineList[i], end=&quot;&quot;)\n    \nword = input(&quot;Enter a word : &quot;)\ncnt = 0\nfor line in lineList:\n    cnt += line.count(word)\n\nprint(&quot;The word&quot;, word, &quot;appears&quot;, cnt, &quot;times in the file&quot;)\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">#!\/usr\/bin\/env python3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">-*-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">coding<\/span><span style=\"color: #E1E4E8\">: utf<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">8<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">-*-<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">Created on Thu Mar  9 05:26:33 202<\/span><span style=\"color: #FDAEB7; font-style: italic\">3<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">@author: Prabodh <\/span><span style=\"color: #79B8FF\">C<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">P<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">import os.pat<\/span><span style=\"color: #FDAEB7; font-style: italic\">h<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">import<\/span><span style=\"color: #E1E4E8\"> sys<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">fname = input(<\/span><span style=\"color: #9ECBFF\">&quot;Enter the filename : &quot;<\/span><span style=\"color: #E1E4E8\">)      <\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">if not os.path.isfile(fname):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    print(<\/span><span style=\"color: #9ECBFF\">&quot;File&quot;<\/span><span style=\"color: #E1E4E8\">, fname, <\/span><span style=\"color: #9ECBFF\">&quot;doesn&#39;t exists&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    sys.exit(0)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">infile = open(fname, <\/span><span style=\"color: #9ECBFF\">&quot;r&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">lineList = infile.readlines()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">lineCount = int(input(<\/span><span style=\"color: #9ECBFF\">&quot;Enter the number of lines you want to display : &quot;<\/span><span style=\"color: #E1E4E8\">))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">for i in range(lineCount):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    print(i+1, <\/span><span style=\"color: #9ECBFF\">&quot;:&quot;<\/span><span style=\"color: #E1E4E8\">, lineList[i], end=<\/span><span style=\"color: #9ECBFF\">&quot;&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">word = input(<\/span><span style=\"color: #9ECBFF\">&quot;Enter a word : &quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">cnt = 0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">for line in lineList:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    cnt += line.count(word)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">print(<\/span><span style=\"color: #9ECBFF\">&quot;The word&quot;<\/span><span style=\"color: #E1E4E8\">, word, <\/span><span style=\"color: #9ECBFF\">&quot;appears&quot;<\/span><span style=\"color: #E1E4E8\">, cnt, <\/span><span style=\"color: #9ECBFF\">&quot;times in the file&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This Python program is designed to analyze a text file. Here&#8217;s a brief description:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>File Existence Check:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The program prompts the user to input a filename (<code>fname<\/code>).<\/li>\n\n\n\n<li>It checks whether the specified file exists using <code>os.path.isfile(fname)<\/code>.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>File Opening:<\/strong>\n<ul class=\"wp-block-list\">\n<li>If the file exists, it opens the file (<code>infile = open(fname, \"r\")<\/code>) for reading.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Reading Lines:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The program reads all lines from the file and stores them in a list (<code>lineList = infile.readlines()<\/code>).<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Displaying Initial Lines:<\/strong>\n<ul class=\"wp-block-list\">\n<li>It prints the first 20 lines of the file, numbered from 1 to 20.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Word Count:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The program then prompts the user to input a word (<code>word<\/code>).<\/li>\n\n\n\n<li>It counts the occurrences of the specified word in the entire file.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Output:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The program prints the count of occurrences of the specified word in the file.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>This program provides a quick overview of the content of a text file, allowing users to inspect the initial lines and find the frequency of a specific word within the file. It is a useful tool for preliminary text analysis.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Enter the filename :  example.txt\nEnter the number of lines you want to display :  6\n1 : this is phone number +918151894220\n2 : no phone number here\n3 : here we have one +829392938876\n4 : we have an email prakash81.82@gmail.in and a number +918768456234 \n5 : nothing of that sort here\n6 : Better hope the life-inspector doesn't come around while you have your\nEnter a word :  Why\nThe word Why appears 2 times in the file\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Enter the <\/span><span style=\"color: #B392F0\">filename<\/span><span style=\"color: #E1E4E8\"> :  example.txt<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter the number <\/span><span style=\"color: #F97583\">of<\/span><span style=\"color: #E1E4E8\"> lines you want to <\/span><span style=\"color: #B392F0\">display<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">6<\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> : <\/span><span style=\"color: #79B8FF\">this<\/span><span style=\"color: #E1E4E8\"> is phone number <\/span><span style=\"color: #F97583\">+<\/span><span style=\"color: #79B8FF\">918151894220<\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\"> : no phone number here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">3<\/span><span style=\"color: #E1E4E8\"> : here we have one <\/span><span style=\"color: #F97583\">+<\/span><span style=\"color: #79B8FF\">829392938876<\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">4<\/span><span style=\"color: #E1E4E8\"> : we have an email prakash81.<\/span><span style=\"color: #79B8FF\">82<\/span><span style=\"color: #E1E4E8\">@gmail.in and a number <\/span><span style=\"color: #F97583\">+<\/span><span style=\"color: #79B8FF\">918768456234<\/span><span style=\"color: #E1E4E8\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\"> : nothing <\/span><span style=\"color: #F97583\">of<\/span><span style=\"color: #E1E4E8\"> that sort here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">6<\/span><span style=\"color: #E1E4E8\"> : Better hope the life<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #E1E4E8\">inspector doesn<\/span><span style=\"color: #9ECBFF\">&#39;t come around while you have you<\/span><span style=\"color: #FDAEB7; font-style: italic\">r<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter a <\/span><span style=\"color: #B392F0\">word<\/span><span style=\"color: #E1E4E8\"> :  Why<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">The word Why appears <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\"> times <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> the file<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"06b\">Zip operation on a folder<\/h3>\n\n\n\n<p>Develop a program to backing Up a given Folder (Folder in a current working directory) into a ZIP File by using relevant modules and suitable methods.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Python Code<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n&quot;&quot;&quot;\nCreated on Fri Dec 23 16:14:28 2022\n\n@author: Prabodh C P\n&quot;&quot;&quot;\n\nimport os\nimport sys\nimport pathlib\nimport zipfile\n\ndirName = input(&quot;Enter Directory name that you want to backup : &quot;)\n\nif not os.path.isdir(dirName):\n    print(&quot;Directory&quot;, dirName, &quot;doesn't exists&quot;)\n    sys.exit(0)\n    \ncurDirectory = pathlib.Path(dirName)\n    \nwith zipfile.ZipFile(&quot;myZip.zip&quot;, mode=&quot;w&quot;) as archive:\n    for file_path in curDirectory.rglob(&quot;*&quot;):\n        archive.write(file_path, arcname=file_path.relative_to(curDirectory))\n    \nif os.path.isfile(&quot;myZip.zip&quot;):\n    print(&quot;Archive&quot;, &quot;myZip.zip&quot;, &quot;created successfully&quot;)\nelse:\n    print(&quot;Error in creating zip archive&quot;)\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">#!\/usr\/bin\/env python3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">-*-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">coding<\/span><span style=\"color: #E1E4E8\">: utf<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">8<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">-*-<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">Created on Fri Dec 23 16:14:28 202<\/span><span style=\"color: #FDAEB7; font-style: italic\">2<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">@author: Prabodh <\/span><span style=\"color: #79B8FF\">C<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">P<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">import o<\/span><span style=\"color: #FDAEB7; font-style: italic\">s<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">import<\/span><span style=\"color: #E1E4E8\"> sys<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">import pathlib<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">import zipfile<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">dirName = input(<\/span><span style=\"color: #9ECBFF\">&quot;Enter Directory name that you want to backup : &quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">if not os.path.isdir(dirName):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    print(<\/span><span style=\"color: #9ECBFF\">&quot;Directory&quot;<\/span><span style=\"color: #E1E4E8\">, dirName, <\/span><span style=\"color: #9ECBFF\">&quot;doesn&#39;t exists&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    sys.exit(0)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">curDirectory = pathlib.Path(dirName)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">with zipfile.ZipFile(<\/span><span style=\"color: #9ECBFF\">&quot;myZip.zip&quot;<\/span><span style=\"color: #E1E4E8\">, mode=<\/span><span style=\"color: #9ECBFF\">&quot;w&quot;<\/span><span style=\"color: #E1E4E8\">) as archive:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    for file_path in curDirectory.rglob(<\/span><span style=\"color: #9ECBFF\">&quot;*&quot;<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        archive.write(file_path, arcname=file_path.relative_to(curDirectory))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">if os.path.isfile(<\/span><span style=\"color: #9ECBFF\">&quot;myZip.zip&quot;<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    print(<\/span><span style=\"color: #9ECBFF\">&quot;Archive&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;myZip.zip&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;created successfully&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">else:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    print(<\/span><span style=\"color: #9ECBFF\">&quot;Error in creating zip archive&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This Python program is designed to create a backup of a directory by compressing its contents into a zip file. Here&#8217;s a brief description:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Directory Existence Check:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The program prompts the user to input a directory name (<code>dirName<\/code>).<\/li>\n\n\n\n<li>It checks whether the specified directory exists using <code>os.path.isdir(dirName)<\/code>.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Directory Path Setup:<\/strong>\n<ul class=\"wp-block-list\">\n<li>If the directory exists, it creates a <code>pathlib.Path<\/code> object (<code>curDirectory<\/code>) representing the specified directory.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Zip File Creation:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The program uses the <code>zipfile<\/code> module to create a zip file named &#8220;myZip.zip&#8221; (<code>with zipfile.ZipFile(\"myZip.zip\", mode=\"w\") as archive<\/code>).<\/li>\n\n\n\n<li>It iterates through all files in the specified directory and its subdirectories using <code>curDirectory.rglob(\"*\")<\/code>.<\/li>\n\n\n\n<li>For each file, it adds the file to the zip archive, preserving the directory structure within the archive (<code>archive.write(file_path, arcname=file_path.relative_to(curDirectory))<\/code>).<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Output:<\/strong>\n<ul class=\"wp-block-list\">\n<li>If the zip file &#8220;myZip.zip&#8221; is successfully created, it prints a success message.<\/li>\n\n\n\n<li>If there&#8217;s an issue creating the zip archive, it prints an error message.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>This program is a simple and effective way to create a compressed backup of a directory, making it easier to store and transfer a set of files and directories.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Enter Directory name that you want to backup : zipDemo\nArchive myZip.zip created successfully\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Enter Directory name that you want to <\/span><span style=\"color: #B392F0\">backup<\/span><span style=\"color: #E1E4E8\"> : zipDemo<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Archive myZip.zip created successfully<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Question 7<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"07a\">Inheritance<\/h3>\n\n\n\n<p>By using the concept of inheritance write a python program to find the area of triangle, circle and rectangle.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Python Code<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n&quot;&quot;&quot;\nCreated on Thu Mar  9 05:40:37 2023\n\n@author: Prabodh C P\n&quot;&quot;&quot;\n\nimport math\n\nclass Shape:\n    def __init__(self):\n        self.area = 0\n        self.name = &quot;&quot;\n        \n    def showArea(self):\n        print(&quot;The area of the&quot;, self.name, &quot;is&quot;, self.area, &quot;units&quot;)\n        \nclass Circle(Shape):\n    def __init__(self,radius):\n        self.area = 0\n        self.name = &quot;Circle&quot;\n        self.radius = radius\n        \n    def calcArea(self):\n        self.area = math.pi * self.radius * self.radius\n    \nclass Rectangle(Shape):\n    def __init__(self,length,breadth):\n        self.area = 0\n        self.name = &quot;Rectangle&quot;\n        self.length = length\n        self.breadth = breadth\n        \n    def calcArea(self):\n        self.area = self.length * self.breadth\n\nclass Triangle(Shape):\n    def __init__(self,base,height):\n        self.area = 0\n        self.name = &quot;Triangle&quot;\n        self.base = base\n        self.height = height\n        \n    def calcArea(self):\n        self.area = self.base * self.height \/ 2\n    \n\n    \nc1 = Circle(5)\nc1.calcArea()\nc1.showArea()\n\n\nr1 = Rectangle(5, 4)\nr1.calcArea()\nr1.showArea()\n\n\nt1 = Triangle(3, 4)\nt1.calcArea()\nt1.showArea()\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">#!\/usr\/bin\/env python3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">-*-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">coding<\/span><span style=\"color: #E1E4E8\">: utf<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">8<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">-*-<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">Created on Thu Mar  9 05:40:37 202<\/span><span style=\"color: #FDAEB7; font-style: italic\">3<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">@author: Prabodh <\/span><span style=\"color: #79B8FF\">C<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">P<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">import mat<\/span><span style=\"color: #FDAEB7; font-style: italic\">h<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">class<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Shape<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">def<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">__init__<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">area<\/span><span style=\"color: #E1E4E8\"> = 0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">name<\/span><span style=\"color: #E1E4E8\"> = &quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">def<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">showArea<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(&quot;<\/span><span style=\"color: #B392F0\">The<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">area<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">of<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">the<\/span><span style=\"color: #E1E4E8\">&quot;, <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">name<\/span><span style=\"color: #E1E4E8\">, &quot;<\/span><span style=\"color: #B392F0\">is<\/span><span style=\"color: #E1E4E8\">&quot;, <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">area<\/span><span style=\"color: #E1E4E8\">, &quot;<\/span><span style=\"color: #B392F0\">units<\/span><span style=\"color: #E1E4E8\">&quot;)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">class<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Circle<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">Shape<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">def<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">__init__<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">,<\/span><span style=\"color: #B392F0\">radius<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">area<\/span><span style=\"color: #E1E4E8\"> = 0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">name<\/span><span style=\"color: #E1E4E8\"> = &quot;<\/span><span style=\"color: #B392F0\">Circle<\/span><span style=\"color: #E1E4E8\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">radius<\/span><span style=\"color: #E1E4E8\"> = <\/span><span style=\"color: #B392F0\">radius<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">def<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">calcArea<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">area<\/span><span style=\"color: #E1E4E8\"> = <\/span><span style=\"color: #B392F0\">math<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">pi<\/span><span style=\"color: #E1E4E8\"> * <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">radius<\/span><span style=\"color: #E1E4E8\"> * <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">radius<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">class<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Rectangle<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">Shape<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">def<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">__init__<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">,<\/span><span style=\"color: #B392F0\">length<\/span><span style=\"color: #E1E4E8\">,<\/span><span style=\"color: #B392F0\">breadth<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">area<\/span><span style=\"color: #E1E4E8\"> = 0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">name<\/span><span style=\"color: #E1E4E8\"> = &quot;<\/span><span style=\"color: #B392F0\">Rectangle<\/span><span style=\"color: #E1E4E8\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">length<\/span><span style=\"color: #E1E4E8\"> = <\/span><span style=\"color: #B392F0\">length<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">breadth<\/span><span style=\"color: #E1E4E8\"> = <\/span><span style=\"color: #B392F0\">breadth<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">def<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">calcArea<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">area<\/span><span style=\"color: #E1E4E8\"> = <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">length<\/span><span style=\"color: #E1E4E8\"> * <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">breadth<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">class<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Triangle<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">Shape<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">def<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">__init__<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">,<\/span><span style=\"color: #B392F0\">base<\/span><span style=\"color: #E1E4E8\">,<\/span><span style=\"color: #B392F0\">height<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">area<\/span><span style=\"color: #E1E4E8\"> = 0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">name<\/span><span style=\"color: #E1E4E8\"> = &quot;<\/span><span style=\"color: #B392F0\">Triangle<\/span><span style=\"color: #E1E4E8\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">base<\/span><span style=\"color: #E1E4E8\"> = <\/span><span style=\"color: #B392F0\">base<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">height<\/span><span style=\"color: #E1E4E8\"> = <\/span><span style=\"color: #B392F0\">height<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">def<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">calcArea<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">area<\/span><span style=\"color: #E1E4E8\"> = <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">base<\/span><span style=\"color: #E1E4E8\"> * <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">height<\/span><span style=\"color: #E1E4E8\"> \/ 2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">c1<\/span><span style=\"color: #E1E4E8\"> = <\/span><span style=\"color: #B392F0\">Circle<\/span><span style=\"color: #E1E4E8\">(5)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">c1<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">calcArea<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">c1<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">showArea<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">r1<\/span><span style=\"color: #E1E4E8\"> = <\/span><span style=\"color: #B392F0\">Rectangle<\/span><span style=\"color: #E1E4E8\">(5, 4)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">r1<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">calcArea<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">r1<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">showArea<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">t1<\/span><span style=\"color: #E1E4E8\"> = <\/span><span style=\"color: #B392F0\">Triangle<\/span><span style=\"color: #E1E4E8\">(3, 4)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">t1<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">calcArea<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">t1<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">showArea<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This Python program defines a simple object-oriented system to calculate and display the area of different geometric shapes. Here&#8217;s a brief description:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Shape Class:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The <code>Shape<\/code> class serves as the base class for geometric shapes. It has an <code>__init__<\/code> method to initialize the area and name, and a <code>showArea<\/code> method to display the area.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Circle, Rectangle, and Triangle Classes:<\/strong>\n<ul class=\"wp-block-list\">\n<li>These classes (<code>Circle<\/code>, <code>Rectangle<\/code>, and <code>Triangle<\/code>) inherit from the <code>Shape<\/code> class.<\/li>\n\n\n\n<li>Each shape class has its own <code>__init__<\/code> method to set specific attributes like radius, length, and breadth.<\/li>\n\n\n\n<li>Each shape class has a <code>calcArea<\/code> method to calculate the area based on its specific formula.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Example Instances:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The program creates instances of each shape class (<code>c1<\/code>, <code>r1<\/code>, and <code>t1<\/code>).<\/li>\n\n\n\n<li>For each instance, it calls the <code>calcArea<\/code> method to calculate the area.<\/li>\n\n\n\n<li>Finally, it calls the <code>showArea<\/code> method to display the area for each shape.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Output:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The program outputs the calculated areas for a circle, rectangle, and triangle.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>This program demonstrates basic principles of object-oriented programming (OOP) by using inheritance and encapsulation to model different shapes and their respective areas. It provides a clear structure for extending the system to include additional shapes in the future.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"The area of the Circle is 78.53981633974483 units\nThe area of the Rectangle is 20 units\nThe area of the Triangle is 6.0 units\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">The area <\/span><span style=\"color: #F97583\">of<\/span><span style=\"color: #E1E4E8\"> the Circle is <\/span><span style=\"color: #79B8FF\">78.53981633974483<\/span><span style=\"color: #E1E4E8\"> units<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">The area <\/span><span style=\"color: #F97583\">of<\/span><span style=\"color: #E1E4E8\"> the Rectangle is <\/span><span style=\"color: #79B8FF\">20<\/span><span style=\"color: #E1E4E8\"> units<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">The area <\/span><span style=\"color: #F97583\">of<\/span><span style=\"color: #E1E4E8\"> the Triangle is <\/span><span style=\"color: #79B8FF\">6.0<\/span><span style=\"color: #E1E4E8\"> units<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"07b\">Employee Details<\/h3>\n\n\n\n<p>Write a python program by creating a class called Employee to store the details of Name, Employee_ID, Department and Salary, and implement a method to update salary of employees belonging to a given department.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Python Code<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n&quot;&quot;&quot;\nCreated on Thu Mar  9 12:09:50 2023\n\n@author: Prabodh C P\n&quot;&quot;&quot;\n\nclass Employee:\n    def __init__(self):\n        self.name = &quot;&quot;\n        self.empId = &quot;&quot;\n        self.dept = &quot;&quot;\n        self.salary = 0\n        \n    def getEmpDetails(self):\n        self.name = input(&quot;Enter Employee name : &quot;)\n        self.empId = input(&quot;Enter Employee ID : &quot;)\n        self.dept = input(&quot;Enter Employee Dept : &quot;)\n        self.salary = int(input(&quot;Enter Employee Salary : &quot;))\n        \n    def showEmpDetails(self):\n        print(&quot;Employee Details&quot;)\n        print(&quot;Name : &quot;, self.name)\n        print(&quot;ID : &quot;, self.empId)\n        print(&quot;Dept : &quot;, self.dept)\n        print(&quot;Salary : &quot;, self.salary)\n        \n    def updtSalary(self, hike):\n        self.salary += self.salary*hike\/100\n        print(&quot;Updated Salary for&quot;,self.name)\n        \ncompany = []\ndef main():\n    for i in range(5):\n        e1 = Employee()\n        e1.getEmpDetails()\n        company.append(e1)\n\n    print(&quot;\\nEMPLOYEE DETAILS\\n&quot;)\n    for emp in company:\n        emp.showEmpDetails()\n        \n    dept = input(&quot;Enter Department for which you want to update salary&quot;)\n    hike = eval(input(&quot;Enter hike in percentage : &quot;))\n    for emp in company:\n        if emp.dept == dept:\n            emp.updtSalary(hike)\n            \n    print(&quot;\\nUPDATED EMPLOYEE DETAILS\\n&quot;)\n    for emp in company:\n        emp.showEmpDetails()\n\nmain()\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">#!\/usr\/bin\/env python3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">-*-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">coding<\/span><span style=\"color: #E1E4E8\">: utf<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">8<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">-*-<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">Created on Thu Mar  9 12:09:50 202<\/span><span style=\"color: #FDAEB7; font-style: italic\">3<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">@author: Prabodh <\/span><span style=\"color: #79B8FF\">C<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">P<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">class Employee<\/span><span style=\"color: #FDAEB7; font-style: italic\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    def <\/span><span style=\"color: #B392F0\">__init__<\/span><span style=\"color: #E1E4E8\">(self):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        self.name <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        self.empId <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        self.dept <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        self.salary <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    def <\/span><span style=\"color: #B392F0\">getEmpDetails<\/span><span style=\"color: #E1E4E8\">(self):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        self.name <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">input<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Enter Employee name : &quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        self.empId <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">input<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Enter Employee ID : &quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        self.dept <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">input<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Enter Employee Dept : &quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        self.salary <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">int<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">input<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Enter Employee Salary : &quot;<\/span><span style=\"color: #E1E4E8\">))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    def <\/span><span style=\"color: #B392F0\">showEmpDetails<\/span><span style=\"color: #E1E4E8\">(self):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Employee Details&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Name : &quot;<\/span><span style=\"color: #E1E4E8\">, self.name)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;ID : &quot;<\/span><span style=\"color: #E1E4E8\">, self.empId)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Dept : &quot;<\/span><span style=\"color: #E1E4E8\">, self.dept)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Salary : &quot;<\/span><span style=\"color: #E1E4E8\">, self.salary)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    def <\/span><span style=\"color: #B392F0\">updtSalary<\/span><span style=\"color: #E1E4E8\">(self, hike):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        self.salary <\/span><span style=\"color: #F97583\">+=<\/span><span style=\"color: #E1E4E8\"> self.salary<\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #E1E4E8\">hike<\/span><span style=\"color: #F97583\">\/<\/span><span style=\"color: #79B8FF\">100<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Updated Salary for&quot;<\/span><span style=\"color: #E1E4E8\">,self.name)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">company <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> []<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">def <\/span><span style=\"color: #B392F0\">main<\/span><span style=\"color: #E1E4E8\">():<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    for i <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">range<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        e1 <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Employee<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        e1.<\/span><span style=\"color: #B392F0\">getEmpDetails<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        company.<\/span><span style=\"color: #B392F0\">append<\/span><span style=\"color: #E1E4E8\">(e1)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;<\/span><span style=\"color: #79B8FF\">\\n<\/span><span style=\"color: #9ECBFF\">EMPLOYEE DETAILS<\/span><span style=\"color: #79B8FF\">\\n<\/span><span style=\"color: #9ECBFF\">&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    for emp <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">company<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        emp.<\/span><span style=\"color: #B392F0\">showEmpDetails<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    dept <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">input<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Enter Department for which you want to update salary&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    hike <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">eval<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">input<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Enter hike in percentage : &quot;<\/span><span style=\"color: #E1E4E8\">))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    for emp <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">company<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> emp.dept <\/span><span style=\"color: #F97583\">==<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">dept<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            emp.<\/span><span style=\"color: #B392F0\">updtSalary<\/span><span style=\"color: #E1E4E8\">(hike)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;<\/span><span style=\"color: #79B8FF\">\\n<\/span><span style=\"color: #9ECBFF\">UPDATED EMPLOYEE DETAILS<\/span><span style=\"color: #79B8FF\">\\n<\/span><span style=\"color: #9ECBFF\">&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    for emp <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">company<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        emp.<\/span><span style=\"color: #B392F0\">showEmpDetails<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">main<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This Python program defines a simple <code>Employee<\/code> class with methods to manage employee details. Here&#8217;s a brief description:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Employee Class:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The <code>Employee<\/code> class has attributes for the employee&#8217;s name, ID, department, and salary.<\/li>\n\n\n\n<li>The <code>__init__<\/code> method initializes these attributes.<\/li>\n\n\n\n<li>The <code>getEmpDetails<\/code> method takes user input to set the employee details.<\/li>\n\n\n\n<li>The <code>showEmpDetails<\/code> method prints the employee details.<\/li>\n\n\n\n<li>The <code>updtSalary<\/code> method allows updating the employee&#8217;s salary.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Example Instance:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The program creates an instance of the <code>Employee<\/code> class (<code>e1<\/code>).<\/li>\n\n\n\n<li>It calls the <code>getEmpDetails<\/code> method to input employee details.<\/li>\n\n\n\n<li>It calls the <code>showEmpDetails<\/code> method to display the entered details.<\/li>\n\n\n\n<li>It calls the <code>updtSalary<\/code> method to update the employee&#8217;s salary.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Output:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The program outputs the entered and updated employee details.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>This program demonstrates the use of a class to model an employee, encapsulating related functionality and data. It also showcases how class methods can interact with instance variables and user input, providing a foundation for managing employee information in a more extensive human resources system.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Enter Employee name :  Raju\nEnter Employee ID :  SIT123\nEnter Employee Dept :  CSE\nEnter Employee Salary :  76500\nEnter Employee name :  Jacob\nEnter Employee ID :  SIT124\nEnter Employee Dept :  ECE\nEnter Employee Salary :  72000\nEnter Employee name :  Seema\nEnter Employee ID :  SIT125\nEnter Employee Dept :  CSE\nEnter Employee Salary :  75000\nEnter Employee name :  Abdul\nEnter Employee ID :  SIT126\nEnter Employee Dept :  ME\nEnter Employee Salary :  65000\nEnter Employee name :  Babu\nEnter Employee ID :  SIT127\nEnter Employee Dept :  EEE\nEnter Employee Salary :  64000\n\nEMPLOYEE DETAILS\n\nEmployee Details\nName :  Raju\nID :  SIT123\nDept :  CSE\nSalary :  76500\nEmployee Details\nName :  Jacob\nID :  SIT124\nDept :  ECE\nSalary :  72000\nEmployee Details\nName :  Seema\nID :  SIT125\nDept :  CSE\nSalary :  75000\nEmployee Details\nName :  Abdul\nID :  SIT126\nDept :  ME\nSalary :  65000\nEmployee Details\nName :  Babu\nID :  SIT127\nDept :  EEE\nSalary :  64000\nEnter Department for which you want to update salary CSE\nEnter hike in percentage :  10\nUpdated Salary for Raju\nUpdated Salary for Seema\n\nUPDATED EMPLOYEE DETAILS\n\nEmployee Details\nName :  Raju\nID :  SIT123\nDept :  CSE\nSalary :  84150.0\nEmployee Details\nName :  Jacob\nID :  SIT124\nDept :  ECE\nSalary :  72000\nEmployee Details\nName :  Seema\nID :  SIT125\nDept :  CSE\nSalary :  82500.0\nEmployee Details\nName :  Abdul\nID :  SIT126\nDept :  ME\nSalary :  65000\nEmployee Details\nName :  Babu\nID :  SIT127\nDept :  EEE\nSalary :  64000\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Enter Employee <\/span><span style=\"color: #B392F0\">name<\/span><span style=\"color: #E1E4E8\"> :  Raju<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter Employee <\/span><span style=\"color: #B392F0\">ID<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">SIT123<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter Employee <\/span><span style=\"color: #B392F0\">Dept<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">CSE<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter Employee <\/span><span style=\"color: #B392F0\">Salary<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">76500<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter Employee <\/span><span style=\"color: #B392F0\">name<\/span><span style=\"color: #E1E4E8\"> :  Jacob<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter Employee <\/span><span style=\"color: #B392F0\">ID<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">SIT124<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter Employee <\/span><span style=\"color: #B392F0\">Dept<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">ECE<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter Employee <\/span><span style=\"color: #B392F0\">Salary<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">72000<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter Employee <\/span><span style=\"color: #B392F0\">name<\/span><span style=\"color: #E1E4E8\"> :  Seema<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter Employee <\/span><span style=\"color: #B392F0\">ID<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">SIT125<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter Employee <\/span><span style=\"color: #B392F0\">Dept<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">CSE<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter Employee <\/span><span style=\"color: #B392F0\">Salary<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">75000<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter Employee <\/span><span style=\"color: #B392F0\">name<\/span><span style=\"color: #E1E4E8\"> :  Abdul<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter Employee <\/span><span style=\"color: #B392F0\">ID<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">SIT126<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter Employee <\/span><span style=\"color: #B392F0\">Dept<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">ME<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter Employee <\/span><span style=\"color: #B392F0\">Salary<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">65000<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter Employee <\/span><span style=\"color: #B392F0\">name<\/span><span style=\"color: #E1E4E8\"> :  Babu<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter Employee <\/span><span style=\"color: #B392F0\">ID<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">SIT127<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter Employee <\/span><span style=\"color: #B392F0\">Dept<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">EEE<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter Employee <\/span><span style=\"color: #B392F0\">Salary<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">64000<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">EMPLOYEE<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">DETAILS<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Employee Details<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Name<\/span><span style=\"color: #E1E4E8\"> :  Raju<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">ID<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">SIT123<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Dept<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">CSE<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Salary<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">76500<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Employee Details<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Name<\/span><span style=\"color: #E1E4E8\"> :  Jacob<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">ID<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">SIT124<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Dept<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">ECE<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Salary<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">72000<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Employee Details<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Name<\/span><span style=\"color: #E1E4E8\"> :  Seema<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">ID<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">SIT125<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Dept<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">CSE<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Salary<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">75000<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Employee Details<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Name<\/span><span style=\"color: #E1E4E8\"> :  Abdul<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">ID<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">SIT126<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Dept<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">ME<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Salary<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">65000<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Employee Details<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Name<\/span><span style=\"color: #E1E4E8\"> :  Babu<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">ID<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">SIT127<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Dept<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">EEE<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Salary<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">64000<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter Department for which you want to update salary <\/span><span style=\"color: #79B8FF\">CSE<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter hike <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">percentage<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">10<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Updated Salary for Raju<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Updated Salary for Seema<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">UPDATED<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">EMPLOYEE<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">DETAILS<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Employee Details<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Name<\/span><span style=\"color: #E1E4E8\"> :  Raju<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">ID<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">SIT123<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Dept<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">CSE<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Salary<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">84150.0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Employee Details<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Name<\/span><span style=\"color: #E1E4E8\"> :  Jacob<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">ID<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">SIT124<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Dept<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">ECE<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Salary<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">72000<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Employee Details<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Name<\/span><span style=\"color: #E1E4E8\"> :  Seema<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">ID<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">SIT125<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Dept<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">CSE<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Salary<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">82500.0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Employee Details<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Name<\/span><span style=\"color: #E1E4E8\"> :  Abdul<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">ID<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">SIT126<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Dept<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">ME<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Salary<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">65000<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Employee Details<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Name<\/span><span style=\"color: #E1E4E8\"> :  Babu<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">ID<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">SIT127<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Dept<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">EEE<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Salary<\/span><span style=\"color: #E1E4E8\"> :  <\/span><span style=\"color: #79B8FF\">64000<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Question 8<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"08a\">Polymorphism and Inheritance<\/h3>\n\n\n\n<p>Write a python program to find the whether the given input is palindrome or not (for both string and integer) using the concept of polymorphism and inheritance.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Python Code<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n&quot;&quot;&quot;\nCreated on Thu Mar  9 12:20:20 2023\n\n@author: Prabodh C P\n&quot;&quot;&quot;\n\nclass PaliStr:\n    def __init__(self):\n        self.isPali = False\n        \n    def chkPalindrome(self, myStr):\n        if myStr == myStr[::-1]:\n            self.isPali = True\n        else:\n            self.isPali = False\n            \n        return self.isPali\n            \nclass PaliInt(PaliStr):\n    def __init__(self):\n        self.isPali = False\n        \n    def chkPalindrome(self, val):\n        temp = val\n        rev = 0\n        while temp != 0:\n            dig = temp % 10\n            rev = (rev*10) + dig\n            temp = temp \/\/10\n            \n        if val == rev:\n            self.isPali = True\n        else:\n            self.isPali = False\n        \n        return self.isPali\n\nst = input(&quot;Enter a string : &quot;)\n\nstObj = PaliStr()\nif stObj.chkPalindrome(st):\n    print(&quot;Given string is a Palindrome&quot;)\nelse:\n    print(&quot;Given string is not a Palindrome&quot;)\n\nval = int(input(&quot;Enter a integer : &quot;))    \n\nintObj = PaliInt()\nif intObj.chkPalindrome(val):\n    print(&quot;Given integer is a Palindrome&quot;)\nelse:\n    print(&quot;Given integer is not a Palindrome&quot;)\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">#!\/usr\/bin\/env python3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">-*-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">coding<\/span><span style=\"color: #E1E4E8\">: utf<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">8<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">-*-<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">Created on Thu Mar  9 12:20:20 202<\/span><span style=\"color: #FDAEB7; font-style: italic\">3<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">@author: Prabodh <\/span><span style=\"color: #79B8FF\">C<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">P<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">class PaliStr<\/span><span style=\"color: #FDAEB7; font-style: italic\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    def <\/span><span style=\"color: #B392F0\">__init__<\/span><span style=\"color: #E1E4E8\">(self):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        self.isPali <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> False<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    def <\/span><span style=\"color: #B392F0\">chkPalindrome<\/span><span style=\"color: #E1E4E8\">(self, myStr):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #E1E4E8\"> myStr <\/span><span style=\"color: #F97583\">==<\/span><span style=\"color: #E1E4E8\"> myStr[::<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">]:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            self.isPali <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> True<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #F97583\">else<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            self.isPali <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> False<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #E1E4E8\"> self.isPali<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">class<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">PaliInt<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">PaliStr<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">def<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">__init__<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">isPali<\/span><span style=\"color: #E1E4E8\"> = <\/span><span style=\"color: #B392F0\">False<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">def<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">chkPalindrome<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #B392F0\">val<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">temp<\/span><span style=\"color: #E1E4E8\"> = <\/span><span style=\"color: #B392F0\">val<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">rev<\/span><span style=\"color: #E1E4E8\"> = 0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">while<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">temp<\/span><span style=\"color: #E1E4E8\"> != 0:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            <\/span><span style=\"color: #B392F0\">dig<\/span><span style=\"color: #E1E4E8\"> = <\/span><span style=\"color: #B392F0\">temp<\/span><span style=\"color: #E1E4E8\"> % 10<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            <\/span><span style=\"color: #B392F0\">rev<\/span><span style=\"color: #E1E4E8\"> = (<\/span><span style=\"color: #B392F0\">rev<\/span><span style=\"color: #E1E4E8\">*10) + <\/span><span style=\"color: #B392F0\">dig<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            <\/span><span style=\"color: #B392F0\">temp<\/span><span style=\"color: #E1E4E8\"> = <\/span><span style=\"color: #B392F0\">temp<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #6A737D\">\/\/10<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">if<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">val<\/span><span style=\"color: #E1E4E8\"> == <\/span><span style=\"color: #B392F0\">rev<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">isPali<\/span><span style=\"color: #E1E4E8\"> = <\/span><span style=\"color: #B392F0\">True<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">else<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">isPali<\/span><span style=\"color: #E1E4E8\"> = <\/span><span style=\"color: #B392F0\">False<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">return<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">self<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">isPali<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">st<\/span><span style=\"color: #E1E4E8\"> = <\/span><span style=\"color: #B392F0\">input<\/span><span style=\"color: #E1E4E8\">(&quot;<\/span><span style=\"color: #B392F0\">Enter<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">a<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">string<\/span><span style=\"color: #E1E4E8\"> : &quot;)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">stObj<\/span><span style=\"color: #E1E4E8\"> = <\/span><span style=\"color: #B392F0\">PaliStr<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">if<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">stObj<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">chkPalindrome<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">st<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(&quot;<\/span><span style=\"color: #B392F0\">Given<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">string<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">is<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">a<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Palindrome<\/span><span style=\"color: #E1E4E8\">&quot;)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">else<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(&quot;<\/span><span style=\"color: #B392F0\">Given<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">string<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">is<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">not<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">a<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Palindrome<\/span><span style=\"color: #E1E4E8\">&quot;)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">val<\/span><span style=\"color: #E1E4E8\"> = <\/span><span style=\"color: #B392F0\">int<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">input<\/span><span style=\"color: #E1E4E8\">(&quot;<\/span><span style=\"color: #B392F0\">Enter<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">a<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">integer<\/span><span style=\"color: #E1E4E8\"> : &quot;))    <\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">intObj<\/span><span style=\"color: #E1E4E8\"> = <\/span><span style=\"color: #B392F0\">PaliInt<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">if<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">intObj<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #B392F0\">chkPalindrome<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">val<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(&quot;<\/span><span style=\"color: #B392F0\">Given<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">integer<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">is<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">a<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Palindrome<\/span><span style=\"color: #E1E4E8\">&quot;)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">else<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(&quot;<\/span><span style=\"color: #B392F0\">Given<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">integer<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">is<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">not<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">a<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Palindrome<\/span><span style=\"color: #E1E4E8\">&quot;)<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This Python program defines two classes, <code>PaliStr<\/code> and <code>PaliInt<\/code>, which check whether a given string or integer is a palindrome. Here&#8217;s a brief description:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>PaliStr Class:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The <code>PaliStr<\/code> class has an attribute <code>isPali<\/code> initialized to <code>False<\/code>.<\/li>\n\n\n\n<li>The <code>__init__<\/code> method initializes the <code>isPali<\/code> attribute.<\/li>\n\n\n\n<li>The <code>chkPalindrome<\/code> method checks whether a given string is a palindrome.\n<ul class=\"wp-block-list\">\n<li>It compares the string with its reverse.<\/li>\n\n\n\n<li>If they match, <code>isPali<\/code> is set to <code>True<\/code>, indicating a palindrome.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>PaliInt Class:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The <code>PaliInt<\/code> class is a subclass of <code>PaliStr<\/code>.<\/li>\n\n\n\n<li>It has a similar structure but is designed to check palindromes for integers.<\/li>\n\n\n\n<li>The <code>chkPalindrome<\/code> method reverses the digits of the integer and compares it with the original value.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Example Usage:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The program takes user input for both a string and an integer.<\/li>\n\n\n\n<li>It creates instances of <code>PaliStr<\/code> and <code>PaliInt<\/code>.<\/li>\n\n\n\n<li>It calls the <code>chkPalindrome<\/code> method for each instance to check whether the given input is a palindrome.<\/li>\n\n\n\n<li>The program then prints whether the string or integer is a palindrome based on the results.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Output:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The program outputs whether the entered string and integer are palindromes.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>This program demonstrates the use of class inheritance and polymorphism in Python. It provides a reusable and modular way to check whether a given input, whether a string or an integer, is a palindrome.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Enter a string : madam\nGiven string is a Palindrome\nEnter a integer : 567587\nGiven integer is not a Palindrome\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Enter a <\/span><span style=\"color: #B392F0\">string<\/span><span style=\"color: #E1E4E8\"> : madam<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Given string is a Palindrome<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter a <\/span><span style=\"color: #B392F0\">integer<\/span><span style=\"color: #E1E4E8\"> : <\/span><span style=\"color: #79B8FF\">567587<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Given integer is not a Palindrome<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Enter a string : INDIA\nGiven string is not a Palindrome\nEnter a integer : 6789876\nGiven integer is a Palindrome\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Enter a <\/span><span style=\"color: #B392F0\">string<\/span><span style=\"color: #E1E4E8\"> : <\/span><span style=\"color: #79B8FF\">INDIA<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Given string is not a Palindrome<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter a <\/span><span style=\"color: #B392F0\">integer<\/span><span style=\"color: #E1E4E8\"> : <\/span><span style=\"color: #79B8FF\">6789876<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Given integer is a Palindrome<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Question 9<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"09a\">Download XKCD comics<\/h3>\n\n\n\n<p class=\"has-text-align-justify\">Write a python program to download the all XKCD comics<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Python Code<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n&quot;&quot;&quot;\nCreated on Thu Mar  9 13:02:47 2023\n\n@author: Prabodh C P\n&quot;&quot;&quot;\n\nimport requests\nimport os\nfrom bs4 import BeautifulSoup\n\n# Set the URL of the first XKCD comic\nurl = 'https:\/\/xkcd.com\/1\/'\n\n# Create a folder to store the comics\nif not os.path.exists('xkcd_comics'):\n    os.makedirs('xkcd_comics')\n\n# Loop through all the comics\nwhile True:\n    try:\n        # Download the page content\n        res = requests.get(url)\n        res.raise_for_status()\n\n        # Parse the page content using BeautifulSoup\n        soup = BeautifulSoup(res.text, 'html.parser')\n\n        # Find the URL of the comic image\n        comic_elem = soup.select('#comic img')\n        if comic_elem == []:\n            print('Could not find comic image.')\n        else:\n            comic_url = 'https:' + comic_elem[0].get('src')\n\n            # Download the comic image\n            print(f'Downloading {comic_url}...')\n            res = requests.get(comic_url)\n            res.raise_for_status()\n\n            # Save the comic image to the xkcd_comics folder\n            image_file = open(os.path.join('xkcd_comics', os.path.basename(comic_url)), 'wb')\n            for chunk in res.iter_content(100000):\n                image_file.write(chunk)\n            image_file.close()\n\n        # Get the URL of the previous comic\n        prev_link = soup.select('a[rel=&quot;prev&quot;]')[0]\n        if not prev_link:\n            break\n        url = 'https:\/\/xkcd.com' + prev_link.get('href')\n\n    except requests.exceptions.RequestException as e:\n        print(f&quot;Error: {e}&quot;)\n        print(&quot;Stopping due to a bad URL.&quot;)\n        break\n\nprint('All comics downloaded.')\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">#!\/usr\/bin\/env python3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">-*-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">coding<\/span><span style=\"color: #E1E4E8\">: utf<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">8<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">-*-<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">Created on Thu Mar  9 13:02:47 202<\/span><span style=\"color: #FDAEB7; font-style: italic\">3<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">@author: Prabodh <\/span><span style=\"color: #79B8FF\">C<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">P<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">import request<\/span><span style=\"color: #FDAEB7; font-style: italic\">s<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">import<\/span><span style=\"color: #E1E4E8\"> os<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">from<\/span><span style=\"color: #E1E4E8\"> bs4 import BeautifulSoup<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># Set the URL of the first XKCD comic<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">url = <\/span><span style=\"color: #9ECBFF\">&#39;https:\/\/xkcd.com\/1\/&#39;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># Create a folder to store the comics<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">if not os.path.exists(<\/span><span style=\"color: #9ECBFF\">&#39;xkcd_comics&#39;<\/span><span style=\"color: #E1E4E8\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    os.makedirs(<\/span><span style=\"color: #9ECBFF\">&#39;xkcd_comics&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># Loop through all the comics<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">while True:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    try:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        # Download the page content<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        res = requests.get(url)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        res.raise_for_status()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        # Parse the page content using BeautifulSoup<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        soup = BeautifulSoup(res.text, <\/span><span style=\"color: #9ECBFF\">&#39;html.parser&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        # Find the URL of the comic image<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        comic_elem = soup.select(<\/span><span style=\"color: #9ECBFF\">&#39;#comic img&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        if comic_elem == []:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            print(<\/span><span style=\"color: #9ECBFF\">&#39;Could not find comic image.&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        else:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            comic_url = <\/span><span style=\"color: #9ECBFF\">&#39;https:&#39;<\/span><span style=\"color: #E1E4E8\"> + comic_elem[0].get(<\/span><span style=\"color: #9ECBFF\">&#39;src&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            # Download the comic image<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            print(f<\/span><span style=\"color: #9ECBFF\">&#39;Downloading {comic_url}...&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            res = requests.get(comic_url)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            res.raise_for_status()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            # Save the comic image to the xkcd_comics folder<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            image_file = open(os.path.join(<\/span><span style=\"color: #9ECBFF\">&#39;xkcd_comics&#39;<\/span><span style=\"color: #E1E4E8\">, os.path.basename(comic_url)), <\/span><span style=\"color: #9ECBFF\">&#39;wb&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            for chunk in res.iter_content(100000):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">                image_file.write(chunk)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            image_file.close()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        # Get the URL of the previous comic<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        prev_link = soup.select(<\/span><span style=\"color: #9ECBFF\">&#39;a[rel=&quot;prev&quot;]&#39;<\/span><span style=\"color: #E1E4E8\">)[0]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        if not prev_link:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            break<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        url = <\/span><span style=\"color: #9ECBFF\">&#39;https:\/\/xkcd.com&#39;<\/span><span style=\"color: #E1E4E8\"> + prev_link.get(<\/span><span style=\"color: #9ECBFF\">&#39;href&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    except requests.exceptions.RequestException as e:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        print(f<\/span><span style=\"color: #9ECBFF\">&quot;Error: {e}&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        print(<\/span><span style=\"color: #9ECBFF\">&quot;Stopping due to a bad URL.&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        break<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">print(<\/span><span style=\"color: #9ECBFF\">&#39;All comics downloaded.&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This Python script downloads XKCD comics from the XKCD website and saves them to a local folder. Here&#8217;s a brief description:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Initialization:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The script starts by setting the URL of the first XKCD comic (<code>https:\/\/xkcd.com\/1\/<\/code>).<\/li>\n\n\n\n<li>It creates a folder named <code>xkcd_comics<\/code> to store the downloaded comics.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Comic Download Loop:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The script enters a loop that iterates through XKCD comics.<\/li>\n\n\n\n<li>For each iteration:\n<ul class=\"wp-block-list\">\n<li>It sends an HTTP request to the specified URL using the <code>requests<\/code> library.<\/li>\n\n\n\n<li>The HTML content of the page is parsed using <code>BeautifulSoup<\/code> to extract relevant information.<\/li>\n\n\n\n<li>It finds the URL of the comic image on the page.<\/li>\n\n\n\n<li>If the comic image is found, it downloads the image and saves it to the local <code>xkcd_comics<\/code> folder.<\/li>\n\n\n\n<li>It then retrieves the URL of the previous comic to prepare for the next iteration.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Output:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The script prints messages indicating the progress, such as downloading the comic image.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Termination:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The loop continues until there are no more previous comics, indicating the end of the XKCD series.<\/li>\n\n\n\n<li>The script prints &#8216;All comics downloaded&#8217; when the process is complete.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>This program automates the process of downloading XKCD comics, making it convenient for fans of the webcomic to archive the entire series locally. The use of the <code>requests<\/code> library simplifies web scraping, and the <code>BeautifulSoup<\/code> library aids in parsing HTML content. The program demonstrates web scraping techniques for extracting specific data from web pages.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Downloading https:\/\/imgs.xkcd.com\/comics\/barrel_cropped_(1).jpg...\nDownloading https:\/\/imgs.xkcd.com\/comics\/radians_are_cursed.png...\nDownloading https:\/\/imgs.xkcd.com\/comics\/presents_for_biologists.png...\nDownloading https:\/\/imgs.xkcd.com\/comics\/launch_window.png...\nDownloading https:\/\/imgs.xkcd.com\/comics\/obituary_editor.png...\nDownloading https:\/\/imgs.xkcd.com\/comics\/fanservice.png...\nDownloading https:\/\/imgs.xkcd.com\/comics\/hand_dryers.png...\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Downloading <\/span><span style=\"color: #B392F0\">https<\/span><span style=\"color: #E1E4E8\">:<\/span><span style=\"color: #6A737D\">\/\/imgs.xkcd.com\/comics\/barrel_cropped_(1).jpg...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Downloading <\/span><span style=\"color: #B392F0\">https<\/span><span style=\"color: #E1E4E8\">:<\/span><span style=\"color: #6A737D\">\/\/imgs.xkcd.com\/comics\/radians_are_cursed.png...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Downloading <\/span><span style=\"color: #B392F0\">https<\/span><span style=\"color: #E1E4E8\">:<\/span><span style=\"color: #6A737D\">\/\/imgs.xkcd.com\/comics\/presents_for_biologists.png...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Downloading <\/span><span style=\"color: #B392F0\">https<\/span><span style=\"color: #E1E4E8\">:<\/span><span style=\"color: #6A737D\">\/\/imgs.xkcd.com\/comics\/launch_window.png...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Downloading <\/span><span style=\"color: #B392F0\">https<\/span><span style=\"color: #E1E4E8\">:<\/span><span style=\"color: #6A737D\">\/\/imgs.xkcd.com\/comics\/obituary_editor.png...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Downloading <\/span><span style=\"color: #B392F0\">https<\/span><span style=\"color: #E1E4E8\">:<\/span><span style=\"color: #6A737D\">\/\/imgs.xkcd.com\/comics\/fanservice.png...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Downloading <\/span><span style=\"color: #B392F0\">https<\/span><span style=\"color: #E1E4E8\">:<\/span><span style=\"color: #6A737D\">\/\/imgs.xkcd.com\/comics\/hand_dryers.png...<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"09b\">Spreadsheet Operations<\/h3>\n\n\n\n<p>Demonstrate python program to read the data from the spreadsheet and write the data in to the spreadsheet<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Python Code<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n&quot;&quot;&quot;\nCreated on Thu Mar  9 15:34:37 2023\n\n@author: Prabodh C P\n&quot;&quot;&quot;\n\nfrom openpyxl import Workbook \nfrom openpyxl.styles import Font\n\nwb = Workbook() \nsheet = wb.active\nsheet.title = &quot;Language&quot;\nwb.create_sheet(title = &quot;Capital&quot;)\n\nlang = [&quot;Kannada&quot;, &quot;Telugu&quot;, &quot;Tamil&quot;]\nstate = [&quot;Karnataka&quot;, &quot;Telangana&quot;, &quot;Tamil Nadu&quot;]\ncapital = [&quot;Bengaluru&quot;, &quot;Hyderabad&quot;, &quot;Chennai&quot;]\ncode =['KA', 'TS', 'TN']\n\nsheet.cell(row = 1, column = 1).value = &quot;State&quot;\nsheet.cell(row = 1, column = 2).value = &quot;Language&quot;\nsheet.cell(row = 1, column = 3).value = &quot;Code&quot;\n\n\nft = Font(bold=True)\nfor row in sheet[&quot;A1:C1&quot;]:\n    for cell in row:\n        cell.font = ft\n        \nfor i in range(2,5):\n    sheet.cell(row = i, column = 1).value = state[i-2]\n    sheet.cell(row = i, column = 2).value = lang[i-2]\n    sheet.cell(row = i, column = 3).value = code[i-2]\n    \nwb.save(&quot;demo.xlsx&quot;)\n\n\nsheet = wb[&quot;Capital&quot;]\n\nsheet.cell(row = 1, column = 1).value = &quot;State&quot;\nsheet.cell(row = 1, column = 2).value = &quot;Capital&quot;\nsheet.cell(row = 1, column = 3).value = &quot;Code&quot;\n\nft = Font(bold=True)\nfor row in sheet[&quot;A1:C1&quot;]:\n    for cell in row:\n        cell.font = ft\n        \nfor i in range(2,5):\n    sheet.cell(row = i, column = 1).value = state[i-2]\n    sheet.cell(row = i, column = 2).value = capital[i-2]\n    sheet.cell(row = i, column = 3).value = code[i-2]\n    \nwb.save(&quot;demo.xlsx&quot;)\nprint(&quot;File demo.xlsx created successfully&quot;)\n\nsrchCode = input(&quot;Enter state code for finding capital &quot;)\nfor i in range(2,5):\n    data = sheet.cell(row = i, column = 3).value\n    if data == srchCode:\n        print(&quot;Corresponding capital for code&quot;, srchCode, &quot;is&quot;, sheet.cell(row = i, column = 2).value)\n        \n\nsheet = wb[&quot;Language&quot;]\n\nsrchCode = input(&quot;Enter state code for finding language &quot;)\nfor i in range(2,5):\n    data = sheet.cell(row = i, column = 3).value\n    if data == srchCode:\n        print(&quot;Corresponding language for code&quot;, srchCode, &quot;is&quot;, sheet.cell(row = i, column = 2).value)\n\nwb.close()\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">#!\/usr\/bin\/env python3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">-*-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">coding<\/span><span style=\"color: #E1E4E8\">: utf<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">8<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">-*-<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">Created on Thu Mar  9 15:34:37 202<\/span><span style=\"color: #FDAEB7; font-style: italic\">3<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">@author: Prabodh <\/span><span style=\"color: #79B8FF\">C<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">P<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">from openpyxl import Workbook<\/span><span style=\"color: #FDAEB7; font-style: italic\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">from openpyxl.styles <\/span><span style=\"color: #F97583\">import<\/span><span style=\"color: #E1E4E8\"> Font<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">wb = Workbook() <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">sheet = wb.active<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">sheet.title = <\/span><span style=\"color: #9ECBFF\">&quot;Language&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">wb.create_sheet(title = <\/span><span style=\"color: #9ECBFF\">&quot;Capital&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">lang = [<\/span><span style=\"color: #9ECBFF\">&quot;Kannada&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;Telugu&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;Tamil&quot;<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">state = [<\/span><span style=\"color: #9ECBFF\">&quot;Karnataka&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;Telangana&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;Tamil Nadu&quot;<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">capital = [<\/span><span style=\"color: #9ECBFF\">&quot;Bengaluru&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;Hyderabad&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;Chennai&quot;<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">code =[<\/span><span style=\"color: #9ECBFF\">&#39;KA&#39;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&#39;TS&#39;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&#39;TN&#39;<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">sheet.cell(row = 1, column = 1).value = <\/span><span style=\"color: #9ECBFF\">&quot;State&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">sheet.cell(row = 1, column = 2).value = <\/span><span style=\"color: #9ECBFF\">&quot;Language&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">sheet.cell(row = 1, column = 3).value = <\/span><span style=\"color: #9ECBFF\">&quot;Code&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">ft = Font(bold=True)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">for row in sheet[<\/span><span style=\"color: #9ECBFF\">&quot;A1:C1&quot;<\/span><span style=\"color: #E1E4E8\">]:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    for cell in row:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        cell.font = ft<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">for i in range(2,5):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    sheet.cell(row = i, column = 1).value = state[i-2]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    sheet.cell(row = i, column = 2).value = lang[i-2]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    sheet.cell(row = i, column = 3).value = code[i-2]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">wb.save(<\/span><span style=\"color: #9ECBFF\">&quot;demo.xlsx&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">sheet = wb[<\/span><span style=\"color: #9ECBFF\">&quot;Capital&quot;<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">sheet.cell(row = 1, column = 1).value = <\/span><span style=\"color: #9ECBFF\">&quot;State&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">sheet.cell(row = 1, column = 2).value = <\/span><span style=\"color: #9ECBFF\">&quot;Capital&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">sheet.cell(row = 1, column = 3).value = <\/span><span style=\"color: #9ECBFF\">&quot;Code&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">ft = Font(bold=True)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">for row in sheet[<\/span><span style=\"color: #9ECBFF\">&quot;A1:C1&quot;<\/span><span style=\"color: #E1E4E8\">]:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    for cell in row:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        cell.font = ft<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">for i in range(2,5):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    sheet.cell(row = i, column = 1).value = state[i-2]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    sheet.cell(row = i, column = 2).value = capital[i-2]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    sheet.cell(row = i, column = 3).value = code[i-2]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">wb.save(<\/span><span style=\"color: #9ECBFF\">&quot;demo.xlsx&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">print(<\/span><span style=\"color: #9ECBFF\">&quot;File demo.xlsx created successfully&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">srchCode = input(<\/span><span style=\"color: #9ECBFF\">&quot;Enter state code for finding capital &quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">for i in range(2,5):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    data = sheet.cell(row = i, column = 3).value<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    if data == srchCode:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        print(<\/span><span style=\"color: #9ECBFF\">&quot;Corresponding capital for code&quot;<\/span><span style=\"color: #E1E4E8\">, srchCode, <\/span><span style=\"color: #9ECBFF\">&quot;is&quot;<\/span><span style=\"color: #E1E4E8\">, sheet.cell(row = i, column = 2).value)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">sheet = wb[<\/span><span style=\"color: #9ECBFF\">&quot;Language&quot;<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">srchCode = input(<\/span><span style=\"color: #9ECBFF\">&quot;Enter state code for finding language &quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">for i in range(2,5):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    data = sheet.cell(row = i, column = 3).value<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    if data == srchCode:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        print(<\/span><span style=\"color: #9ECBFF\">&quot;Corresponding language for code&quot;<\/span><span style=\"color: #E1E4E8\">, srchCode, <\/span><span style=\"color: #9ECBFF\">&quot;is&quot;<\/span><span style=\"color: #E1E4E8\">, sheet.cell(row = i, column = 2).value)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">wb.close()<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This Python script uses the <code>openpyxl<\/code> library to create an Excel workbook with two sheets, &#8220;Language&#8221; and &#8220;Capital&#8221;. It populates the sheets with data related to states, languages, capitals, and codes. The script then prompts the user to enter a state code and finds and prints the corresponding capital and language.<\/p>\n\n\n\n<p>Here&#8217;s a brief description of the program:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Workbook and Sheets Creation:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The script creates an Excel workbook using <code>Workbook()<\/code> from <code>openpyxl<\/code>.<\/li>\n\n\n\n<li>It adds two sheets named &#8220;Language&#8221; and &#8220;Capital&#8221; using <code>create_sheet()<\/code>.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Data Population:<\/strong>\n<ul class=\"wp-block-list\">\n<li>For each sheet, it populates the headers and data using nested loops and cell assignments.<\/li>\n\n\n\n<li>Headers are formatted with bold using the <code>Font<\/code> class from <code>openpyxl.styles<\/code>.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Saving the Workbook:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The workbook is saved with the name &#8220;demo.xlsx&#8221; using <code>save()<\/code>.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Search and Print:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The script prompts the user to enter a state code.<\/li>\n\n\n\n<li>It then searches for the code in both sheets, &#8220;Language&#8221; and &#8220;Capital&#8221;.<\/li>\n\n\n\n<li>If a match is found, it prints the corresponding capital or language.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Workbook Closure:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The workbook is closed using <code>close()<\/code>.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>This program showcases the use of <code>openpyxl<\/code> for Excel file manipulation, including creating sheets, populating data, and searching for information within the workbook. It can be useful for managing data related to states, languages, and capitals in a structured Excel format.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Enter state code for finding capital KA\nCorresponding capital for code KA is Bengaluru\nEnter state code for finding language TS\nCorresponding language for code TS is Telugu\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Enter state code for finding capital <\/span><span style=\"color: #79B8FF\">KA<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Corresponding capital for code <\/span><span style=\"color: #79B8FF\">KA<\/span><span style=\"color: #E1E4E8\"> is Bengaluru<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Enter state code for finding language <\/span><span style=\"color: #79B8FF\">TS<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Corresponding language for code <\/span><span style=\"color: #79B8FF\">TS<\/span><span style=\"color: #E1E4E8\"> is Telugu<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Question 10<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"10a\">Merge selected pages from Multiple PDFs to a new PDF<\/h3>\n\n\n\n<p class=\"has-text-align-justify\">Write a python program to combine select pages from many PDFs<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Python Code<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n&quot;&quot;&quot;\nCreated on Thu Mar  9 17:34:55 2023\n\n@author: Prabodh C P\n&quot;&quot;&quot;\n\nfrom PyPDF2 import PdfWriter, PdfReader\n\nnum = int(input(&quot;Enter page number you want combine from multiple documents &quot;))\n\npdf1 = open('birds.pdf', 'rb')\npdf2 = open('birdspic.pdf', 'rb')\n\npdf_writer = PdfWriter()\n\npdf1_reader = PdfReader(pdf1)    \npage = pdf1_reader.pages[num - 1]\npdf_writer.add_page(page)\n\npdf2_reader = PdfReader(pdf2)    \npage = pdf2_reader.pages[num - 1]\npdf_writer.add_page(page)\n\nwith open('output.pdf', 'wb') as output:\n    pdf_writer.write(output)\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">#!\/usr\/bin\/env python3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">-*-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">coding<\/span><span style=\"color: #E1E4E8\">: utf<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">8<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">-*-<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">Created on Thu Mar  9 17:34:55 202<\/span><span style=\"color: #FDAEB7; font-style: italic\">3<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">@author: Prabodh <\/span><span style=\"color: #79B8FF\">C<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">P<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">from PyPDF2 import PdfWriter, PdfReade<\/span><span style=\"color: #FDAEB7; font-style: italic\">r<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">num <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">int<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">input<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Enter page number you want combine from multiple documents &quot;<\/span><span style=\"color: #E1E4E8\">))<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">pdf1 <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">open<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;birds.pdf&#39;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&#39;rb&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">pdf2 <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">open<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;birdspic.pdf&#39;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&#39;rb&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">pdf_writer <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">PdfWriter<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">pdf1_reader <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">PdfReader<\/span><span style=\"color: #E1E4E8\">(pdf1)    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">page <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> pdf1_reader.pages[num <\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">pdf_writer.<\/span><span style=\"color: #B392F0\">add_page<\/span><span style=\"color: #E1E4E8\">(page)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">pdf2_reader <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">PdfReader<\/span><span style=\"color: #E1E4E8\">(pdf2)    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">page <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> pdf2_reader.pages[num <\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">pdf_writer.<\/span><span style=\"color: #B392F0\">add_page<\/span><span style=\"color: #E1E4E8\">(page)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">with<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">open<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;output.pdf&#39;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&#39;wb&#39;<\/span><span style=\"color: #E1E4E8\">) <\/span><span style=\"color: #F97583\">as<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">output<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    pdf_writer.<\/span><span style=\"color: #B392F0\">write<\/span><span style=\"color: #E1E4E8\">(output)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This Python script uses the <code>PyPDF2<\/code> library to combine specific pages from two PDF documents into a new PDF file. Here&#8217;s a brief description of the program:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>User Input:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The script prompts the user to enter a page number (<code>num<\/code>) that they want to combine from multiple documents.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>PDF File Opening:<\/strong>\n<ul class=\"wp-block-list\">\n<li>It opens two existing PDF files, &#8216;birds.pdf&#8217; and &#8216;birdspic.pdf&#8217;, in binary read mode (<code>'rb'<\/code>).<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>PDF Writer Initialization:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The script initializes a <code>PdfWriter<\/code> object from <code>PyPDF2<\/code>. This object will be used to write the combined pages to a new PDF file.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Page Extraction and Combination:<\/strong>\n<ul class=\"wp-block-list\">\n<li>It reads the specified page (<code>num - 1<\/code> to adjust for zero-based indexing) from each input PDF using <code>PdfReader<\/code> from <code>PyPDF2<\/code>.<\/li>\n\n\n\n<li>The extracted pages are added to the <code>PdfWriter<\/code> object.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Output PDF Creation:<\/strong>\n<ul class=\"wp-block-list\">\n<li>It writes the combined pages to a new PDF file named &#8216;output.pdf&#8217; using the <code>write()<\/code> method.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>File Closure:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The input PDF files are closed using the <code>close()<\/code> method.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>This program demonstrates a simple way to extract specific pages from different PDF documents and combine them into a new PDF file. It can be useful for scenarios where you want to create a new document by selecting specific pages from existing PDFs.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<p>This program allows you to extract specific pages from two PDF files, &#8220;birds.pdf&#8221; and &#8220;birdspic.pdf,&#8221; by entering the page numbers as user input. Once you input the desired page numbers, the program fetches those pages from both PDF files and combines them into a new file called &#8220;output.pdf.&#8221; This way, you can easily compile the desired pages from multiple PDF files into one document for your convenience. <\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Enter page number you want combine from multiple documents 3\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Enter page number you want combine from multiple documents <\/span><span style=\"color: #79B8FF\">3<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div data-wp-interactive=\"core\/file\" class=\"wp-block-file\"><object data-wp-bind--hidden=\"!state.hasPdfPreview\" hidden class=\"wp-block-file__embed\" data=\"https:\/\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2023\/03\/birds.pdf\" type=\"application\/pdf\" style=\"width:100%;height:600px\" aria-label=\"Embed of birds.\"><\/object><a id=\"wp-block-file--media-27d15291-bcdf-4c8d-b5d2-8d04f2c63238\" href=\"https:\/\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2023\/03\/birds.pdf\">birds<\/a><a href=\"https:\/\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2023\/03\/birds.pdf\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-27d15291-bcdf-4c8d-b5d2-8d04f2c63238\">Download<\/a><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div data-wp-interactive=\"core\/file\" class=\"wp-block-file\"><object data-wp-bind--hidden=\"!state.hasPdfPreview\" hidden class=\"wp-block-file__embed\" data=\"https:\/\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2023\/03\/birdspic.pdf\" type=\"application\/pdf\" style=\"width:100%;height:600px\" aria-label=\"Embed of birdspic.\"><\/object><a id=\"wp-block-file--media-a6d38e46-dc9b-4f0c-a2bc-c641ab2d48d9\" href=\"https:\/\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2023\/03\/birdspic.pdf\">birdspic<\/a><a href=\"https:\/\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2023\/03\/birdspic.pdf\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-a6d38e46-dc9b-4f0c-a2bc-c641ab2d48d9\">Download<\/a><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div data-wp-interactive=\"core\/file\" class=\"wp-block-file\"><object data-wp-bind--hidden=\"!state.hasPdfPreview\" hidden class=\"wp-block-file__embed\" data=\"https:\/\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2023\/03\/output.pdf\" type=\"application\/pdf\" style=\"width:100%;height:600px\" aria-label=\"Embed of output.\"><\/object><a id=\"wp-block-file--media-27e66c8c-e8fd-4a06-a1c5-8106763ccc85\" href=\"https:\/\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2023\/03\/output.pdf\">output<\/a><a href=\"https:\/\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2023\/03\/output.pdf\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-27e66c8c-e8fd-4a06-a1c5-8106763ccc85\">Download<\/a><\/div>\n<\/div>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"10b\"> Fetch weather data from the JSON <\/h3>\n\n\n\n<p class=\"has-text-align-justify\">Write a python program to fetch current weather data from the JSON file<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Python Code<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n&quot;&quot;&quot;\nCreated on Fri Mar 10 09:22:53 2023\n\n@author: Prabodh C P\n&quot;&quot;&quot;\n\nimport json\n\n# Load the JSON data from file\nwith open('weather_data.json') as f:\n    data = json.load(f)\n\n# Extract the required weather data\ncurrent_temp = data['main']['temp']\nhumidity = data['main']['humidity']\nweather_desc = data['weather'][0]['description']\n\n# Display the weather data\nprint(f&quot;Current temperature: {current_temp}\u00b0C&quot;)\nprint(f&quot;Humidity: {humidity}%&quot;)\nprint(f&quot;Weather description: {weather_desc}&quot;)\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">#!\/usr\/bin\/env python3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># <\/span><span style=\"color: #F97583\">-*-<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">coding<\/span><span style=\"color: #E1E4E8\">: utf<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">8<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">-*-<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">Created on Fri Mar 10 09:22:53 202<\/span><span style=\"color: #FDAEB7; font-style: italic\">3<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">@author: Prabodh <\/span><span style=\"color: #79B8FF\">C<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">P<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">import jso<\/span><span style=\"color: #FDAEB7; font-style: italic\">n<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># Load the <\/span><span style=\"color: #79B8FF\">JSON<\/span><span style=\"color: #E1E4E8\"> data from file<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">with<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">open<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;weather_data.json&#39;<\/span><span style=\"color: #E1E4E8\">) <\/span><span style=\"color: #F97583\">as<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">f<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    data <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> json.<\/span><span style=\"color: #B392F0\">load<\/span><span style=\"color: #E1E4E8\">(f)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># Extract the required weather data<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">current_temp <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> data[<\/span><span style=\"color: #9ECBFF\">&#39;main&#39;<\/span><span style=\"color: #E1E4E8\">][<\/span><span style=\"color: #9ECBFF\">&#39;temp&#39;<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">humidity <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> data[<\/span><span style=\"color: #9ECBFF\">&#39;main&#39;<\/span><span style=\"color: #E1E4E8\">][<\/span><span style=\"color: #9ECBFF\">&#39;humidity&#39;<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">weather_desc <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> data[<\/span><span style=\"color: #9ECBFF\">&#39;weather&#39;<\/span><span style=\"color: #E1E4E8\">][<\/span><span style=\"color: #79B8FF\">0<\/span><span style=\"color: #E1E4E8\">][<\/span><span style=\"color: #9ECBFF\">&#39;description&#39;<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\"># Display the weather data<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(f<\/span><span style=\"color: #9ECBFF\">&quot;Current temperature: {current_temp}\u00b0C&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(f<\/span><span style=\"color: #9ECBFF\">&quot;Humidity: {humidity}%&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(f<\/span><span style=\"color: #9ECBFF\">&quot;Weather description: {weather_desc}&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">JSON File : <\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"{\n  &quot;coord&quot;: {\n    &quot;lon&quot;: -73.99,\n    &quot;lat&quot;: 40.73\n  },\n  &quot;weather&quot;: [\n    {\n      &quot;id&quot;: 800,\n      &quot;main&quot;: &quot;Clear&quot;,\n      &quot;description&quot;: &quot;clear sky&quot;,\n      &quot;icon&quot;: &quot;01d&quot;\n    }\n  ],\n  &quot;base&quot;: &quot;stations&quot;,\n  &quot;main&quot;: {\n    &quot;temp&quot;: 15.45,\n    &quot;feels_like&quot;: 12.74,\n    &quot;temp_min&quot;: 14.44,\n    &quot;temp_max&quot;: 16.11,\n    &quot;pressure&quot;: 1017,\n    &quot;humidity&quot;: 64\n  },\n  &quot;visibility&quot;: 10000,\n  &quot;wind&quot;: {\n    &quot;speed&quot;: 4.63,\n    &quot;deg&quot;: 180\n  },\n  &quot;clouds&quot;: {\n    &quot;all&quot;: 1\n  },\n  &quot;dt&quot;: 1617979985,\n  &quot;sys&quot;: {\n    &quot;type&quot;: 1,\n    &quot;id&quot;: 5141,\n    &quot;country&quot;: &quot;US&quot;,\n    &quot;sunrise&quot;: 1617951158,\n    &quot;sunset&quot;: 1618000213\n  },\n  &quot;timezone&quot;: -14400,\n  &quot;id&quot;: 5128581,\n  &quot;name&quot;: &quot;New York&quot;,\n  &quot;cod&quot;: 200\n}\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;coord&quot;<\/span><span style=\"color: #E1E4E8\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;lon&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">73.99<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;lat&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">40.73<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;weather&quot;<\/span><span style=\"color: #E1E4E8\">: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #9ECBFF\">&quot;id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">800<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #9ECBFF\">&quot;main&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Clear&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #9ECBFF\">&quot;description&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;clear sky&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #9ECBFF\">&quot;icon&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;01d&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  ],<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;base&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;stations&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;main&quot;<\/span><span style=\"color: #E1E4E8\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;temp&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">15.45<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;feels_like&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">12.74<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;temp_min&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">14.44<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;temp_max&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">16.11<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;pressure&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1017<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;humidity&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">64<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;visibility&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">10000<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;wind&quot;<\/span><span style=\"color: #E1E4E8\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;speed&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">4.63<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;deg&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">180<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;clouds&quot;<\/span><span style=\"color: #E1E4E8\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;all&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;dt&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1617979985<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;sys&quot;<\/span><span style=\"color: #E1E4E8\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;type&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">5141<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;country&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;US&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;sunrise&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1617951158<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;sunset&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1618000213<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;timezone&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">14400<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">5128581<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;name&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;New York&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;cod&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">200<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This Python script reads weather data from a JSON file (&#8216;weather_data.json&#8217;) and extracts specific information, such as current temperature, humidity, and weather description. Here&#8217;s a brief description of the program:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>JSON File Loading:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The script uses the <code>json.load()<\/code> function to load data from the &#8216;weather_data.json&#8217; file, which presumably contains weather-related information in JSON format.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Data Extraction:<\/strong>\n<ul class=\"wp-block-list\">\n<li>It extracts key weather information from the loaded JSON data, such as current temperature (<code>current_temp<\/code>), humidity (<code>humidity<\/code>), and weather description (<code>weather_desc<\/code>).<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Displaying Weather Information:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The script prints the extracted weather data using formatted strings.\n<ul class=\"wp-block-list\">\n<li>Current temperature is displayed in degrees Celsius.<\/li>\n\n\n\n<li>Humidity is displayed as a percentage.<\/li>\n\n\n\n<li>Weather description is displayed.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Example JSON Structure:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The provided example JSON structure contains various weather-related details such as temperature, humidity, wind speed, and more. The script focuses on extracting specific data from this structure.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>This program is useful for accessing and displaying relevant information from JSON files, which can be particularly handy for handling API responses or data stored in JSON format. In this example, it&#8217;s tailored for weather data retrieval.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Current temperature: 15.45\u00b0C\nHumidity: 64%\nWeather description: clear sky\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Current <\/span><span style=\"color: #B392F0\">temperature<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">15.45<\/span><span style=\"color: #E1E4E8\">\u00b0<\/span><span style=\"color: #79B8FF\">C<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">Humidity<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">64<\/span><span style=\"color: #F97583\">%<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">Weather <\/span><span style=\"color: #B392F0\">description<\/span><span style=\"color: #E1E4E8\">: clear sky<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>If you are also looking for the <a href=\"https:\/\/moodle.sit.ac.in\/blog\/design-analysis-of-algorithms-lab-manual-21cs42\/\" title=\"Algorithms\">Algorithms<\/a> Lab Manual ( 21CS42), Click on the link below <\/p>\n\n\n\n<p><blockquote class=\"wp-embedded-content\" data-secret=\"KnqAHBrPm9\"><a href=\"https:\/\/moodle.sit.ac.in\/blog\/design-analysis-of-algorithms-lab-manual-21cs42\/\">Design &amp; Analysis of\u00a0Algorithms Lab Manual &#8211; 21CS42<\/a><\/blockquote><iframe class=\"wp-embedded-content lazyload\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Design &amp; Analysis of\u00a0Algorithms Lab Manual &#8211; 21CS42&#8221; &#8212; MyBlogosphere\" data-src=\"https:\/\/moodle.sit.ac.in\/blog\/design-analysis-of-algorithms-lab-manual-21cs42\/embed\/#?secret=MRHXMkSNNk#?secret=KnqAHBrPm9\" data-secret=\"KnqAHBrPm9\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" data-load-mode=\"1\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog post, you will find solutions for the PYTHON PROGRAMMING LABORATORY (21CSL46) course work for the IV semester of VTU university. To follow along, you will need to set up a Python programming environment. We recommend using the Anaconda Python Distribution with Spyder as the integrated development environment (IDE). You can find the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":597,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[3],"tags":[79,78,26,35,40,80,81,43],"class_list":["post-555","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming","tag-21csl46","tag-cse","tag-foss","tag-lab-manual","tag-python","tag-python-programming-laboratory","tag-spyder","tag-vtu"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2023\/03\/pyth.jpg?fit=860%2C480&ssl=1","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/posts\/555","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/comments?post=555"}],"version-history":[{"count":40,"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/posts\/555\/revisions"}],"predecessor-version":[{"id":1302,"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/posts\/555\/revisions\/1302"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/media\/597"}],"wp:attachment":[{"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/media?parent=555"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/categories?post=555"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/tags?post=555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}