<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>For Loops on SourFox</title>
    <link>https://sourfox.khmersite.net/tags/for-loops/</link>
    <description>Recent content in For Loops on SourFox</description>
    <image>
      <title>SourFox</title>
      <url>https://sourfox.khmersite.net/papermod-cover.png</url>
      <link>https://sourfox.khmersite.net/papermod-cover.png</link>
    </image>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Tue, 28 Jan 2025 14:21:03 +1100</lastBuildDate>
    <atom:link href="https://sourfox.khmersite.net/tags/for-loops/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Binary to Decimal Updated</title>
      <link>https://sourfox.khmersite.net/p/2025/01/binary_to_decimal_updated/</link>
      <pubDate>Tue, 28 Jan 2025 14:21:03 +1100</pubDate>
      <guid>https://sourfox.khmersite.net/p/2025/01/binary_to_decimal_updated/</guid>
      <description>&lt;p&gt;In my other blog post &amp;lsquo;Binary to Decimal&amp;rsquo;, I realized what if I had put in a different number than 1 and 0. I tried putting a 2 and the code still worked. So I will be sharing an updated version, so that you can only put in either 1 or 0. Else there will be an error.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# make a new function&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;bintodeci&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;num&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;reverse&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;len&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;num&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;exp&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;total&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;index&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;range&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;reverse&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;c1&#34;&gt;# if each number is either 0 or 1 else it&amp;#39;ll print out an error.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;num&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;index&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;01&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;            &lt;span class=&#34;n&#34;&gt;total&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+=&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;int&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;num&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;index&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;])&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;**&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;exp&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;            &lt;span class=&#34;n&#34;&gt;exp&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;k&#34;&gt;else&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;            &lt;span class=&#34;nb&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;Error: Invalid binary number&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;            &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;None&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;            
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;c1&#34;&gt;# return the value&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;total&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# In case I want to import it&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;vm&#34;&gt;__name__&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;__main__&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;     &lt;span class=&#34;nb&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;sa&#34;&gt;f&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;The variable __name__ is &lt;/span&gt;&lt;span class=&#34;si&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;vm&#34;&gt;__name__&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;     &lt;span class=&#34;n&#34;&gt;answer&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;bintodeci&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;111&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;     &lt;span class=&#34;nb&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;answer&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    <item>
      <title>Binary to Decimal</title>
      <link>https://sourfox.khmersite.net/p/2025/01/binary_to_decimal/</link>
      <pubDate>Thu, 23 Jan 2025 20:33:23 +1100</pubDate>
      <guid>https://sourfox.khmersite.net/p/2025/01/binary_to_decimal/</guid>
      <description>&lt;p&gt;I&amp;rsquo;m sharing a program that converts binary to decimal in python.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;# make a new function
def bintodeci(num):
    reverse = len(num) -1
    exp = 0
    total = 0
    # range(start, stop, step)
    for digit in range(reverse, -1, -1):
        total += int(num[digit]) * (2**exp)
        exp += 1
    
    # return the value
    return total


