Question

Create a function that will perform addition, subtraction, multiplication and division. Make sure to provide your...

Create a function that will perform addition, subtraction, multiplication and division.

Make sure to provide your file as a Python Notebook - use comments and python coding standards.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def add(n1, n2):
    return n1 + n2


def sub(n1, n2):
    return n1 - n2


def mul(n1, n2):
    return n1 * n2


def div(n1, n2):
    return n1 / n2


def main():
    while True:
        print('1) Addition\n2) Subtraction\n3) Multiplication\n4) Division\n5) Quit')
        choice = int(input('Enter you choice: '))
        if choice == 5:
            break
        n1 = float(input('Enter first number: '))
        n2 = float(input('Enter second number: '))
        if choice == 1:
            print(str(n1) + ' + ' + str(n2) + " = " + str(add(n1, n2)))
        elif choice == 2:
            print(str(n1) + ' - ' + str(n2) + " = " + str(sub(n1, n2)))
        elif choice == 3:
            print(str(n1) + ' * ' + str(n2) + " = " + str(mul(n1, n2)))
        elif choice == 4:
            print(str(n1) + ' / ' + str(n2) + " = " + str(div(n1, n2)))
        print()


if __name__ == '__main__':
    main()
Add a comment
Know the answer?
Add Answer to:
Create a function that will perform addition, subtraction, multiplication and division. Make sure to provide your...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT