Site icon T4Tutorials.com

Python program of arithmetical operations

Python program of arithmetical operations

In this program, we will code the following four basic arithmetical operations.

# Store input numbers:  
FirstNumber = input('Enter first number: ')  
SecondNumber = input('Enter second number: ')  
  
# Adding two numbers  
Result = float(FirstNumber) + float(SecondNumber)  

# Subtracting two numbers  
min = float(FirstNumber) - float(SecondNumber)  

# Multiply two numbers  
mul = float(FirstNumber) * float(SecondNumber)  

#Dividing two numbers  
div = float(FirstNumber) / float(SecondNumber)  

# Displaying the sum  
print('The sum of {0} and {1} is {2}'.format(FirstNumber, SecondNumber, Result))  
  
# Displaying the subtraction  
print('The subtraction of {0} and {1} is {2}'.format(FirstNumber, SecondNumber, min))  
# Display the multiplication  
print('The multiplication of {0} and {1} is {2}'.format(FirstNumber, SecondNumber, mul))  
# Displaying the division  
print('The division of {0} and {1} is {2}'.format(FirstNumber, SecondNumber, div))

Output

Enter first number: 4
Enter second number: 5
The sum of 4 and 5 is 9.0
The subtraction of 4 and 5 is -1.0
The multiplication of 4 and 5 is 20.0
The division of 4 and 5 is 0.8

Exit mobile version