<?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>DEV Community: Pixel</title>
    <description>The latest articles on DEV Community by Pixel (@dev123).</description>
    <link>https://dev.to/dev123</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%2F1264333%2F553a6483-188c-4de1-a5c2-e0d0df435816.png</url>
      <title>DEV Community: Pixel</title>
      <link>https://dev.to/dev123</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dev123"/>
    <language>en</language>
    <item>
      <title>INPUT FUNCTION()</title>
      <dc:creator>Pixel</dc:creator>
      <pubDate>Wed, 14 Feb 2024 10:18:04 +0000</pubDate>
      <link>https://dev.to/dev123/input-function-3m0k</link>
      <guid>https://dev.to/dev123/input-function-3m0k</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcji6rqrj2odn3cphxvxz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcji6rqrj2odn3cphxvxz.png" alt="An image demonstarating the input function code and concatenation " width="800" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;By the end of this lesson you should be able to:&lt;/strong&gt;&lt;br&gt;
1.Describe the input command and its basic usage in python.&lt;br&gt;
2.Code using the input command.&lt;br&gt;
3.Avoid the common errors associated with the input command.&lt;/p&gt;
&lt;h2&gt;
  
  
  The input command
&lt;/h2&gt;

&lt;p&gt;-The input command as the name suggests is used when the user is expected to key in information into the computer.&lt;br&gt;
-A message is shown on the console and the user is expected to type information then press enter for the rest of the code to run.&lt;br&gt;
-The input function has the following basic structure: &lt;strong&gt;input("text")&lt;/strong&gt;&lt;br&gt;
.A point to note is that the text &lt;strong&gt;input&lt;/strong&gt; should be written in small letters for the code to work.&lt;/p&gt;

&lt;p&gt;-Here's an example that demonstrates the basic structure of input function()&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;input("What's your name?")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-If you try running the above code in your python code editor you should be able to key in your name.&lt;br&gt;
-But how do we make use of the user's input? Next up variables&lt;/p&gt;
&lt;h2&gt;
  
  
  Variables
&lt;/h2&gt;

&lt;p&gt;-Variables are used with the input function to store the information that the user keyed in.&lt;br&gt;
-Here's a basic structure of an input function with a variable: &lt;strong&gt;variable = input("")&lt;/strong&gt; &lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myname = input("What's your name?")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-Once the user inputs their name after the question and presses enter, the name which the user keyed in is 'stored' in the variable &lt;strong&gt;myname&lt;/strong&gt; as a text(string).&lt;/p&gt;

&lt;h3&gt;
  
  
  Naming variables
&lt;/h3&gt;

&lt;p&gt;-You can name your variable in whichever way you would like but it is advisable to use a name that is related to the information that you expect to be keyed in. For example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;age = input("How old are you?")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-&lt;strong&gt;Do not use spaces&lt;/strong&gt; when naming variables, instead:&lt;br&gt;
   •use_underscores_between_words&lt;br&gt;
   •camelCaseMethodToMakeItEasierToRead&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;using underscores&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;favorite_hobby = input("What is your most favorite hobby?")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;camel case method&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;favoriteHobby = input("Which hobby do you enjoy the most?")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Printing variables
&lt;/h3&gt;

&lt;p&gt;-We have already learnt the art of storing the user's input in a variable. Your next question should be; How do we get the information stored in the variable to be displayed on the console?&lt;br&gt;
-We simply print the variable by using the print statement that we learnt in the previous lesson.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myname = input("What is your name?:")
print("So you are")
print(myname)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-Try running the code above.You will notice that the name that the you typed after the question will be printed in the last line.&lt;br&gt;
-When printing a variable, do not use the &lt;strong&gt;quotation marks ""&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;-Here's another example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nationality = input("What is your nationality?:")
age = input("How old are you?:")
hobby = input("What do you love doing in your free time?:")
print()
print("So you are a/an")
print(nationality)
print("aged")
print(age)
print("and your hobby is")
print(hobby)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Common errors associated with the input function
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Error 1- Capitalization&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;color = Input("What's your favorite color?:")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-The code will not work because the 'i' in input has been capitalised.&lt;br&gt;
-Therefore the text input must be written in small letters for the code to function.&lt;br&gt;
-The correct format should be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;color = input("What's your favorite color?:")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Error 2- Wrong syntax&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 name = input("What's your name?:")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-The error above is that there's a space in the variable myname.&lt;br&gt;
-The correct format should be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myname = input("What's your name?:")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Error 3- ....&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;myname = input("What is your name?:")
print("So you are")
print("myname")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-In this case, the text that will be printed in the last line will be &lt;strong&gt;myname&lt;/strong&gt; instead of the user's name e.g &lt;strong&gt;Samuel&lt;/strong&gt;.&lt;br&gt;
-to fix this remove the quotation marks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myname = input("What is your name?:")
print("So you are")
print(myname)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Error 4- Name error&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;favoriteShow = input("What's your favorite show?:")
print("Your favorite show is")
print(favoriteshow)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-In the code above the printed variable favouriteshow does not match does not match the variable in the first line, the &lt;strong&gt;favoriteshow in line 3&lt;/strong&gt; is therefore &lt;strong&gt;undefined&lt;/strong&gt;.&lt;br&gt;
-The correct format should therefore be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#the variable name should remain the same otherwise it is classified as undefined.
favoriteShow = input("What's your favorite show?:")
print("Your favorite show is")
print(favoriteShow)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-Please leave any concerns or questions in the comments section below.&lt;br&gt;
That's all for today.&lt;/p&gt;

