Play with numbers

Lets start our first lesson in Python. Python makes calculations easy. Let’s check it out.

First check if IDLE icon is present on your Desktop. If not, click on the Windows Button and type IDLE in the search bar at the bottom of the screen. Right click at IDLE and select open file location. Copy Paste the IDLE (Python 3.6 64-bit) shortcut onto your Desktop.

Now that IDLE is on your Desktop,lets get started.Double click the IDLE icon. The Python 3.6.3 shell appears that looks like this. Lets try simple calculations.Enter these commands and press enter.

Screenshot (17)

  • So here we use +,-,*,/  for addition,subtraction,multiplication and division respectively.
  • ** is used for exponent operations.
  • ‘ % ‘ is the modulus operator which gives the remainder of division of 2 numbers.
  • The integer numbers (e.g. 8, 1) have type int, the ones with a fractional part (e.g. 7.5,6.2) have type float. 
  • Python follows a particular precedence of operation which is as follows: Brackets>Exponent>Division/Multiplication(from left to right)>Subtraction/Addition(from left to right).
  • Division (/) always returns a float.
  • To do floor division and get an integer result (discarding any fractional result) you can use the // operator.   

          >>> 4/3
          >>> 4//3

  • In interactive mode, the last printed expression is assigned to the variable _.

          >>> 4//3
           >>> 5+_


  • round(number,places) is used to round a floating point number to required decimal places.

          >>> round(56.668,1)

          Printing numbers in Python

  • The variable must be enclosed in a parenthesis while printing.

>> a=7
>>> print (a)


     In a later tutorial, you will learn how to combine strings and numbers.







Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Powered by

Up ↑

%d bloggers like this: