Python ProgrammingPython Programming

Demonstrate mathematical operators and use of math module

Write a program in python that reads two integers, M and N, from the user. Then program should compute and display: sum, difference, product, quotient, remainder, logarithm and power of two integers.
##
#Python's program to demonstrate mathematical operators and use of math module
##

#It is a good practise to write import statement at top
from math import log10		# log10 is a function of math module


#Read the input values from the user
m = int(input("Enter the value for M: "))
n = int(input("Enter the value for N: "))

#Calculate and display the diffrent mathematical operations
print(m, "+", n, "is", m+n)
print(m, "-", n, "is", m-n)
print(m, "*", n, "is", m*n)
print(m, "/", n, "is", m/n)
print(m, "%", n, "is", m%n)
print(m, "^", n, "is", m**n)
print("Base 10 logarithm of", m, "is", log10(m))
print("Base 10 logarithm of", n, "is", log10(n))
Sample output of above program.
C:\>python C:\Python\programs\program2.py
Enter the value for M: 15
Enter the value for N: 27
15 + 27 is 42
15 - 27 is -12
15 * 27 is 405
15 / 27 is 0.5555555555555556
15 % 27 is 15
15 ^ 27 is 56815128661595284938812255859375
Base 10 logarithm of 15 is 1.1760912590556813
Base 10 logarithm of 27 is 1.4313637641589874

C:\>