<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Elijah Macharia</title>
    <description>The latest articles on Forem by Elijah Macharia (@elijahmacharia).</description>
    <link>https://forem.com/elijahmacharia</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1016528%2F24525804-5cc8-406e-937a-c777d986ff4f.jpeg</url>
      <title>Forem: Elijah Macharia</title>
      <link>https://forem.com/elijahmacharia</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/elijahmacharia"/>
    <language>en</language>
    <item>
      <title>Looping in Python</title>
      <dc:creator>Elijah Macharia</dc:creator>
      <pubDate>Wed, 22 Feb 2023 09:13:29 +0000</pubDate>
      <link>https://forem.com/elijahmacharia/looping-in-python-3i0n</link>
      <guid>https://forem.com/elijahmacharia/looping-in-python-3i0n</guid>
      <description>&lt;h1&gt;
  
  
  Introduction to loops.
&lt;/h1&gt;

&lt;p&gt;A loop is a series of commands that repeat continuously until a certain condition is reached. This allows you to continuously run the same code multiple times or repeat a subroutine until a stopping condition is met.&lt;/p&gt;

&lt;p&gt;loops come in many different types, and each programming language has its own syntax.&lt;br&gt;
The&lt;br&gt;
loops have one thing in common.&lt;/p&gt;

&lt;p&gt;Stop condition. This condition is checked each time and the loop continues running until the condition is reached.&lt;br&gt;
Python has two types of loops.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The For Loop
is used to determine how many times you want to repeat a block of code. It is used to perform certain actions a certain number of times.&lt;/li&gt;
&lt;/ol&gt;
&lt;h6&gt;
  
  
  Example
&lt;/h6&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fruits = ["Apples", "Oranges", "Banana"]
for i in fruits:
    print(i)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; 'i' is a variable assigned to Fruits.&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Apples
Oranges 
Banana
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  2.While Loop
&lt;/h5&gt;

&lt;p&gt;A while loop is a type of loop in Python that allows you to repeat a block of code until a certain condition is met. The syntax for a while loop is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while condition:
    # do something
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this syntax, a "condition" is a boolean expression that is evaluated on each iteration of the loop. If the condition is true, the loop body is executed. If the condition is false, the loop ends and the program moves to the next line of code.&lt;/p&gt;

&lt;p&gt;The body of the while loop can contain any number of statements, just like any other block of code. This can include conditional statements, function calls, I/O operations, and other types of statements for use in Python code.&lt;br&gt;
One important thing to keep in mind when using a while loop is that the condition must eventually be false. Otherwise the loop will continue indefinitely and the program will crash. This is called an infinite loop and is generally considered a bug in the code.&lt;/p&gt;

&lt;p&gt;Here is an example of a while loop that repeatedly prompts the user for input until input is complete.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user_input = ""
while user_input != "quit":
    user_input = input("Enter a word (or 'quit' to exit): ")
    print("You entered:", user_input)
print("Goodbye!")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the while loop continues prompting the user for input until input is complete. As soon as the input becomes "exit", the loop exits and the message "Goodbye!" appears. It prints to the console.&lt;/p&gt;

&lt;p&gt;The While Loop is a powerful tool in Python programming that allows you to write more flexible and dynamic code. It can be used in a variety of applications, from processing user input to game loops and simulation programs.&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
    </item>
    <item>
      <title>Basics Of Python Language</title>
      <dc:creator>Elijah Macharia</dc:creator>
      <pubDate>Sat, 11 Feb 2023 11:25:05 +0000</pubDate>
      <link>https://forem.com/elijahmacharia/basics-of-python-language-11d2</link>
      <guid>https://forem.com/elijahmacharia/basics-of-python-language-11d2</guid>
      <description>&lt;h1&gt;
  
  
  INTRODUCTION TO PYTHON PROGRAMMING
&lt;/h1&gt;

&lt;p&gt;Python is a high-level-programming language. By high-level-programming language, it means that python is easy to understand. It has been used over many decades and it is considered to be the best and also easy to understand language as compared to other languages. It is also used by big tech companies and also small and medium-sized companies to perform this such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Web development &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Software Development&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mathematics&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;System Scripting&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Python Install
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Windows Install&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Maneuver to your windows and search for &lt;strong&gt;Command Prompt&lt;/strong&gt; and press enter. Later type this code &lt;code&gt;python --version&lt;/code&gt; and see if you have python installed in your system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Linux and Mac Install&lt;/strong&gt;&lt;br&gt;
In both Linux and Mac operating system, Python is already installed directly.&lt;/p&gt;
&lt;h1&gt;
  
  
  Python Syntax