answer = bintodeci(&amp;#34;11&amp;#34;)
print(answer)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;sample output:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;10
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;bai.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Create Restic Backup Program</title>
      <link>https://sourfox.khmersite.net/p/2024/12/create-restic-backup-program/</link>
      <pubDate>Mon, 30 Dec 2024 16:51:56 +1100</pubDate>
      <guid>https://sourfox.khmersite.net/p/2024/12/create-restic-backup-program/</guid>
      <description>&lt;p&gt;I&amp;rsquo;m sharing a wrapper program written in python to backup my files in my device using restic.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;import subprocess

restic_command = [&amp;#39;restic&amp;#39;, &amp;#39;backup&amp;#39;]

backup = [&amp;#34;C:\\Users\\veronica\\ibisPaint&amp;#34;, &amp;#34;C:\\Users\\veronica\\Pictures&amp;#34;, &amp;#34;C:\\Users\\veronica\\Documents&amp;#34;]

print(&amp;#34;List of directories to be backed up:\n&amp;#34; )

#list the files that will be backed up.
#enumerate = allows you to keep track of the number of iterations in a loop.
for number, dir in enumerate(backup, start=1):
    print(f&amp;#34;    {number}. {dir}&amp;#34;)
#  Or: print(&amp;#34;    &amp;#34; + str(number) + &amp;#34;.&amp;#34;, letter )

# \n makes a new line
print(&amp;#34;\nBackup process started...\n&amp;#34;)

# combines the lists together.
backup_command = restic_command + backup

restic = subprocess.run(backup_command, shell=True)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The end. -w-&lt;/p&gt;</description>
    </item>
    <item>
      <title>Atm Bill Dispenser</title>
      <link>https://sourfox.khmersite.net/p/2024/8/atm/</link>
      <pubDate>Fri, 09 Aug 2024 19:17:12 +1000</pubDate>
      <guid>https://sourfox.khmersite.net/p/2024/8/atm/</guid>
      <description>&lt;p&gt;Today, I was given an assignment to write a program to implement an atm dispenser in the following notes: 100, 50, 20, 10, and 5. If the amount is not a multiply of 5, the atm will return a list of 0.&lt;/p&gt;
&lt;p&gt;In the code are short explanations of why I used it.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;# asks the customer to enter an amount of number.
atm = int(input(&amp;#34;Enter an amount in a multiple of 5: &amp;#34;))

# This takes in a amount parameter which is the input  from the user and return an array of bills in the following orders: [$100, $50, $20, $10, $5]. 
def dispenser(amount):
    
    # if statement to check if number entered is divisible by 5. If not, return with 0, if yes, continue code.
    if atm % 5 != 0:
        return [0, 0, 0, 0, 0]
    
    result = []
    bill_types = [100, 50, 20, 10, 5]

# starts with the starting amount being divided by each number in bill_types.
    for each_note in bill_types:
        note_counts = amount // each_note
        result.append(note_counts)

        # get the remainder and overwrite the previous.
        amount = amount % each_note

    return result

# The code below is what will be given back as a sentence to the customer.
print(f&amp;#34;You entered ${atm}: {dispenser(atm)}&amp;#34;)
&lt;/code&gt;&lt;/pre&gt;</description>
    </item>
    <item>
      <title>Make a Frequency Dictionary From the Elements Of a List </title>
      <link>https://sourfox.khmersite.net/p/2024/2/assignment-8/</link>
      <pubDate>Sun, 25 Feb 2024 18:00:14 +1100</pubDate>
      <guid>https://sourfox.khmersite.net/p/2024/2/assignment-8/</guid>
      <description>&lt;p&gt;Halo! Today I have to make a python program that meets these conditions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Write a Python program that creates and print a dictionary that maps each element in a list to its corresponding frequency (how many times it occurs in the list).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The test should be case-sensitive. Therefore, “A” should not be considered the same element as “a”.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I think for today, I&amp;rsquo;m just going to make it short. Yea&amp;hellip;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Finding elements not in list</title>
      <link>https://sourfox.khmersite.net/p/2024/2/assignment-6/</link>
      <pubDate>Sun, 04 Feb 2024 21:14:07 +1100</pubDate>
      <guid>https://sourfox.khmersite.net/p/2024/2/assignment-6/</guid>
      <description>&lt;p&gt;Haloo people! How long has it been since I&amp;rsquo;ve done a blog post? Welp, I&amp;rsquo;ve finished my long break and now it&amp;rsquo;s time to get back to work. Today, I&amp;rsquo;ll be writing a python program that prints the elements of one list (a) that are not in the other list (b) as a list.&lt;/p&gt;
&lt;p&gt;My conditions are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;If the lists have the same elements, it will print an empty list.&lt;/li&gt;
&lt;li&gt;If the first list (a) is an empty list, it&amp;rsquo;ll print an empty list.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;An example -&lt;/p&gt;</description>
    </item>
    <item>
      <title>Assignment 5: Elements and Indices</title>
      <link>https://sourfox.khmersite.net/p/2023/11/assignment-5/</link>
      <pubDate>Sat, 11 Nov 2023 19:08:38 +1100</pubDate>
      <guid>https://sourfox.khmersite.net/p/2023/11/assignment-5/</guid>
      <description>&lt;p&gt;Today I had to do another assignment which is to create a python program which prints the elements of a list followed by their corresponding indices. Each element and its index must be on the same line seperated by a space. And if the list is empty, print &lt;strong&gt;&amp;ldquo;Empty List&amp;rdquo;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m going to make a list called num and put 1 to 4 inside.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;num = [1, 2, 3, 4]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then I&amp;rsquo;ll use the &lt;strong&gt;if&lt;/strong&gt; statement to do:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Assignment 3: Doubling </title>
      <link>https://sourfox.khmersite.net/p/2023/10/assignment-3/</link>
      <pubDate>Wed, 18 Oct 2023 18:59:17 +1100</pubDate>
      <guid>https://sourfox.khmersite.net/p/2023/10/assignment-3/</guid>
      <description>&lt;p&gt;Today, I was given another assignment. (Which I wasn&amp;rsquo;t expecting.) Today&amp;rsquo;s assignment was to write a python program which had to meet the conditions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Write a Python proram that multiplies all the items in a list by the value of the variable factor.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The program must print the list as the output.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The program should allow multiplying the variable factor by a string in case the list contains strings.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You may assume that the value of factor will be a positive integer.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Assignment 1: Using Length and String</title>
      <link>https://sourfox.khmersite.net/p/2023/10/assignment-1-using-length/</link>
      <pubDate>Sun, 15 Oct 2023 11:14:44 +1100</pubDate>
      <guid>https://sourfox.khmersite.net/p/2023/10/assignment-1-using-length/</guid>
      <description>&lt;p&gt;Today, I was given an assignment. My assignment wanted me to write a Python program that pints the length of a string.&lt;/p&gt;
&lt;p&gt;This is what I had to print out:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;The length of &amp;#34;&amp;#34; is 0.
The length of &amp;#34;H&amp;#34; is 1.
The length of &amp;#34;Hello&amp;#34; is 5.
The length of &amp;#34;Amazing&amp;#34; is 7.
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;To do this, I have a plan in my mind which is:&lt;/p&gt;
&lt;p&gt;Step 1. Find out what I&amp;rsquo;m going to use.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
