Question

In: Computer Science

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

Solutions

Expert Solution

# function to addition
def add(num1, num2):
return num1 + num2

# function for suntraction
def sub(num1, num2):
return num1 - num2

# function for multiplication
def multiply(num1, num2):
return num1* num2

# function for division
def divide( num1, num2):
return num1/num2

# main funciton
def main():
# variable for two numbers
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
# printing the menu
print("1-subtract\n2-add\n3-divide\n4-multiply\n")
# taking user choice
choice = int(input("Enter you choice: "))
# checking the user choice and calling the appropriate function
if choice == 1:
print(sub(num1, num2))
elif choice == 2:
print(add(num1,num2))
elif choice == 3:
print(divide(num1, num2))
elif choice == 4:
print(multiply(num1,num2))
else:
print("Invalid Option..:(")

if __name__ == '__main__':
# calling main function
main()


Related Solutions

Using Java Write a simple calculator which can add, subtract, multiply, and divide. Here are the...
Using Java Write a simple calculator which can add, subtract, multiply, and divide. Here are the specifications for the calculator: The calculator has one “accumulator”, which holds the result of all prior calculations. The calculator is set to 0.0 when the calculator is turned on (i.e., instantiated). On the console, the user then enters an operator (+, -, *, or /) and a number. Your console will then apply the operator and operand to the number in the accumulator, and...
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...
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...
Calculator Class Instructions Create a calculator class that will add, subtract, multiply, and divide two numbers....
Calculator Class Instructions Create a calculator class that will add, subtract, multiply, and divide two numbers. It will have a method that will accept three arguments consisting of a string and two numbers example ("+", 4, 5) where the string is the operator and the numbers are what will be used in the calculation. The class must check for a correct operator (+,*,-,/), and a number (integer) for the second and third argument entered. The calculator cannot divide by zero...
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 to add, multiply and divide any two numbers.
Write a Python program to add, multiply and divide any two numbers.
Make a python calculator which deals with arithmetic include plus, minus, divide, and multiply as well...
Make a python calculator which deals with arithmetic include plus, minus, divide, and multiply as well as explaining each answer and use if statement using sign operator.
In python make a simple code. You are writing a code for a program that converts...
In python make a simple code. You are writing a code for a program that converts Celsius and Fahrenheit degrees together. The program should first ask the user in which unit they are entering the temperature degree (c or C for Celcius, and f or F for Fahrenheit). Then it should ask for the temperature and call the proper function to do the conversion and display the result in another unit. It should display the result with a proper message....
How to add, multiply, and divide numbers in flowgorithm
How to add, multiply, and divide numbers in flowgorithm
I am writing a program that will work with two other files to add or subtract...
I am writing a program that will work with two other files to add or subtract fractions for as many fractions that user inputs. I need to overload the + and - and << and >> opperators for the assignment. The two files posted cannot be modified. Can someone correct the Fraction.ccp and Frction.h file that I am working on? I'm really close. // // useFraction.cpp // // DO NOT MODIFY THIS FILE // #include "Fraction.h" #include<iostream> using namespace std;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT