20240415 Calculator Function

Run Settings
LanguagePython
Language Version
Run Command
"""1 **Calculatior Funciton**: Write a Python funciton that takes two numbers and as input and returns the result of the operation""" def calculator(num1, num2, operator): if operator == '+': # check for + return num1 + num2 elif operator == '-': # check for - return num1 - num2 elif operator == '*': # check for * return num1 * num2 elif operator == '/': # check for / if num2 == 0: # make sure num2 is not 0 return "Division error" else: # num2 is 0 return num1 / num2 else : # opeartor is not +-*/ return "error : invalid operator" result = calculator(5, 3, '+') print(result)
Editor Settings
Theme
Key bindings
Full width
Lines