Question

7- (50 points) Write a simple calculator in Python which supports four basic mathematical operators (1.e. + - / *). You need

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code as below:

Module to be used for basic maths functions - calculation.py


def add(num1, num2):
return num1 + num2

def subtract(num1, num2):
return num1 - num2

def multiply(num1, num2):
return num1 * num2
  
def divide(num1, num2):
return num1 / num2

Main code file to be executed - basic_calculation.py

import calculation

print("Select operation:")   
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
  
user_input = input("Enter your choice(1/2/3/4):")
  
number_1 = int(input("Enter first number:"))
number_2 = int(input("Enter second number:"))
  
print(user_input)
if user_input == 1:
print(str(number_1) + '+' + str(number_2) + '=' +
str(calculation.add(number_1, number_2)))
  
elif user_input == 2:
print(str(number_1) + '-' + str(number_2) + '=' +
str(calculation.subtract(number_1, number_2)))
  
elif user_input == 3:
print(str(number_1) + '*' + str(number_2) + '=' +
str(calculation.multiply(number_1, number_2)))
  
elif user_input == 4:
print(str(number_1) + '/' + str(number_2) + '=' +
str(calculation.divide(number_1, number_2)))
else:
print("Invalid input")

OUTPUT

Select operation: 1. Add 2. Subtract 3. Multiply 4.Divide Enter your choice(1/2/3/4):1 Enter first number: 12 Enter second nu

Select operation: 1. Add 2. Subtract 3. Multiply 4.Divide Enter your choice(1/2/3/4):2 Enter first number: 12 Enter second nu

Select operation: 1. Add 2. Subtract 3.Multiply 4.Divide Enter your choice(1/2/3/4):3 Enter first number: 12 Enter second num

Select operation: 1. Add 2. Subtract 3. Multiply 4.Divide Enter your choice(1/2/3/4):4 Enter first number: 12 Enter second nu

Add a comment
Know the answer?
Add Answer to:
7- (50 points) Write a simple calculator in Python which supports four basic mathematical operators (1.e....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 20: Write a python program that will perform the operations of simple calculator. The operations...

    Question 20: Write a python program that will perform the operations of simple calculator. The operations are : Addition, subtraction, Multiplication and division. Sample output : Select operation. 1.Add 2.Subtract 3.Multiply 4.Divide Enter choice(1/2/3/4): 3 Enter first number: 15 Enter second number: 14 15 * 14 = 210

  • Write an ARM program that implements a simple four-function calculator and prompts the user to enter...

    Write an ARM program that implements a simple four-function calculator and prompts the user to enter a pair of decimal integers (A and B) followed by a character that specifies one of the operators: ‘+’ for addition to compute A+B                             ‘-‘ for subtraction to compute A-B ‘*’ for multiplication to produce the product A*B ‘/’ for division to produce the quotient A/B. Input should be the pair of numbers followed by the operand followed by a return. For example...

  • Write a calculator that will give the user this menu options: 1)Add 2)Subtract 3)Multiply 4)Divide 5)Exit...

    Write a calculator that will give the user this menu options: 1)Add 2)Subtract 3)Multiply 4)Divide 5)Exit . Your program should continue asking until the user chooses 5. If user chooses to exit give a goodbye message. After the user selections options 1 - 4, prompt the user for two numbers. Perform the requested mathematical operation on those two numbers. Round the result to 1 decimal place. Please answer in python and make it simple. Please implement proper indentation, not just...

  • Write a Python Program that displays repeatedly a menu as shown in the sample run below....

    Write a Python Program that displays repeatedly a menu as shown in the sample run below. The user will enter 1, 2, 3, 4 or 5 for choosing addition, substation, multiplication, division or exit respectively. Then the user will be asked to enter the two numbers and the result for the operation selected will be displayed. After an operation is finished and output is displayed the menu is redisplayed, you may choose another operation or enter 5 to exit the...

  • Write an ARM program that implements a simple four-function calculator and prompts the user to enter...

    Write an ARM program that implements a simple four-function calculator and prompts the user to enter a pair of decimal integers (A and B) followed by a character that specifies one of the operators: ‘+’ for addition to compute A+B                             ‘-‘ for subtraction to compute A-B ‘*’ for multiplication to produce the product A*B ‘/’ for division to produce the quotient A/B. Input should be the pair of numbers followed by the operand followed by a return. For example...

  • PLease IN C not in C++ or JAVA, Lab3. Write a computer program in C which...

    PLease IN C not in C++ or JAVA, Lab3. Write a computer program in C which will simulate a calculator. Your calculator needs to support the five basic operations (addition, subtraction, multiplication, division and modulus) plus primality testing (natural number is prime if it has no non-trivial divisors). : Rewrite your lab 3 calculator program using functions. Each mathematical operation in the menu should be represented by a separate function. In addition to all operations your calculator had to support...

  • Creating a Calculator Program

    Design a calculator program that will add, subtract, multiply, or divide two numbers input by a user.Your program should contain the following:-The main menu of your program is to continue to prompt the user for an arithmetic choice until the user enters a sentinel value to quit the calculatorprogram.-When the user chooses an arithmetic operation (i.e. addition) the operation is to continue to be performed (i.e. prompting the user for each number, displayingthe result, prompting the user to add two...

  • Could you code this question on Matlab? :) Question: Design a GUI based application, named Calculator, which perform basic arithmetic operations ie., add, subtract, multiply, and divide Your design m...

    Could you code this question on Matlab? :) Question: Design a GUI based application, named Calculator, which perform basic arithmetic operations ie., add, subtract, multiply, and divide Your design must have 1) Two separate input fields for reading the two operands (let's say a and b) 2) 4 Four button (labeled as +, -, *, /) to let the user select an operation. 3) An output field for displaying the result Following table shows operations performed on pushing each of...

  • Python REALLY NEED HELP !!!!!!!!! [10pts] Write the class Vector that supports the basic vector operations....

    Python REALLY NEED HELP !!!!!!!!! [10pts] Write the class Vector that supports the basic vector operations. Such operations are addition (+) and subtraction (-) of vectors of the same length, dot product (*) and multiplication (*) of a vector by a scalar. All methods must return (not print) the result. Your class should also support the rich comparison for equality (==) - You must use the special methods for those 4 operators in order to override their behavior - You...

  • C++ prefix 3. Add four basic mathematical operators +, -, *, and 7, the six comparison...

    C++ prefix 3. Add four basic mathematical operators +, -, *, and 7, the six comparison operators < <= > >= ==, and !=, and the input and output operators to the Rational class. Write the mathematical and comparison operators as methods. Store the numerator and denominator in reduced form. 1) Programming Exercise: p. 352 / 3 Use this code to test your program: Rational_testing.cpp entre include <iostres include "Rational3. using namespace std; int main() 5 - Rational (7.2). -...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT