Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #Simple Calculator from High School Computer Programming - python v3.0
  2. #Function definitions for each operation
  3. def multiply(x, y):
  4. print(x * y)
  5.  
  6. def divide(x, y):
  7. print (x / y)
  8.  
  9. def add(x, y):
  10. print (x + y)
  11.  
  12. def subtract(x, y):
  13. print (x - y)
  14. #print is used in Python to print out on the screen
  15. print("Choose an operation")
  16. print("1.Multiply")
  17. print("2.Divide")
  18. print("3.Add")
  19. print("4.Subtract")
  20. #creates a variable 'number' to get the input from a user
  21. number = input("Enter choice between 1 and 4: ")
  22. #Declares a variable 'x' and 'y' and saves the input as an integer, input is saved as a string by default!
  23. x = int(input("Enter the first whole number "))
  24. y = int(input("Enter the second whole number: "))
  25. #Basically a goto check. If a number is equal to one of the operations, it does it. Otherwise, an error occurs.
  26. if number == '1':
  27. multiply(x,y)
  28. elif number == '2':
  29. divide(x,y)
  30. elif number == '3':
  31. add(x,y)
  32. elif number == '4':
  33. subtract(x,y)
  34. else:
  35. print("Incorrect responses")
  36.  
  37. #Python 2: raw_input() and print in python 2
  38. #Python 3: input() and print() in python 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement