Saturday, November 3, 2018

First Program | Hello World | Python

In a software we need to interact with humans. So to interact with human software need to send some messages in a language which is understandable to human like English. So our first program be to welcome.
To start programming you only need one editor, where you write code means some instruction in English language and second one is special software.

What is editor?
Editor is a software where you can write. Example - Notepad
I recommend you to use Notepad++ or Sublime Text or Visual Studio Code for writing code.

What is special software?
Computer does not know the english language. So this special software is need to tell the computer first that we want to talk in some programming language. For computer to understand that we need this special software.
For python programming language we install python from python.org

To setup python environment in your computer please check official document of python.

Lets code

To show any thing we use print command. 
Fist see my code and try this and check the explanation


Explanation:

First we create a file and save it as test.py . Here 'test' is our file name and '.py' is used for python file.
First line of code - print("hello")
Between inverted coma whatever you write it will show in the out put. You have to use () for python3. In python2 it is not mandatory.

Second line - print ("10") 
This also show the thing written between " ",10. So output of second line is 10

3rd line - print (10)
Now you think that why I am not using "" here. Because to print any number you can use "" but if you don't use, there is no problem.

4th line - print (10.5)
As same as 3rd line it results 10.5. Here also you can use print ("10.5") also.

Till now, we use only print ("some text to show"), but here one thing in python. When you only use print (" ") , the next print automatically start from the next line. You can see that our 1st line code output in the 1st line and second one is in second line. Now if we use end , we can change the setting.

Like my code, I use end = "next line -". This means after showing whatever write between quote it shows the end option. For that the next line code start after 'next line -'.

By default end = "\n".  \n means new line.

If you have any question about printing anything please comment below, I will give you the solution.


Assignment

1. print I got 100% marks
2. print My first priority is "LOVE".
3. print 10,20,30,40,50 #Note : Use end for this. And use 5 print statements


Answer of Assignment

1. print ("I got 100% marks")

2. print ("My first priority is \"LOVE\".")
Note : This is a special case. To print a " you need to write \". Because python has no meaning after " any statement. So we use escape character \.

3. print (10,end=", ")
    print (20,end=", ")
    print (30,end=", ")
    print (40,end=", ")
    print (50)


Thank you.

Friday, October 12, 2018

Use of Programming

Programming is a set of instructions. We give instruction to machine and machine do that thing.

Example of Programming

1. There is a machine which cut woods. We need to give the instruction that how much the machine cut. If someone said 5 then the machine cuts 5 cm  wood. In this case we use programming. A program which take value from the user and give instruction to the machine.

2. We regular use calculator. When we want to add something, we press the one value then press '+' sign and then press the second value and then press = and get the result. To multiply we give an instruction with value and * sign and when we press = we get result. How calculator give the right answer when you give an instruction? This is happen because of programming. We tell the calculator when what and how. Calculator just follow our instruction.

3. We use Facebook. When you give your user id and password and press log in then why you get your profile. Why this not happen that you give your id and password but open your friend's account. Because of programming.