Learn Python easy way - Part 2

Reading and Writing in Python

Let us see how addition is done in Python

Now we will try to get input from the user.  Press run and then add any two numbers in the adjacent Black window. Each number followed by Enter. As soon as you type two numbers, you will see its sum in the next line.

Now Can you modify the above program to accept three numbers from the user as input and display it's result on the screen. You can do this exercise on the same screen. It will ask if you want to fork. If you have an account on repl.it then you can save the changes made in the code, otherwise press cancel and go ahead with making changes in the code. You can change the code and run it. Only the changes will not be saved after you close the window.

Hint - Solution

a = int (input())
b = int (input())
c = int (input())
print (a + b + c)

Common mathematical operators used in Python

print (2 + 3)   # Addition
print (2 * 3)   # Multiplication
print (2 ** 3) # This means 2 raised to 3, that is 2*2*2
print ( 3/2)     # Division operator
print (13//3)   # Integer division. Remainder is ignored
print (13 % 3) # Modulus operator. Only remainder is printed

User Data Input

When you want to receive data from the user, the input () function is used. 

Press Run, and then enter your name in the adjacent black window, then press Enter to see the Welcome message. You can also make changes to the code if you want to. 

Next : Calculate Chocolates for your friends