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
PYTHON: Im writing a program to make a simple calculator that can add, subtract, multiply, divide...
PYTHON: Im writing a program to make a simple calculator that can add, subtract, multiply, divide using functions. It needs to ask for the two numbers from the user and will ask the user for their choice of arithmetic operation 1- subtract 2- add 3- divide 4- multiply
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 Python program that takes as input two numbers, the height, and width of a...
Write a Python program that takes as input two numbers, the height, and width of a rectangle. It then prints a rectangle with height lines and width characters in each line. The rectangle should contain information regarding its dimensions and area inside (centered vertically but not horizontally). If any part of the information (including two stars on each end and a space before and after the line) does not fit in the rectangle, then print the complete information after the...
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.
Must make a "Calculator" using C. The calculator must subtract, add, divide, and multiply inputs, and...
Must make a "Calculator" using C. The calculator must subtract, add, divide, and multiply inputs, and tell whether a number is prime or not. The user chooses how many inputs go into the calculator. For example, the code will ask the user what function they want. If the user chooses to subtract, the the code will then ask the user how many numbers they want to subtract. After, the code will ask the user to input as many numbers as...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT