• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Mar 19th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def add(n1, n2):
2.   return n1 + n2  #this function returns the sum of two numbers
3. def subtract(n1, n2):
4.   return n1 - n2 #this function returns the difference of two numbers
5. def multiply(n1, n2):
6.   return n1 * n2 #this function returns the product of two numbers
7. def divide(n1, n2):
8.   return n1 / n2 #this function returns the quotient of two numbers
9. #main
10. chose = input("The operations available are: \n1. Addition \n2. Subtraction \n3. Multiplication \n4. Division. \nPick the operation number (1, 2, 3, or 4):") #this line takes the user's choice of operation
11. num1 = input("Enter the first number:") #this line takes the user's first number
12. num2 = input("Enter the second number:" ) #this line takes the user's second number
13. if chose == 1:
14.   print num1, "+" , num2, "=", add(num1, num2) #this statement prints the sum of the two numbers by calling on the function add(n1, n2)
15. elif chose == 2:
16.   print num1, "-", num2, "=", subtract(num1, num2) #this statement prints the difference of the two numbers by calling on the function subtract(n1, n2)
17. elif chose == 3:
18.   print num1, "*", num2, "=", multiply(num1, num2) #this statement prints the product of the two numbers by calling on the function multiply(n1, n2)
19. elif chose == 4:
20.   print num1, "/", num2, "=", divide(num1, num2) #this statement prints the quotient of the two numbers by calling on the function divide(n1, n2)
21. else:
22.   print "Error, invalid input" #this statement tells the user that their operation choice is invalid (not 1-4)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top