&lt;/h1&gt;

&lt;p&gt;Syntax simply refers to a set of instructions that a computer is given to generate an output. Failure to do so your program may run in errors instead. It is advisable to follow them so that you do not spend more time than expected on your code. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Indentation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Indentation refers to putting the a appropriate 'punctuation marks' so that your code does not run in errors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
The correct syntax for indenting an if...else statement in python is;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 10 
b = 22
if a &amp;gt; b:
 print(" This is Correct")
else:
 print("This is Incorrect")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The addition of &lt;code&gt;:&lt;/code&gt; in the code after declaring it, it must be there, or else you may run into an error called a &lt;em&gt;syntax error&lt;/em&gt;. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The spacing before the print statement should be there in order for us not to get a &lt;em&gt;syntax error&lt;/em&gt;. Any spacing &amp;gt; 1 is accepted. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The 'p' in &lt;code&gt;print()&lt;/code&gt; is in small letters and not in capital so that it doesn't display a syntax error.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2.Comments&lt;/strong&gt;&lt;br&gt;
Comments are put using the &lt;code&gt;#&lt;/code&gt; symbol.&lt;br&gt;
Comments in coding are used for;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Make the code more readable.&lt;/li&gt;
&lt;li&gt;Are used to prevent execution when texting code.&lt;/li&gt;
&lt;li&gt;Used to explain python code. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are two types of comments;&lt;br&gt;
&lt;strong&gt;1.Single-Line comments&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#Addition
a = 2 
b = 3
print("2+3")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Output:
5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;#addition&lt;/code&gt; has been put at the beginning of the code, the code will run without the comments.&lt;/li&gt;
&lt;li&gt;Comments can be kept in any part of the code. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Multi-line comments&lt;/strong&gt;&lt;br&gt;
Multi line comments are used to display more than one line of comment instead of using the &lt;code&gt;#&lt;/code&gt; symbol everywhere in your comments. &lt;br&gt;
Multi-line comments are represented using the &lt;code&gt;"""code"""&lt;/code&gt;.&lt;br&gt;
&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"""
Hello there!
This is how to run 'python is cool' in python.
"""
print("Python is cool")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; Multi-line comments can be displayed if they are assigned values before them and printed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;value = """This multi-line comment will be printed."""
print(value)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Python Variables
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Variables&lt;/strong&gt;&lt;br&gt;
Variables are assigned containers for storing data values. &lt;br&gt;
By the word 'assigned containers' it means that something must be put in front of it followed by an &lt;code&gt;=&lt;/code&gt; sign. &lt;br&gt;
Example&lt;br&gt;
&lt;code&gt;x = 2&lt;/code&gt;&lt;br&gt;
In this example the value of &lt;code&gt;x&lt;/code&gt; here has been assigned the value of &lt;code&gt;2&lt;/code&gt;. This is an example of a container. &lt;/p&gt;

&lt;p&gt;The word data values is use to describe if the value is either a string &lt;code&gt;str&lt;/code&gt;, integer &lt;code&gt;int&lt;/code&gt;, boolean &lt;code&gt;bool&lt;/code&gt; character &lt;code&gt;char&lt;/code&gt; or a double &lt;code&gt;float&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A variable is created when you assign a value to it &lt;code&gt;x = 2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In this case there are rules in which we must follow when giving our variable names. These are; &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A variable name must start with a letter or the underscore  character.e.g &lt;code&gt;_my_var = "pets"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;A variable name cannot start with a number. e.g. &lt;code&gt;2my_var = "family"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;A variable name can only contain underscores (A-z, 0-9 and _ ).e.g.&lt;code&gt;My_Var2 = "students"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Variable names are case-sensitive.e.g &lt;code&gt;age, Age and AGE&lt;/code&gt; are 3 different variables. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There are some techniques that one can use to make them more readable. They include;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. camelCase&lt;/strong&gt; &lt;br&gt;
Each word, except the first, starts with a capital letter&lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myVariableName = "children"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. PascalCase&lt;/strong&gt;&lt;br&gt;
Each word starts with a capital letter. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MyVariableName = "family"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. snake_Case&lt;/strong&gt;&lt;br&gt;
Each word is separated by an underscore character. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_Variable_Name = "pets"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>howto</category>
      <category>education</category>
      <category>writing</category>
    </item>
  </channel>
</rss>
