Basic Python Calculator Write functions, to implement a calculator that performs
ID: 3668430 • Letter: B
Question
Basic Python Calculator
Write functions, to implement a calculator that performs basic arithmetic operations of addition,
subtraction, multiplication, and division. These functions MUST return the results of their
operation. Note that the menu() function MUST return the option entered by user and the prompt()
function MUST return entered operand values.
You should write SIX functions and 1 Main Function (To loop the program): 1) displaying menu and
2) prompting to enter the two operands (i.e., value1 and value2), 3)Add, 4) Subtract, 5) Multiply, and 6)
Divide.
These functions should have the form:
• def add(num1, num2):
• def subtract(num1, num2):
• def multiply(num1, num2):
• def divide(num1, num2):
• def prompt():
• def menu():
• def main():
Explanation / Answer
#!/usr/bin/python
def main():
def add(num1,num2)
return num1+num2
def sub(num1,num2)
return num1-num2
def mul(num1,num2)
return num1*num2
def div(num1,num2)
return num1/num2
menu[‘1’]=“Addition”
menu[‘2’]=“Subtraction”
menu[‘3’]=“Multiplicaton”
menu[‘4’]=“Division”
for choice:
print choice,menu[choice]
if CHOICE=“1”:
print’adding two numbers’
add(num1,num2):
else if CHOICE=“2”:
print’subtracting two numbers’
sub(num1,num2):
else if CHOICE=“3”:
print’multiplying two numbers’
mul(num1,num2):
else if CHOICE=“4”:
print’dividing two numbers’
div(num1,num2):
else
print”0”:
return 0: