Python program to do arithmetical operations

python tutorials and learn python

Created with Sketch.

Python program to do arithmetical operations

The arithmetic operations are performed by a calculator where we can perform addition, subtraction, multiplication, and division. This example shows the basic arithmetic operations i.e.

  • Addition
  • Subtraction
  • Multiplication
  • Division

See this example:

  1. # Store input numbers:
  2. num1 = input(‘Enter first number: ‘)
  3. num2 = input(‘Enter second number: ‘)
  4. # Add two numbers
  5. sum = float(num1) + float(num2)
  6. # Subtract two numbers
  7. min = float(num1) – float(num2)
  8. # Multiply two numbers
  9. mul = float(num1) * float(num2)
  10. #Divide two numbers
  11. div = float(num1) / float(num2)
  12. # Display the sum
  13. print(‘The sum of {0} and {1} is {2}’.format(num1, num2, sum))
  14. # Display the subtraction
  15. print(‘The subtraction of {0} and {1} is {2}’.format(num1, num2, min))
  16. # Display the multiplication
  17. print(‘The multiplication of {0} and {1} is {2}’.format(num1, num2, mul))
  18. # Display the division
  19. print(‘The division of {0} and {1} is {2}’.format(num1, num2, div))

Note: Here input numbers are 10 and 20.

Output:

Python Basic Programs2

 

Leave a Reply

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