Question

In: Accounting

Write a Python program to add, multiply and divide any two numbers.

Write a Python program to add, multiply and divide any two numbers.

Solutions

Expert Solution

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

Related Solutions

How to add, multiply, and divide numbers in flowgorithm
How to add, multiply, and divide numbers in flowgorithm
Write a calculator program that prompts the user with the following menu: Add Subtract Multiply Divide...
Write a calculator program that prompts the user with the following menu: Add Subtract Multiply Divide Power Root Modulus Upon receiving the user's selection, prompt the user for two numeric values and print the corresponding solution based on the user's menu selection. Ask the user if they would like to use the calculator again. If yes, display the calculator menu. otherwise exit the program. EXAMPLE PROGRAM EXECUTION: Add Subtract Multiply Divide Power Root Modulus Please enter the number of the...
Implement a Java program that is capable of performingthe basic arithmetic operations (add, subtract, multiply, divide)...
Implement a Java program that is capable of performingthe basic arithmetic operations (add, subtract, multiply, divide) on binary numbers using only logical operations (i.e., not using the actual mathematical operators thatJava already supports).A skeleton for the implementation is provided and can be downloaded from Canvas.In this source file  (BinaryCalculator.java), there is already code to read stringsfrom the keyboard.  The program will exit if the string “QUIT” is received, otherwiseit will attempt to process commands of the form: <binary operand 1> <operator> <binary...
Write a MASM program that uses a loop to multiply 2 numbers. Use the equal sign...
Write a MASM program that uses a loop to multiply 2 numbers. Use the equal sign directive to define the two numbers. Save the product in the EAX register. Hint 4 x 5 = 4 + 4 +4 + 4 + 4 = 5 + 5 + 5 + 5 Language (Assembly) ASAP
P-3.36 Write a Java program for a matrix class that can add and multiply arbitrary twodimensional...
P-3.36 Write a Java program for a matrix class that can add and multiply arbitrary twodimensional arrays of integers.
Python program. Write a python program that can convert any radix-d (arbitrary base) number to the...
Python program. Write a python program that can convert any radix-d (arbitrary base) number to the equivalent radix-e (another arbitrary base) number. Where e and d are members in [2, 16]. Remember, base 16 needs to be calculated as hexadecimal. So, if radix-d is input as a hexadecimal number, it needs to convert and output to desired base. Conversely, if base 16 is the desired output, then the output needs to show a hexadecimal number. Hints: The easiest approach is...
Using the Python program: a/ Write a program that adds all numbers from 1 to 100...
Using the Python program: a/ Write a program that adds all numbers from 1 to 100 to a list (in order). Then remove the multiples of 3 from the list. Print the remaining values. b/ Write a program that initializes a list with ten random integers from 1 to 100. Then remove the multiples of 3 and 5 from the list. Print the remaining values. Please show your work and explain. Thanks
Write a python program to sum the prime numbers existing in an array . For instance...
Write a python program to sum the prime numbers existing in an array . For instance , if A = [4, 7, 12, 3, 9] the output should be 10
Write a Python program that calls a function to sum all the numbers in a list...
Write a Python program that calls a function to sum all the numbers in a list and returns the result to the caller. The main program creates a list (with hard-coded or user input) and passes the list as an argument to the function. You may not use the built-in function, sum. The program calls a second function to multiply all the numbers in a list passed to it by main and returns the product back to the caller. List...
Write a program IN PYTHON of the JUPYTER NOOTBOOK that keeps getting a set of numbers...
Write a program IN PYTHON of the JUPYTER NOOTBOOK that keeps getting a set of numbers from user until the user enters "done". Then shows the count, total, and average of the entered numbers. This should the answer when finished Enter a number: 55 Enter a number: 90 Enter a number: 12 Enter a number: done You entered 3 numbers, total is 157, average is 52.33333
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT