{"id":2827,"date":"2020-11-21T18:33:11","date_gmt":"2020-11-21T18:33:11","guid":{"rendered":"https:\/\/idiagress.com\/vinaaypatil\/?p=2827"},"modified":"2023-10-29T09:16:37","modified_gmt":"2023-10-29T09:16:37","slug":"1-8-comparing-lists-using-functions","status":"publish","type":"post","link":"https:\/\/idiagress.com\/vinaaypatil\/2020\/11\/21\/1-8-comparing-lists-using-functions\/","title":{"rendered":"1.8 Comparing Lists using Functions"},"content":{"rendered":"\n<p>Moving on from our exploration of quadratic equation roots, we are about to dive into another captivating realm of problem-solving. <\/p>\n\n\n\n<p>Yet, before we do, it&#8217;s essential to acknowledge a limitation in our bisection program. Our current implementation works well for cases with one positive and one negative root. <\/p>\n\n\n\n<p>However, it falls short when both roots share the same sign, be it positive or negative. To illustrate, let&#8217;s consider the equation (x+2)(x+5), which expands to x^2 + 7x + 10. In this scenario, the roots are x = -2 and x = -5, both negative. Unfortunately, our current program captures only one of these two roots.<\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/bisection_needs_improvements.png\"><img loading=\"lazy\" decoding=\"async\" width=\"360\" height=\"206\" src=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/bisection_needs_improvements-360x206.png\" alt=\"\" class=\"wp-image-2829\"\/><\/a><\/figure>\n<\/div>\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>From the Output, it is clear the program needs work. Maybe you can work and try to improve it.<\/p>\n\n\n\n<p>For now, let&#8217;s move to Factorization<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>A. Prime Factorization<\/strong><\/p>\n\n\n\n<p>In mathematics, factors of a number are those values that, when multiplied together, yield the original number. For instance, in the case of 24, we can express it as the product of 12 and 2. Here, 12 and 2 are factors of 24.<\/p>\n\n\n\n<p>Nonetheless, in mathematical pursuits, our primary concern lies in discerning the prime factors of a number. Prime factors are those indivisible components of a number that are prime themselves. For example, when we delve into the prime factors of 24, we can decompose it into 2, 2, 2, and 3\u2014a collection of purely prime factors.<\/p>\n\n\n\n<p>Let&#8217;s now delve into crafting an algorithm for the precise determination of these prime factors.<\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/factors_Algorithm_01.png\"><img loading=\"lazy\" decoding=\"async\" width=\"618\" height=\"815\" src=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/factors_Algorithm_01.png\" alt=\"\" class=\"wp-image-2830\" srcset=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/factors_Algorithm_01.png 618w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/factors_Algorithm_01-227x300.png 227w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/factors_Algorithm_01-254x335.png 254w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/factors_Algorithm_01-600x791.png 600w\" sizes=\"auto, (max-width: 618px) 100vw, 618px\" \/><\/a><\/figure>\n<\/div>\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"591\" height=\"817\" src=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/Factors_algorithm_02.png\" alt=\"\" class=\"wp-image-2831\" srcset=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/Factors_algorithm_02.png 591w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/Factors_algorithm_02-217x300.png 217w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/Factors_algorithm_02-242x335.png 242w\" sizes=\"auto, (max-width: 591px) 100vw, 591px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:25%\"><\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:50%\">\n<p>Here&#8217;s a step-by-step approach to finding the prime factors of a number:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Start with the number you want to find the prime factors of (let&#8217;s call it <code>n<\/code>).<\/li>\n\n\n\n<li>Initialize an empty list to store the prime factors.<\/li>\n\n\n\n<li>Begin with the smallest prime number, which is 2.<\/li>\n\n\n\n<li>Check if <code>n<\/code> is divisible by 2. If it is, add 2 to the list of prime factors and divide <code>n<\/code> by 2 repeatedly until it is no longer divisible by 2.<\/li>\n\n\n\n<li>Move on to the next prime number, which is 3, and check if <code>n<\/code> is divisible by 3. If it is, add 3 to the list of prime factors and divide <code>n<\/code> by 3 repeatedly until it is no longer divisible by 3.<\/li>\n\n\n\n<li>Continue this process, incrementing the prime number each time, and checking if <code>n<\/code> is divisible by the current prime number. If it is, add the prime factor to the list and divide <code>n<\/code> by that prime number as many times as possible.<\/li>\n\n\n\n<li>Repeat steps 4-6 until you have exhausted all prime numbers less than or equal to the square root of <code>n<\/code>. After this, if <code>n<\/code> is greater than 1, it means that <code>n<\/code> itself is a prime factor.<\/li>\n\n\n\n<li>You now have a list of prime factors that, when multiplied together, will give you the original number <code>n<\/code>.<\/li>\n<\/ol>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:25%\"><\/div>\n<\/div>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The fundamental idea behind prime factorization is to progress through the sequence of prime numbers (2, 3, 5, 7, 11, and so on) until the quotient becomes &#8216;1.&#8217;<\/p>\n\n\n\n<p>Now, you might wonder if it&#8217;s necessary to maintain a list of all prime numbers. <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">Interestingly, besides &#8216;2,&#8217; all prime numbers are &#8216;odd.&#8217; <\/mark><\/strong>Therefore, a more efficient approach is to simply advance through the list of odd numbers. This simplifies the programming.<\/p>\n\n\n\n<p>But what about factors that are &#8216;odd&#8217; yet not &#8216;prime&#8217;? For instance, consider 27, which can be expressed as 9 multiplied by 3. The factor &#8216;9&#8217; in this case is &#8216;not a prime&#8217; number. The primary goal, however, is to isolate prime numbers.<\/p>\n\n\n\n<p>Here&#8217;s a crucial point to grasp: By starting with a lower odd number (e.g., 3) and continually dividing until reaching a non-zero remainder, we effectively eliminate non-prime factors before encountering a non-prime number.<\/p>\n\n\n\n<p>To illustrate, let&#8217;s take the number 99 as an example. Our concern is the possibility of capturing a non-prime factor. In this instance, 99 can be factored into 9 and 11. But what if &#8216;9&#8217; is mistakenly identified as a factor?<\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/prime_factors_of_a_number.png\"><img loading=\"lazy\" decoding=\"async\" width=\"644\" height=\"485\" src=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/prime_factors_of_a_number.png\" alt=\"\" class=\"wp-image-2832\" srcset=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/prime_factors_of_a_number.png 644w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/prime_factors_of_a_number-300x226.png 300w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/prime_factors_of_a_number-335x252.png 335w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/prime_factors_of_a_number-600x452.png 600w\" sizes=\"auto, (max-width: 644px) 100vw, 644px\" \/><\/a><\/figure>\n<\/div>\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>We can see that the factor of &#8216;9&#8217; gets reduced before we reach &#8216;9&#8217; as a divisor. Thus, it does not get captured as a factor<\/p>\n\n\n\n<p>This greatly simplifies our program. We don&#8217;t need to maintain a list of prime numbers; we can move upwards without worrying about non-prime numbers getting captured as factors.<\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Flow of the program<\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\"><b>Step No<\/b><\/span><\/td><td>&nbsp;<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\"><b>Command<\/b><\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\"><b>Interpretation<\/b><\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\"><b>Paramater Value<\/b><\/span><\/td><\/tr><tr><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">1<\/span><\/td><td>&nbsp;<\/td><td><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">_number = <\/span><span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">int<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(<\/span><span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">input<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(<\/span><span style=\"color: #2aa198; font-family: Courier; font-size: medium;\">&#8220;Enter the number for factorization:\u201d<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">)) <\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">Ask user to input value of<span class=\"Apple-converted-space\">&nbsp; <\/span>number for factorization<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_number = 132<\/span><\/td><\/tr><tr><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">2<\/span><\/td><td>&nbsp;<\/td><td><span style=\"color: #859905; font-family: Courier; font-size: medium;\">while<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> _number % 2== <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">0<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">:<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">2 is a factor till remainder is zero<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">132 % 2 = 0<\/span> <p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">TRUE<\/mark><\/strong><\/span><\/p> <\/td><\/tr><tr><td>&nbsp;<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">2.L.1<\/span><\/td><td><span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">print<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(<\/span><span style=\"color: #2aa198; font-family: Courier; font-size: medium;\">\u201c2 is a factor\u201d<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">)<\/span><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>&nbsp;<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">2.L.2<\/span><\/td><td><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">_number = _number \/ 2<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">Get quotient<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_number = 132\/2<\/span>\n<p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_number = 66<\/span><\/p>\n<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td><span style=\"color: #859905; font-family: Courier; font-size: medium;\">while<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> _number % 2== <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">0<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">:<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">2 is a factor till remainder is zero<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">66 % 2 = 0<\/span> <p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">TRUE<\/mark><\/strong><\/span><\/p> <\/td><\/tr><tr><td>&nbsp;<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">2.L.1<\/span><\/td><td><span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">print<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(<\/span><span style=\"color: #2aa198; font-family: Courier; font-size: medium;\">\u201c2 is a factor\u201d<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">)<\/span><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>&nbsp;<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">2.L.2<\/span><\/td><td><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">_number = _number \/ 2<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">Get quotient<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_number = 66 \/2<\/span>\n<p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_number = 33<\/span><\/p>\n<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td><span style=\"color: #859905; font-family: Courier; font-size: medium;\">while<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> _number % 2== <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">0<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">:<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">2 is a factor till remainder is zero<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">33 % 2 = 0<\/span> <p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><strong>FALSE<\/strong><\/mark><\/span><\/p> <\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><strong>EXIT WHILE LOOP<\/strong><\/mark><\/span><\/td><td>&nbsp;<\/td><\/tr><tr><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">3<\/span><\/td><td>&nbsp;<\/td><td><span style=\"color: #859905; font-family: Courier; font-size: medium;\">for<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> _fac <\/span><span style=\"color: #859905; font-family: Courier; font-size: medium;\">in<\/span> <span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">range<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(<\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">3<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">, _number, <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">2<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">):<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">begin \u2018for\u2019 loop to scan for \u2018odd\u2019 factors <\/span><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\"><strong><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">NOTE: We are jumping range by &#8216;2&#8217;, which means we will go, 3, 5, 7, i.e ODD numbers<\/span>. <\/strong><\/mark><br><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_fac = 3<\/span>\n<p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_number = 33<\/span><\/p>\n<\/td><\/tr><tr><td>&nbsp;<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">3.L.1<\/span><\/td><td><span style=\"color: #859905; font-family: Courier; font-size: medium;\">while<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> _number % _fac== <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">0<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">:<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_fac is a factor till remainder is zero<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">33 % 3 = 0<\/span> <p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\"><strong>TRUE<\/strong><\/mark><\/span><\/p> <\/td><\/tr><tr><td>&nbsp;<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">3.L.2<\/span><\/td><td><span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">print<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(_fac, <\/span><span style=\"color: #2aa198; font-family: Courier; font-size: medium;\">\u201c is a factor\u201d<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">)<\/span><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>&nbsp;<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">3.L.3<\/span><\/td><td><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">_number = _number \/ _fac<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">Get quotient<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_number = 33 \/3<\/span>\n<p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_number = 11<\/span><\/p>\n<\/td><\/tr><tr><td>&nbsp;<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">3.L.1<\/span><\/td><td><span style=\"color: #859905; font-family: Courier; font-size: medium;\">while<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> _number % fac == <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">0<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">:<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_fac is a factor till remainder is zero<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">11 % 3 = 0<\/span> <p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">FALSE<\/mark><\/strong><\/span><\/p> <\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">EXIT WHILE LOOP<\/mark><\/strong><\/span><\/td><td>&nbsp;<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">_fac <\/span><span style=\"color: #859905; font-family: Courier; font-size: medium;\">in<\/span> <span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">range<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(<\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">3<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">, _number, <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">2<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">)<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_fac = _fac + 2<\/span>\n<p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">range increment<\/span><\/p>\n<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_fac = 3 + 2<\/span>\n<p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_fac = 5<\/span><\/p>\n<\/td><\/tr><tr><td>&nbsp;<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">3.L.1<\/span><\/td><td><span style=\"color: #859905; font-family: Courier; font-size: medium;\">while<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> _number % fac == <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">0<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">:<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_fac is a factor till remainder is zero<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">11 % 5 = 0<\/span> <p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">FALSE<\/mark><\/strong><\/span><\/p> <\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">EXIT WHILE LOOP<\/mark><\/strong><\/span><\/td><td>&nbsp;<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">_fac <\/span><span style=\"color: #859905; font-family: Courier; font-size: medium;\">in<\/span> <span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">range<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(<\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">3<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">, _number, <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">2<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">)<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_fac = _fac + 2<\/span>\n<p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">range increment<\/span><\/p>\n<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_fac = 5 + 2<\/span>\n<p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_fac = 7<\/span><\/p>\n<\/td><\/tr><tr><td>&nbsp;<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">3.L.1<\/span><\/td><td><span style=\"color: #859905; font-family: Courier; font-size: medium;\">while<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> _number % fac == <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">0<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">:<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_fac is a factor till remainder is zero<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">11 % 7 = 0<\/span> <p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">FALSE<\/mark><\/strong><\/span><\/p> <\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><strong>EXIT WHILE LOOP<\/strong><\/mark><\/span><\/td><td>&nbsp;<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">_fac <\/span><span style=\"color: #859905; font-family: Courier; font-size: medium;\">in<\/span> <span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">range<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(<\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">3<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">, _number, <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">2<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">)<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_fac = _fac + 2<\/span>\n<p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">range increment<\/span><\/p>\n<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_fac = 7 + 2<\/span>\n<p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_fac = 9<\/span><\/p>\n<\/td><\/tr><tr><td>&nbsp;<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">3.L.1<\/span><\/td><td><span style=\"color: #859905; font-family: Courier; font-size: medium;\">while<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> _number % fac == <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">0<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">:<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_fac is a factor till remainder is zero<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">11 % 9 = 0<\/span> <p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">FALSE<\/mark><\/strong><\/span><\/p> <\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">EXIT WHILE LOOP<\/mark><\/strong><\/span><\/td><td>&nbsp;<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">_fac <\/span><span style=\"color: #859905; font-family: Courier; font-size: medium;\">in<\/span> <span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">range<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(<\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">3<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">, _number, <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">2<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">)<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_fac = _fac + 2<\/span>\n<p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">range increment<\/span><\/p>\n<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_fac = 9 + 2<\/span>\n<p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_fac = 11<\/span><\/p>\n<\/td><\/tr><tr><td>&nbsp;<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">3.L.1<\/span><\/td><td><span style=\"color: #859905; font-family: Courier; font-size: medium;\">while<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> _number % _fac== <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">0<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">:<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_fac is a factor till remainder is zero<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">11 % 11 = 0<\/span>\n<p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">TRUE<\/span><\/p>\n<\/td><\/tr><tr><td>&nbsp;<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">3.L.2<\/span><\/td><td><span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">print<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(_fac, <\/span><span style=\"color: #2aa198; font-family: Courier; font-size: medium;\">\u201c is a factor\u201d<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">)<\/span><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>&nbsp;<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">3.L.3<\/span><\/td><td><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">_number = _number \/ _fac<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">Get quotient<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_number = 11 \/3<\/span>\n<p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_number = 1<\/span><\/p>\n<\/td><\/tr><tr><td>&nbsp;<\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">3.L.4<\/span><\/td><td><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">fac <\/span><span style=\"color: #859905; font-family: Courier; font-size: medium;\">in<\/span> <span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">range<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(<\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">3<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">, _number, <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">2<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">)<\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">FINISH program as _fac is beyond range<\/mark><\/strong><\/span><\/td><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">_fac &gt; _number<\/span>\n<p><span style=\"color: #000000; font-family: Avenir; font-size: medium;\">11 &gt; 1<\/span><\/p>\n<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Based on the above algorithm the program (basic_factors.py) is as follows:<span class=\"Apple-converted-space\">&nbsp;<\/span><\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\"><b>basic_factors.py<\/b><\/span><\/td><\/tr><tr><td><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">_number = <\/span><span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">int<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(<\/span><span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">input<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(<\/span><span style=\"color: #2aa198; font-family: Courier; font-size: medium;\">&#8220;Enter number for Factorization: &#8220;<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">))<br><span class=\"Apple-converted-space\">&nbsp; <\/span><br><\/span><span style=\"color: #859905; font-family: Courier; font-size: medium;\">while<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> _number % <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">2<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> == <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">0<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">:<br><span class=\"Apple-converted-space\">&nbsp; &nbsp; <\/span><\/span><span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">print<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(<\/span><span style=\"color: #2aa198; font-family: Courier; font-size: medium;\">&#8220;2 is a factor &#8220;<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">)<br><span class=\"Apple-converted-space\">&nbsp; &nbsp; <\/span>_number = _number \/<\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">2<br><\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"><span class=\"Apple-converted-space\">&nbsp;&nbsp; <\/span><br><\/span><span style=\"color: #859905; font-family: Courier; font-size: medium;\">for<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> _fac <\/span><span style=\"color: #859905; font-family: Courier; font-size: medium;\">in<\/span> <span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">range<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> (<\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">3<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">, _number, <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">2<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">):<br><span class=\"Apple-converted-space\">&nbsp; &nbsp; <\/span><\/span><span style=\"color: #859905; font-family: Courier; font-size: medium;\">while<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> _number % _fac ==<\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">0<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">:<br><span class=\"Apple-converted-space\">&nbsp; &nbsp; &nbsp; &nbsp; <\/span><\/span><span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">print<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(_fac, <\/span><span style=\"color: #2aa198; font-family: Courier; font-size: medium;\">&#8221; is a factor&#8221;<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">)<br><span class=\"Apple-converted-space\">&nbsp; &nbsp; &nbsp; &nbsp; <\/span>_number = _number\/ _fac <\/span><span style=\"color: #657b83; font-family: Courier; font-size: large;\"><br><\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The output of the program is as follows.<\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/float_error_output_basic_factors_python.png\"><img loading=\"lazy\" decoding=\"async\" width=\"956\" height=\"182\" src=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/float_error_output_basic_factors_python.png\" alt=\"\" class=\"wp-image-2833\" srcset=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/float_error_output_basic_factors_python.png 956w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/float_error_output_basic_factors_python-300x57.png 300w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/float_error_output_basic_factors_python-768x146.png 768w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/float_error_output_basic_factors_python-335x64.png 335w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/float_error_output_basic_factors_python-600x114.png 600w\" sizes=\"auto, (max-width: 956px) 100vw, 956px\" \/><\/a><\/figure>\n<\/div>\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The output successfully executes the code for the first &#8216;while&#8217; loop, identifying &#8216;2&#8217; as a factor. However, a challenge arises when the program enters the &#8216;for&#8217; loop, resulting in an error related to a &#8216;float&#8217; object.<\/p>\n\n\n\n<p><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">This issue stems from the fact that during the process of dividing a number, the data type can transition to &#8216;float.&#8217; For instance, when we execute the operation <code>_number = _number \/ 2<\/code>, <code>_number<\/code> becomes a &#8216;float&#8217; data type.<\/mark><\/strong><\/p>\n\n\n\n<p>The problem arises when we subsequently pass this variable, which is now a &#8216;float,&#8217; into the &#8216;range&#8217; function. <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">It&#8217;s crucial to note that the &#8216;range&#8217; function exclusively accepts &#8216;integer&#8217; variables<\/mark><\/strong>, and this discrepancy leads to the error..<\/p>\n\n\n\n<p>To circumvent this issue, we need to reconvert the variable back to an &#8216;integer&#8217; before using it in the &#8216;for&#8217; loop. We can achieve this by applying the following modification:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for _fac inrange (3, int(_number), 2):<\/code><\/pre>\n\n\n\n<p>This alteration ensures that the data type of <code>_number<\/code> remains as an &#8216;integer&#8217; within the &#8216;for&#8217; loop, preventing any &#8216;float&#8217; object errors. This refined approach maintains data type consistency and facilitates accurate prime factorization.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/corrected_output_basic_factors_python.png\"><img loading=\"lazy\" decoding=\"async\" width=\"558\" height=\"144\" src=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/corrected_output_basic_factors_python.png\" alt=\"\" class=\"wp-image-2834\" srcset=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/corrected_output_basic_factors_python.png 558w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/corrected_output_basic_factors_python-300x77.png 300w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/corrected_output_basic_factors_python-335x86.png 335w\" sizes=\"auto, (max-width: 558px) 100vw, 558px\" \/><\/a><\/figure>\n<\/div>\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><b>B. Comparison of Factors<\/b><\/h3>\n\n\n\n<p>In our existing program, we are proficient at identifying factors of a given number. However, what&#8217;s currently missing is the mechanism to store these factors. Since our objective is to collect all the factors in one organized place, the most practical approach is to employ a &#8216;list.&#8217;<\/p>\n\n\n\n<p>We can leverage the <code>append()<\/code> function to conveniently add identified factors to a list. To achieve this, we will encapsulate the steps for calculating factors within a dedicated function and return a list containing all the factors for a specified number.<\/p>\n\n\n\n<p>The program, titled &#8216;<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">list_factors.py<\/mark><\/strong>,&#8217; is structured as follows:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><span style=\"color: #000000; font-family: Avenir; font-size: medium;\"><b>list_factors.py<\/b><\/span><\/td><\/tr><tr><td><span style=\"color: #859905; font-family: Courier; font-size: medium;\">def<\/span> <span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">factorize_number<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(_number):<br><span class=\"Apple-converted-space\">&nbsp; &nbsp; <\/span><\/span><span style=\"color: #2aa198; font-family: Courier; font-size: medium;\">&#8220;&#8221;&#8221; function to calculate factors of a number &#8220;&#8221;&#8221;<br><\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"><span class=\"Apple-converted-space\">&nbsp; &nbsp; <\/span>_factors = []<br><span class=\"Apple-converted-space\">&nbsp;&nbsp; &nbsp; &nbsp; <\/span><br><span class=\"Apple-converted-space\">&nbsp; &nbsp; <\/span><\/span><span style=\"color: #859905; font-family: Courier; font-size: medium;\">while<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> _number % <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">2<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> == <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">0<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">:<br><span class=\"Apple-converted-space\">&nbsp; &nbsp; &nbsp; &nbsp; <\/span>_factors.<\/span><span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">append<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(<\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">2<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">)<br><span class=\"Apple-converted-space\">&nbsp; &nbsp; &nbsp; &nbsp; <\/span>_number = _number\/<\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">2<br><\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"><span class=\"Apple-converted-space\">&nbsp;&nbsp; &nbsp; <\/span><br><span class=\"Apple-converted-space\">&nbsp; &nbsp; <\/span><\/span><span style=\"color: #859905; font-family: Courier; font-size: medium;\">for<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> _fac <\/span><span style=\"color: #859905; font-family: Courier; font-size: medium;\">in<\/span> <span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">range<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(<\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">3<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">, <\/span><span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">int<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(_number), <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">2<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">):<br><span class=\"Apple-converted-space\">&nbsp; &nbsp; &nbsp; &nbsp; <\/span><\/span><span style=\"color: #859905; font-family: Courier; font-size: medium;\">while<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> _number % _fac == <\/span><span style=\"color: #d33682; font-family: Courier; font-size: medium;\">0<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">:<br><span class=\"Apple-converted-space\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <\/span>_factors.<\/span><span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">append<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(_fac)<br><span class=\"Apple-converted-space\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <\/span>_number = _number\/_fac<br><span class=\"Apple-converted-space\">&nbsp;&nbsp; &nbsp; <\/span><br><span class=\"Apple-converted-space\">&nbsp; &nbsp; <\/span><\/span><span style=\"color: #859905; font-family: Courier; font-size: medium;\">return<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> _factors<br><span class=\"Apple-converted-space\">&nbsp;&nbsp; <\/span><br><span class=\"Apple-converted-space\">&nbsp;&nbsp; <\/span><br>_a = <\/span><span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">int<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(<\/span><span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">input<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(<\/span><span style=\"color: #2aa198; font-family: Courier; font-size: medium;\">&#8220;Enter number for Factorization: &#8220;<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">))<br>_factors_a = <\/span><span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">factorize_number<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(_a)<br><span class=\"Apple-converted-space\">&nbsp;&nbsp; <\/span><br><\/span><span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">print<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(<\/span><span style=\"color: #2aa198; font-family: Courier; font-size: medium;\">&#8220;The factors of &#8220;<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">, _a, <\/span><span style=\"color: #2aa198; font-family: Courier; font-size: medium;\">&#8221; are &#8220;<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">, _factors_a)<br><\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>We&#8217;ve carried out a straightforward replacement in the code. Wherever in our previous program, there was a <code>print(\"is a factor\")<\/code>, we&#8217;ve replaced it with <code>_factors.append<\/code> to add the identified factor to a list. The result is a neatly organized list of factors.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/list_factors_output_python.png\"><img loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"96\" src=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/list_factors_output_python.png\" alt=\"\" class=\"wp-image-2835\" srcset=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/list_factors_output_python.png 525w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/list_factors_output_python-300x55.png 300w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/list_factors_output_python-335x61.png 335w\" sizes=\"auto, (max-width: 525px) 100vw, 525px\" \/><\/a><\/figure>\n<\/div>\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>The next part will be to factorize two numbers, so that we can calculate the H.C.F. (Highest Common Factor).<\/p>\n\n\n\n<p>Let\u2019s see a sample HCF calculation.<\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Calculate HCF of the numbers 60 and 82<\/p>\n\n\n\n<p>Factors of 60 &nbsp; &nbsp; &nbsp;are &nbsp; &nbsp; [ 2 , 2 , 3 , 5 ]<\/p>\n\n\n\n<p>Factors of 84 &nbsp; &nbsp; &nbsp;are &nbsp; &nbsp; [ 2 , 2,<span class=\"Apple-converted-space\">&nbsp; <\/span>3 , 7 ]<\/p>\n\n\n\n<p>Comparing the factors and highlighting common factors<\/p>\n\n\n\n<p>[ <strong><span style=\"color: #800000;\">2, 2, 3<\/span> <\/strong>, 5 ] <span class=\"Apple-converted-space\">&nbsp; &nbsp; <\/span>[ <strong><span style=\"color: #800000;\">2, 2, 3<\/span><\/strong> , 7 ]<\/p>\n\n\n\n<p>Common factors &nbsp; &nbsp; are &nbsp; &nbsp; [ 2 , 2 , 3 ]<\/p>\n\n\n\n<p>HCF is multiplication of common factors &nbsp; &nbsp; = 2 \u2022 2 \u2022 3 &nbsp; &nbsp; &nbsp;= 12<\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Our program excels at calculating the factors and storing them in a list. The next essential task is to compare these two lists and construct a new list comprising all the common factors.<\/p>\n\n\n\n<p>To accomplish this comparison, we iterate through the elements of list A and, for each element, check against every other element in list B. If two elements match, we add that element to a common list and ensure it isn&#8217;t considered again in subsequent comparisons. The logic for this comparison can be expressed  as follows:<\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td><span style=\"color: #000000; font-family: Times; font-size: medium;\"><b>For every <span class=\"Apple-converted-space\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<\/span><\/b><\/span><\/td><td><span style=\"color: #000000; font-family: Times; font-size: medium;\"><b>element <\/b><\/span><\/td><td><span style=\"color: #000000; font-family: Times; font-size: medium;\"><b>in <\/b><\/span><\/td><td><span style=\"color: #000000; font-family: Times; font-size: medium;\"><b>list A,<span class=\"Apple-converted-space\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<\/span><\/b><\/span><\/td><\/tr><tr><td><span style=\"color: #000000; font-family: Times; font-size: medium;\"><b>we want to check every<\/b><\/span><\/td><td><span style=\"color: #000000; font-family: Times; font-size: medium;\"><b>other element <\/b><\/span><\/td><td><span style=\"color: #000000; font-family: Times; font-size: medium;\"><b>in<\/b><\/span><\/td><td><span style=\"color: #000000; font-family: Times; font-size: medium;\"><b>list B,<\/b><\/span><\/td><\/tr><tr><td><span style=\"color: #000000; font-family: Times; font-size: medium;\"><b>and<\/b><\/span><\/td><td><span style=\"color: #000000; font-family: Times; font-size: medium;\"><b>if the two elements are equal<\/b><\/span><\/td><td><span style=\"color: #000000; font-family: Times; font-size: medium;\"><b>add element in <\/b><\/span><\/td><td><span style=\"color: #000000; font-family: Times; font-size: medium;\"><b>a <span class=\"Apple-converted-space\">&nbsp; &nbsp; <\/span>Common list<\/b><\/span><\/td><\/tr><tr><td><span style=\"color: #000000; font-family: Times; font-size: medium;\"><b>Plus,<\/b><\/span><\/td><td><span style=\"color: #000000; font-family: Times; font-size: medium;\"><b>Don\u2019t consider the element again <\/b><\/span><\/td><td><span style=\"color: #000000; font-family: Times; font-size: medium;\"><b>in the<\/b><\/span><\/td><td><span style=\"color: #000000; font-family: Times; font-size: medium;\"><b>next comparison<\/b><\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Code wise we can write the logic as:<\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><span style=\"color: #000000; font-family: Avenir; font-size: small;\"><b>Appending function for Factors<\/b><\/span><\/td><\/tr><tr><td><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"><span class=\"Apple-converted-space\">&nbsp;&nbsp; <\/span><\/span><span style=\"color: #859905; font-family: Courier; font-size: medium;\">for<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> element <\/span><span style=\"color: #859905; font-family: Courier; font-size: medium;\">in<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> _fa:<br><span class=\"Apple-converted-space\">&nbsp; &nbsp; &nbsp; &nbsp; <\/span><\/span><span style=\"color: #859905; font-family: Courier; font-size: medium;\">for<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> other_element <\/span><span style=\"color: #859905; font-family: Courier; font-size: medium;\">in<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> _fb:<br><span class=\"Apple-converted-space\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <\/span><\/span><span style=\"color: #859905; font-family: Courier; font-size: medium;\">if<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> element == other_element:<br><span class=\"Apple-converted-space\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <\/span>_common.<\/span><span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">append<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(element)<br><span class=\"Apple-converted-space\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <\/span>_fb.<\/span><span style=\"color: #268bd2; font-family: Courier; font-size: medium;\">remove<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\">(other_element)<br><span class=\"Apple-converted-space\">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <\/span><br><span class=\"Apple-converted-space\">&nbsp;&nbsp; <\/span><\/span><span style=\"color: #859905; font-family: Courier; font-size: medium;\">return<\/span><span style=\"color: #657b83; font-family: Courier; font-size: medium;\"> _common<\/span><span style=\"color: #657b83; font-family: Courier; font-size: small;\"><br><span class=\"Apple-converted-space\">&nbsp;&nbsp;<\/span><\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>We now need to code the above code for comparison as a function defined to compare two lists.<\/p>\n\n\n\n<p>The program (hcf.py) is as follows.<span class=\"Apple-converted-space\">&nbsp;<\/span><\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/factors_compare_python_1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"541\" height=\"643\" src=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/factors_compare_python_1.png\" alt=\"\" class=\"wp-image-2837\" srcset=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/factors_compare_python_1.png 541w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/factors_compare_python_1-252x300.png 252w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/factors_compare_python_1-282x335.png 282w\" sizes=\"auto, (max-width: 541px) 100vw, 541px\" \/><\/a><\/figure>\n<\/div>\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/factors_compare_python_2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"587\" height=\"362\" src=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/factors_compare_python_2.png\" alt=\"\" class=\"wp-image-2838\" srcset=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/factors_compare_python_2.png 587w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/factors_compare_python_2-300x185.png 300w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/factors_compare_python_2-335x207.png 335w\" sizes=\"auto, (max-width: 587px) 100vw, 587px\" \/><\/a><\/figure>\n<\/div>\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The output is<\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/list_factors_output_python-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"96\" src=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/list_factors_output_python-1.png\" alt=\"\" class=\"wp-image-2836\" srcset=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/list_factors_output_python-1.png 525w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/list_factors_output_python-1-300x55.png 300w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/list_factors_output_python-1-335x61.png 335w\" sizes=\"auto, (max-width: 525px) 100vw, 525px\" \/><\/a><\/figure>\n<\/div>\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><b>C. Immutable and Mutable<span class=\"Apple-converted-space\">&nbsp;<\/span><\/b><\/h2>\n\n\n\n<p>Before we delve into our program and calculate the HCF by multiplying the common factors, it&#8217;s crucial to grasp a fundamental concept about lists and other data types: the distinction between mutable and immutable objects. To gain a clearer understanding, you can run your program in Thonny or insert print commands in the Atom file to examine the final values of variables.<\/p>\n\n\n\n<p>If you scrutinize the final values of variables, you&#8217;ll observe that the list <code>_factors_b<\/code> has been modified from <code>[2, 2, 3, 7]<\/code> to <code>[7]<\/code>. This modification takes place even after we saved <code>_factors_b<\/code> in <code>_fb<\/code> before passing the lists into the functions. Both lists are being altered within the function.<\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/variables_in_common_factors.png\"><img loading=\"lazy\" decoding=\"async\" width=\"287\" height=\"193\" src=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/variables_in_common_factors.png\" alt=\"\" class=\"wp-image-2839\"\/><\/a><\/figure>\n<\/div>\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>This behavior can be attributed to the fact that, in Python, everything is an object, and objects are categorized into two groups: mutable and immutable.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Mutable Objects<\/strong>: These are objects whose values can change. When you modify a mutable object, it alters the object itself. Lists and dictionaries are examples of mutable objects.<\/li>\n<\/ul>\n\n\n\n<p>For instance, if you have a list <code>_a = [2, 3, 5, 7, 11]<\/code> and another list <code>_b = _a<\/code>, both <code>_a<\/code> and <code>_b<\/code> point to the same object in memory. Modifying one list will affect the other because they share the same object.<\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Immutable Objects<\/strong>: These are objects whose values do not change once they are created. Numbers and strings are examples of immutable objects.<\/li>\n<\/ul>\n\n\n\n<p>For instance, if you have an integer <code>a = 5<\/code> and another integer <code>b = a<\/code>, both <code>a<\/code> and <code>b<\/code> are distinct objects with the same value. Modifying one will not affect the other.<\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>In the context of our program, when we copied <code>_factors_b<\/code> to <code>_fb<\/code>, both variables were essentially referencing the same list object, which is why modifications to one list were reflected in the other.<\/p>\n\n\n\n<p>On the other hand, for mutable objects, the object&#8217;s name points to an address in memory. Thus when we copy an immutable object, we do not create a new object. We simply create another name that points to the same address. Thus, change one, and the copy also changes. Lists and Dictionaries are mutable.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>To resolve this, we can use the <code>copy()<\/code> function when duplicating lists. This function creates a distinct copy of the list, ensuring that changes made to one list do not impact the other.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> Instead of  <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><span style=\"font-family: inherit; font-size: inherit;\">_fa = _factors_a<\/span>,<\/mark> \nwe can use <code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">_fa = _factors_a.copy()<\/mark><\/code> <\/code><\/pre>\n\n\n\n<p>This creates an independent copy of the list.<\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>In addition to this modification, we&#8217;ll also add another function to multiply the factors and obtain the HCF in the program (hcf_final.py).<\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/hcf_final_01.png\"><img loading=\"lazy\" decoding=\"async\" width=\"614\" height=\"638\" src=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/hcf_final_01.png\" alt=\"\" class=\"wp-image-2840\" srcset=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/hcf_final_01.png 614w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/hcf_final_01-289x300.png 289w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/hcf_final_01-322x335.png 322w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/hcf_final_01-600x623.png 600w\" sizes=\"auto, (max-width: 614px) 100vw, 614px\" \/><\/a><\/figure>\n<\/div>\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/hcf_final_2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"609\" height=\"624\" src=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/hcf_final_2.png\" alt=\"\" class=\"wp-image-2841\" srcset=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/hcf_final_2.png 609w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/hcf_final_2-293x300.png 293w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/hcf_final_2-327x335.png 327w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/hcf_final_2-600x615.png 600w\" sizes=\"auto, (max-width: 609px) 100vw, 609px\" \/><\/a><\/figure>\n<\/div>\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The output is as follows <span class=\"Apple-converted-space\">&nbsp;<\/span><\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/output_hcf_final.png\"><img loading=\"lazy\" decoding=\"async\" width=\"519\" height=\"172\" src=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/output_hcf_final.png\" alt=\"\" class=\"wp-image-2842\" srcset=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/output_hcf_final.png 519w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/output_hcf_final-300x99.png 300w, https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/output_hcf_final-335x111.png 335w\" sizes=\"auto, (max-width: 519px) 100vw, 519px\" \/><\/a><\/figure>\n<\/div>\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>And when we check out the variables, we see that the original lists are preserved.<\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/variables_hcf_final.png\"><img loading=\"lazy\" decoding=\"async\" width=\"271\" height=\"209\" src=\"https:\/\/idiagress.com\/vinaaypatil\/wp-content\/uploads\/2020\/11\/variables_hcf_final.png\" alt=\"\" class=\"wp-image-2843\"\/><\/a><\/figure>\n<\/div>\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Now, here comes a pivotal question: Is it truly necessary to preserve these lists of factors? In this case, the resounding answer is &#8220;Yes!&#8221;<\/p>\n\n\n\n<p>This necessity becomes evident when you consider the typical progression in mathematical problem-solving. After calculating the Highest Common Factor (HCF), the subsequent task often revolves around determining the Least Common Multiple (LCM). The LCM is, essentially, the result of multiplying the common factors with the non-common factors.<\/p>\n\n\n\n<p>Mathematically speaking, the LCM is defined as:<\/p>\n\n\n\n<p>LCM = Common Factors \u2022 Non-common Factors<\/p>\n\n\n\n<p>Hence, to accurately calculate the LCM, you must have access to the original factor lists once again. These lists are indispensable for distinguishing between the common and non-common factors, a critical step in finding the LCM.<\/p>\n\n\n\n<p><strong>As an exercise create a program to calculate LCM<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Summary<\/h3>\n\n\n\n<p>we have explored the process of factorization, which involves breaking down a number into its prime factors. This process is essential for various mathematical calculations, including finding the Highest Common Factor (HCF) and the Least Common Multiple (LCM) of numbers.<\/p>\n\n\n\n<p>Here&#8217;s a summary of the key points covered in this chapter:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Factorization<\/strong>: Factorization is the process of breaking a number down into its prime factors, which are the indivisible components of the number.<\/li>\n\n\n\n<li><strong>Prime Factors<\/strong>: Prime factors are prime numbers that multiply to form the original number. They are crucial for various mathematical calculations.<\/li>\n\n\n\n<li><strong>Algorithm for Finding Prime Factors<\/strong>: We discussed an algorithm for finding the prime factors of a number, which involves iterating through prime numbers and dividing the number until it becomes 1.<\/li>\n\n\n\n<li><strong>Storing Factors in Lists<\/strong>: We learned how to store the identified factors in lists for easy access and further calculations.<\/li>\n\n\n\n<li><strong>Mutable and Immutable Objects<\/strong>: Understanding the concept of mutable and immutable objects is vital. Immutable objects, like numbers and strings, retain their values when copied, while mutable objects, like lists, can change when copied.<\/li>\n\n\n\n<li><strong>Preserving Lists<\/strong>: We emphasized the importance of preserving the original lists of factors, especially when calculating the LCM, which depends on both common and non-common factors.<\/li>\n<\/ol>\n\n\n\n<p>Overall, this chapter has laid the foundation for efficient mathematical problem-solving by providing tools and insights into factorization, the use of lists, and the significance of distinguishing between mutable and immutable objects in Python.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><a class='vw-button vw-button--purple ' href='https:\/\/idiagress.com\/vinaaypatil\/2020\/09\/28\/1-7-user-defined-functions-in-python\/' target='_self'>Prev Chapter<\/a> &nbsp; <a class='vw-button vw-button-- ' href='https:\/\/idiagress.com\/vinaaypatil\/first-steps-in-python\/' target='_self'>Course Homepage<\/a> &nbsp; &nbsp;<a class='vw-button vw-button--pink  vw-button--arrow' href='https:\/\/idiagress.com\/vinaaypatil\/2020\/11\/25\/1-9-testing-code-importing-and-exporting-from-python\/' target='_self'>Next Chapter<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Moving on from our exploration of quadratic equation roots, we are about to dive into another captivating realm of problem-solving. Yet, before we do, it&#8217;s essential to acknowledge a limitation in our bisection program. Our current implementation works well for cases with one positive and one negative root. However, it falls short when both roots &#8230;<\/p>\n","protected":false},"author":2,"featured_media":2828,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[412],"tags":[439,407,416,413,394],"class_list":["post-2827","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-first-steps-in-python","tag-factorization-using-python","tag-floats-in-python","tag-functions-in-python","tag-lists-in-python","tag-python"],"_links":{"self":[{"href":"https:\/\/idiagress.com\/vinaaypatil\/wp-json\/wp\/v2\/posts\/2827","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idiagress.com\/vinaaypatil\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idiagress.com\/vinaaypatil\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idiagress.com\/vinaaypatil\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/idiagress.com\/vinaaypatil\/wp-json\/wp\/v2\/comments?post=2827"}],"version-history":[{"count":4,"href":"https:\/\/idiagress.com\/vinaaypatil\/wp-json\/wp\/v2\/posts\/2827\/revisions"}],"predecessor-version":[{"id":3844,"href":"https:\/\/idiagress.com\/vinaaypatil\/wp-json\/wp\/v2\/posts\/2827\/revisions\/3844"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idiagress.com\/vinaaypatil\/wp-json\/wp\/v2\/media\/2828"}],"wp:attachment":[{"href":"https:\/\/idiagress.com\/vinaaypatil\/wp-json\/wp\/v2\/media?parent=2827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idiagress.com\/vinaaypatil\/wp-json\/wp\/v2\/categories?post=2827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idiagress.com\/vinaaypatil\/wp-json\/wp\/v2\/tags?post=2827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}