Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Simple Calculator from High School Computer Programming - python v3.0
- #Function definitions for each operation
- def multiply(x, y):
- print(x * y)
- def divide(x, y):
- print (x / y)
- def add(x, y):
- print (x + y)
- def subtract(x, y):
- print (x - y)
- #print is used in Python to print out on the screen
- print("Choose an operation")
- print("1.Multiply")
- print("2.Divide")
- print("3.Add")
- print("4.Subtract")
- #creates a variable 'number' to get the input from a user
- number = input("Enter choice between 1 and 4: ")
- #Declares a variable 'x' and 'y' and saves the input as an integer, input is saved as a string by default!
- x = int(input("Enter the first whole number "))
- y = int(input("Enter the second whole number: "))
- #Basically a goto check. If a number is equal to one of the operations, it does it. Otherwise, an error occurs.
- if number == '1':
- multiply(x,y)
- elif number == '2':
- divide(x,y)
- elif number == '3':
- add(x,y)
- elif number == '4':
- subtract(x,y)
- else:
- print("Incorrect responses")
- #Python 2: raw_input() and print in python 2
- #Python 3: input() and print() in python 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement