In: Accounting
Program to perform addition, multiplication and division on two input numbers in Python
In this program, user is asked to input two numbers and the operator (+ for addition, * for multiplication and / for division). Based on the input, program computes the result and displays it as output.
# Python program to perform Addition Multiplication
# and Division of two numbers
num1 = int(input("Enter First Number: "))
num2 = int(input("Enter Second Number: "))
print("Enter which operation would you like to perform?")
ch = input("Enter any of these char for specific operation +,*,/: ")
result = 0
if ch == '+':
result = num1 + num2
elif ch == '*':
result = num1 * num2
elif ch == '/':
result = num1 / num2
else:
print("Input character is not recognized!")
print(num1, ch , num2, ":", result)
Output will be
Output 1 -Addition
Enter First Number: 50
Enter Second Number: 25
Enter which operation would you like to perform?
Enter any of these char for specific operation +,*,/: +
50 + 25 : 75
Output 2 - Division
Enter First Number: 10 Enter Second Number: 5 Enter which operation would you like to perform? Enter any of these char for specific operation +,*,/: / 10 / 5 : 2.0
Output 3 - Multiplication
Enter First Number: 3 Enter Second Number: 5 Enter which operation would you like to perform? Enter any of these char for specific operation +,*,/: * 3 * 5 : 15