<?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>If Statement on SourFox</title>
    <link>https://sourfox.khmersite.net/tags/if-statement/</link>
    <description>Recent content in If Statement 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>Fri, 09 Aug 2024 19:17:12 +1000</lastBuildDate>
    <atom:link href="https://sourfox.khmersite.net/tags/if-statement/index.xml" rel="self" type="application/rss+xml" />
    <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>Finding the GCD of two numbers</title>
      <link>https://sourfox.khmersite.net/p/2024/7/assignment_gcd/</link>
      <pubDate>Fri, 12 Jul 2024 12:43:30 +1000</pubDate>
      <guid>https://sourfox.khmersite.net/p/2024/7/assignment_gcd/</guid>
      <description>&lt;p&gt;In this assignment, it&amp;rsquo;ll be finding the GCD(Greatest Common Divisor). This means I need to write a program to find the GCD of two numbers. Below, I have written the program and next to the hashtags are just a sentence that&amp;rsquo;ll explain to you what each part of the code is doing.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;#The two variables &amp;#39;num&amp;#39; and &amp;#39;ber&amp;#39; will be where the inputs will be stored in. When it starts it will show &amp;#39;(num)a: &amp;#39; and you&amp;#39;ll have to put a number in. This goes the same for &amp;#39;(ber)b: &amp;#39;

num = int(input(&amp;#34;a: &amp;#34;))
ber = int(input(&amp;#34;b: &amp;#34;))

#Then once the variable has gotten their information, they will go through this: 

def gcd(num, ber):
    if ber == 0:
        return num
    else:
        return gcd(ber, num % ber)
    
#And last, it&amp;#39;ll gather their answer and print it for you as a sentence.

print(f&amp;#34;The GCD {num}, {ber} is {gcd(num, ber)}.&amp;#34;)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;That&amp;rsquo;s all today. Bye!&lt;/p&gt;</description>
    </item>
    <item>
      <title>Check if a year is a leap year</title>
      <link>https://sourfox.khmersite.net/p/2024/5/assignment_9/</link>
      <pubDate>Tue, 14 May 2024 17:43:09 +1000</pubDate>
      <guid>https://sourfox.khmersite.net/p/2024/5/assignment_9/</guid>
      <description>&lt;p&gt;Today, I just got back to python after a few months. So when coming back, I got an assignment. My assignment was to &lt;em&gt;check if a year is a leap year.&lt;/em&gt; In the assignment, it also gave hints. These were the hints:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;A leap year is a calendar year that contains an additional day (February 29th) compared to a common year. It occurs once every four year.
s
&lt;strong&gt;This is how you can determine if a year is a leap year or not:&lt;/strong&gt;&lt;/p&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 the Second Largest Value in a List</title>
      <link>https://sourfox.khmersite.net/p/2024/2/assignment-7/</link>
      <pubDate>Sat, 10 Feb 2024 19:35:52 +1100</pubDate>
      <guid>https://sourfox.khmersite.net/p/2024/2/assignment-7/</guid>
      <description>&lt;p&gt;Halooo! Today I&amp;rsquo;ll be teaching you how to find the second largest value in a list. The conditions -&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Write a Python program that prints the second largest value in a list.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If the list is empty or only has one element, print None.SSS&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;To do this, we&amp;rsquo;ll have to make a list and then sort it and then we use the if statement and else.&lt;/p&gt;
&lt;p&gt;Input:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;lista = [1, 4, 8, 9, 100, 200, 30]
lista.sort()

if len(lista) &amp;gt; 1:
    print(lista[-2])
else:
    print(&amp;#34;None&amp;#34;)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Output -&lt;/p&gt;</description>
    </item>
    <item>
      <title>Bonus assignment: Challenge Add a Key-Value Pair Only if the Key is Not in the Dictionary </title>
      <link>https://sourfox.khmersite.net/p/2023/11/dictionary/</link>
      <pubDate>Sat, 18 Nov 2023 18:51:34 +1100</pubDate>
      <guid>https://sourfox.khmersite.net/p/2023/11/dictionary/</guid>
      <description>&lt;p&gt;Today I was very bored so I checked my bonus assignments and I got this.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Write a Python program that adds a new key-value pair to a dictionary only if the key doesn&amp;rsquo;t exist already.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If the key-value pair exists in the dictionary, do not update the existing value. The dictionary should not be modified in this case.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Store the new key in the new_key variable and the new value in the new_value variable.
Print the final value of the dictionary.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Check if a Key Is in a Dictionary</title>
      <link>https://sourfox.khmersite.net/p/2023/11/check-if-a-key-is-in-a-dictionary/</link>
      <pubDate>Wed, 15 Nov 2023 20:31:21 +1100</pubDate>
      <guid>https://sourfox.khmersite.net/p/2023/11/check-if-a-key-is-in-a-dictionary/</guid>
      <description>&lt;p&gt;&lt;em&gt;The next one I&amp;rsquo;ll actually explain thoroughly.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;So I had enough time to make another program. This time I had to meet the condtitions:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Write a Python program that checks if a key exists in a dictionary or not.
 
If the key exists in the dictionary, print True. Else, print False.

The key should be stored in the variable key.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here is how I did it:&lt;/p&gt;
&lt;p&gt;Input:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;dict = {&amp;#34;toy&amp;#34;: &amp;#34;dino&amp;#34;, &amp;#34;sport&amp;#34;: &amp;#34;soccer&amp;#34;, &amp;#34;food&amp;#34;: &amp;#34;ramen&amp;#34;}
key = &amp;#34;toy&amp;#34;
if key in dict:
    print(True)
else:
    print(False)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Output:&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 4: Checking if a list is empty</title>
      <link>https://sourfox.khmersite.net/p/2023/10/assignment-4/</link>
      <pubDate>Sun, 29 Oct 2023 18:42:54 +1100</pubDate>
      <guid>https://sourfox.khmersite.net/p/2023/10/assignment-4/</guid>
      <description>&lt;p&gt;I was given an assignment for the fourth time. My goal was to write a python program that checks if a list is empty or not. If the list is empty, then it&amp;rsquo;ll print &lt;strong&gt;empty&lt;/strong&gt;, if not, it&amp;rsquo;ll print &lt;strong&gt;not empty&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m going to start with an empty list.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;emp = []
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So that I can start the next step. I&amp;rsquo;m going to use&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;if statement&lt;/li&gt;
&lt;li&gt;len()&lt;/li&gt;
&lt;li&gt;else&lt;/li&gt;
&lt;li&gt;print()&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;When using if, there must be a condition met. My condition is:&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
