Study Guide

6.3.7 Add, Subtract, or Multiply CodeHS Answers

6.3.7 Add, Subtract, or Multiply CodeHS Answers

The most common answer is:

num1 = int(input("What is the first number?: "))
num2 = int(input("What is the second number?: "))
mathtype = input("Choose an operation (add, subtract, multiply): ").lower()

def do_math(a, b, operation):
    if operation == "add":
        result = a + b
        print(f"{a} + {b} = {result}")
    elif operation == "subtract":
        result = a - b
        print(f"{a} - {b} = {result}")
    elif operation == "multiply":
        result = a * b
        print(f"{a} * {b} = {result}")
    else:
        print("Invalid operation selected.")

do_math(num1, num2, mathtype)