Calculator

Calculator – A simple calculator to do basic operators. Make it a scientific calculator
for added complexity.

"""
Q: Calculator - A simple calculator to do basic operators. Make it a scientific calculator
   for added complexity.
"""
def calculator(a, b, op):
    

    if op not in '+-/*':
        return 'Please only type one of these characters: "+, -, *, /" '

    if op == '+':
        return(str(a) + ' ' + op + ' ' + str(b) + ' = ' + str(a + b))
    if op == '-':
        return(str(a) + ' ' + op + ' ' + str(b) + ' = ' + str(a - b))
    if op == '*':
        return(str(a) + ' ' + op + ' ' + str(b) + ' = ' + str(a * b))
    if op == '/':
        return(str(a) + ' ' + op + ' ' + str(b) + ' = ' + str(a / b))


def main():  

    a = int(input('Please type the first number: '))
    b = int(input('Please type the second number: '))
    op = input('What operation would you like to perform?\
        \nChoose between "+, -, *, /" : ')

    print(calculator(a, b, op))

#this is done to call only main function and all the remaining will be called
if __name__ == '__main__':
    main()

Leave a comment