&lt;p&gt;Next up;Concatenation!&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>programming</category>
      <category>lesson2</category>
    </item>
    <item>
      <title>THE PRINT() FUNCTION</title>
      <dc:creator>Pixel</dc:creator>
      <pubDate>Thu, 08 Feb 2024 09:45:14 +0000</pubDate>
      <link>https://dev.to/dev123/the-print-function-2ii0</link>
      <guid>https://dev.to/dev123/the-print-function-2ii0</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff3ha1x8vhuum1sjykj5s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff3ha1x8vhuum1sjykj5s.png" alt="Image description" width="800" height="173"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  By the end of this lesson you should be able to:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Describe the print function and its usage as used in python.&lt;/li&gt;
&lt;li&gt;Write a simple code using the print function.&lt;/li&gt;
&lt;li&gt;Avoid common errors associated with the print function.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's hop right into the action!&lt;/p&gt;

&lt;h2&gt;
  
  
  The print function
&lt;/h2&gt;

&lt;p&gt;-The print statement is one of the easiest ways to display data such as texts to the user using python.&lt;br&gt;
To bring it into perspective, adding a print function tells the computer, &lt;strong&gt;'Display whatever's in the brackets on the user's console'&lt;/strong&gt;. &lt;br&gt;
-Here's a good example of a print function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print("Hello world!")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As illustrated above, the print function is made up of three components:&lt;strong&gt;Print, Parentheses() and Double quotation marks""&lt;/strong&gt;&lt;br&gt;
-A point to note is that all of the above mentioned components must be included or the code won't work! This is further illustrated in the common errors associated with the print function below.&lt;/p&gt;

&lt;p&gt;-The double quotations can also be replaced by single quotation marks and the code would still work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print('Hey, I love your smile!')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Common errors
&lt;/h2&gt;

&lt;p&gt;Here are examples of errors that most beginners commit and simple solutions to the errors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Error 1&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;Print("I love travelling")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-The statement print above has been &lt;strong&gt;capitalized&lt;/strong&gt; and the code will therefore not work.The print statement must therefore be written in small letters for the code to work.&lt;br&gt;
-The code will also not work if the print statement is &lt;strong&gt;misspelled&lt;/strong&gt;.&lt;br&gt;
-The correct code should be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print("I love travelling")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Error 2&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;print(John was sent to the shopping center to buy meat.)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-The code above will not work because the &lt;strong&gt;quotation marks "" or ''&lt;/strong&gt;&lt;br&gt;
have not been included in the code.Instead, the code should be written as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print("John was sent to the shopping center to buy meat.")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Error 3&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;print"Chicken wings are the best!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-The code does not have &lt;strong&gt;parentheses()&lt;/strong&gt; and will therefore not work. The code should be re-written as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print("Chicken wings are the best!")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Error 4&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;print("I am Darkside be prepared to meet
                          your
                           doom!")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-The code above if run fails to display the message on the user's console.But why? Haven't we included all the required components?&lt;br&gt;
-The problem can be easily solved by using &lt;strong&gt;triple quotes """&lt;em&gt;text&lt;/em&gt; """&lt;/strong&gt; instead of &lt;strong&gt;double quotes ""&lt;em&gt;text&lt;/em&gt;""&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;print("""I am Darkside be prepared to meet
                          your
                           doom!""")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-Please note that double quotes are only used for single line texts.&lt;br&gt;
-Triple quotes""" are used for multi-line texts &lt;/p&gt;

&lt;p&gt;Please leave any question that you may be having in the comments section.That's all for today.&lt;br&gt;
Thank you! &lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>programming</category>
      <category>lesson1</category>
    </item>
  </channel>
</rss>
