Write a program to show all the arithmetic operations +,-, *, /, //, %, ** in python
Answers
Answer:
a = 21
b = 10
c = 0
c = a + b
print "Line 1 - Value of c is ", c
c = a - b
print "Line 2 - Value of c is ", c
c = a * b
print "Line 3 - Value of c is ", c
c = a / b
print "Line 4 - Value of c is ", c
c = a % b
print "Line 5 - Value of c is ", c
a = 2
b = 3
c = a**b
print "Line 6 - Value of c is ", c
a = 10
b = 5
c = a//b
print "Line 7 - Value of c is ", c
Explanation:
Arithmetic operations
Arithmetic operators are used with numeric values to perform common mathematical operations:
In this program, we'll show how to print out all the arithmetic operations on the screen.
In order to accomplish this, we need to take user input to accept numbers. We store them as float values. Then, we calculate the arithmetic operators using the formula and display it.
PROGRAM:
a = float(input("Enter a number: "))
b = float(input("Enter a number: "))
print(f"{a} + {b} = {a+b}")
print(f"{a} - {b} = {a-b}")
print(f"{a} * {b} = {a*b}")
print(f"{a} / {b} = {a/b}")
print(f"{a} // {b} = {a//b}")
print(f"{a}^{b} = {a* *b}")
OUTPUT:
4
5
4.0 + 5.0 = 9.0
4.0 - 5.0 = -1.0
4.0 * 5.0 = 20.0
4.0 / 5.0 = 0.8
4.0 // 5.0 = 0.0
4.0^5.0 = 1024.0