Numeric Data types and Mathematical Operations in Python

Learning numeric data type in Python is essential to learning the Language. I created a training episode below for this basic fundamentals of learning python and i’m surprised to see a lot of mathematical functions available in the language though this is just the basic of them. The link to the video is below:







The code for the demo is published below. Good luck and Happy coding!

import sys
import math
print (sys.version)
print () #print a new line

#integer example
print("a whole number is an example of integer m=1")
m=1
print ("m="+repr(m))
print () #print a new line

#float example
print("a number with decimal is an example of float example m=2.16")
m=2.16
print ("m="+repr(m))
print () #print a new line

print("a number with decimal is an example of float example c=1j")
c=1.j
print ("c="+repr(c))
print ("cx2="+repr(c*2))
print () #print a new line

x=9;y=25;z=3
print("x="+repr(x)+" y="+repr(y)+" z="+repr(z) )
print () #print a new line

print ("******")
print("x+y=")
print(x+y)
print () #print a new line

print ("******")
print( "X divided by y is x/y")
print (x/y)
print () #print a new line

print ("******")
print( "X divided by 2 is x/2")
print (x/2)
print () #print a new line

print ("******")
print( "X divided by 2 and get the int part only (floor division) is x//2")
print (x//2)
print () #print a new line

print ("******")
print( "X mod 2. Get the remainder of x/2 is X%2 ")
print (x%2)
print () #print a new line

print ("******")
print( "get the integer division and mod using is divmod(x,2)")
print (divmod(x,2))
print () #print a new line

print ("******")
print( "X Times y is x*y")
print (x*y)
print () #print a new line

print ("******")
print( "x squared is x**2 or pow(x,2)")
print (x**2)
print (pow(x,2))
print () #print a new line

print ("******")
print ("The squareroot of x is math.sqrt(x)")
print (math.sqrt(x))
print () #print a new line

print ("******")
print ("this is also square root of x. x**(1/2)")
print (x**(1/2))
print () #print a new line

print ("******")
print ("this is the cube root of x. x**(1/3)")
print (x**(1/3))
print () #print a new line

print ("******")
print ("the value of pi is math.e")
print (math.pi)
print () #print a new line

print ("******")
print ("the value of e that we use with log math.e")
print (math.e)
print () #print a new line

print ("******")
print ("log of x is math.log(x)")
print (math.log(x))
print () #print a new line

print ("******")
print ("sine of x is math.sin(x)")
print (math.sin(x))
print () #print a new line

print ("******")
print ("cosine of x is math.cos(x)")
print (math.cos(x))
print () #print a new line

print ("******")
print ("factorial of x")
print (math.factorial(x))

Leave a Reply

Your email address will not be published. Required fields are marked *