Wednesday, September 14, 2011

Modulo and Exponential arithematic operation


In last session i left out the two most important arithematic operators Modulo and the Exponential operator

M % N Modulo: find the remainder of M divided by N

M**N Exponentiation: M to the power N


so now we ill be developing a python program ModuloExponential.py which covers same.

so without wasting anymore time ,right click one the project icon ---> new --> PyDev module---> enter the name of module as ModuloExponential and click on OK.. now we are ready


ModuloExponential.py
-------------------

i1=3 # create an integer and assign it to i1
i2= 4 # create an integer and assign it to i1
i3 = i1**i2 # assign the result of 3 to the power 4 to i3

print(i3)

i4= i2 % i1 # assign the result of 4 mod 3 to i4
print(i4)

Output:
81
1

Was very simple program,hope u all got it easily..
now letz discuss some shortcut operators


Operator Example Description
M += N M = M + N
M -= N M = M - N
M *= N M = M * N
M /= N M = M / N
M %= N M = M % N

No comments:

Post a Comment