Write an algorithm for a program that shows the use of all six math functions. Write, test, and
debug the program using Python. SAMPLE OUTPUT (not including author/program
information) ADDITION: 2+2=4 SUBTRACTION: 4-2=2 MULTIPLICATION: 4*2=8
DIVISION: 4/2=2 EXPONENT: 2**3=8 REMAINDER: 5%2=1
Solution
#!/user/bin/python
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
return x / y
def exp(x, y):
return x ** y
def mod(x, y):
return x % y
print("Select any one operation what you want to perform.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
print("5.Exponent")
print("6.Remainder")
choice = input("Enter choice(1/2/3/4/5/6):")
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
if choice == '1':
print(num1,"+",num2,"=", add(num1,num2))
elif choice == '2':
print(num1,"-",num2,"=", subtract(num1,num2))
elif choice == '3':
print(num1,"*",num2,"=", multiply(num1,num2))
elif choice == '4':
print(num1,"/",num2,"=", divide(num1,num2))
elif choice == '5':
print(num1,"**",num2,"=", exp(num1,num2))
elif choice == '6':
print(num1,"%",num2,"=", mod(num1,num2))
else:
print("Invalid input")

Write an algorithm for a program that shows the use of all six math fu.docx

  • 1.
    Write an algorithmfor a program that shows the use of all six math functions. Write, test, and debug the program using Python. SAMPLE OUTPUT (not including author/program information) ADDITION: 2+2=4 SUBTRACTION: 4-2=2 MULTIPLICATION: 4*2=8 DIVISION: 4/2=2 EXPONENT: 2**3=8 REMAINDER: 5%2=1 Solution #!/user/bin/python def add(x, y): return x + y def subtract(x, y): return x - y def multiply(x, y): return x * y def divide(x, y): return x / y def exp(x, y): return x ** y def mod(x, y): return x % y print("Select any one operation what you want to perform.") print("1.Add") print("2.Subtract")
  • 2.
    print("3.Multiply") print("4.Divide") print("5.Exponent") print("6.Remainder") choice = input("Enterchoice(1/2/3/4/5/6):") num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: ")) if choice == '1': print(num1,"+",num2,"=", add(num1,num2)) elif choice == '2': print(num1,"-",num2,"=", subtract(num1,num2)) elif choice == '3': print(num1,"*",num2,"=", multiply(num1,num2)) elif choice == '4': print(num1,"/",num2,"=", divide(num1,num2)) elif choice == '5': print(num1,"**",num2,"=", exp(num1,num2)) elif choice == '6': print(num1,"%",num2,"=", mod(num1,num2)) else: print("Invalid input")