Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Simple python calculator (Task 2)")
- print("Choose what to do:")
- print("1-Add")
- print("2-Subtract")
- print("3-Multiply")
- print("4-Divide")
- transaction = input("Enter transaction(1/2/3/4):") #asking user to choose transaction number
- if transaction not in ('1', '2', '3', '4'): #if user's choice is not between transactions 1-4 print "invalid"
- print("Invalid input")
- #else user's choice is between transactions 1-4 then ask num1 and num2
- else:
- num1 = int(input("Enter 1st number: "))
- num2 = int(input("Enter 2nd number: "))
- #here are the variables of calculation due to user's choice
- getsum = num1 + num2
- subtract = num1 - num2
- multiply = num1 * num2
- divide = num1 / num2
- if transaction == '1' or transaction == '+':
- print(getsum)
- elif transaction == '2' or transaction == '-':
- print(subtract)
- elif transaction == '3' or transaction == '*':
- print(multiply)
- elif transaction == '4' or transaction == '/':
- print(divide)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement